def main():
    """Gets several historical data series from different countries and stores them in several CSV files. 
       The CSVs are named as follows: <indicator>_<date>.csv.
       The end date is always the current date.
    """
    te.login('guest:guest') #Insert your API Key

    countries = ['United States', 'Germany', 'China', 'United Kingdom', 'Portugal', 'Spain', 'France', 'Japan', 'Australia'] #Choose your Countries
    indicators = ['GDP', 'Interest Rate', 'Population'] #Choose your indicators. WARNING: It must be written like on https://api.tradingeconomics.com/indicators.
    today_date = datetime.now().strftime("%Y-%m-%d")

    for indicator in indicators:
        csv_file_name = indicator + "_" + today_date+".csv"
        pfa = pd.DataFrame()
        print("----------------")
        print(indicator)
        for countries_chunk in chunks(countries, 3): 
            print(countries_chunk)
            mydata = te.getHistoricalData(country = countries_chunk, indicator = [indicator],  initDate = '1950-01-01', endDate = today_date  ) #Choose initDate or EndDate
            for country in countries_chunk:
                for a in mydata[country][indicator][0]:
                    dfa = a.to_frame()
                    pfa = pd.concat([pfa, dfa],axis=1) #axis=1, concatenation on the columns.
            time.sleep(1)
        pfa.to_csv(csv_file_name, header=countries)
Example #2
0
def main():
    indicators = get_indicators()
    today_date = datetime.now().strftime("%Y-%m-%d")
    for indicator in list(indicators):
        countries = get_countries(str(indicator))
        if countries:
            for countries_chunk in chunks(countries, 1):
                print(",".join(countries_chunk) + " - " + indicator)
                mydata = te.getHistoricalData(
                    country=countries_chunk,
                    indicator=[indicator],
                    initDate='1800-01-01',
                    endDate=today_date)  #Choose initDate or EndDate
                print(mydata)
                # HERE: do something with the data
                time.sleep(1)  #avoid throttling protection
    def buttonClicked(self):
        print('the button was clicked')
        countryToUse = self.Entry2.get()
        indicToUse = self.Entry1.get()
        self.Message1.configure(text='The button was clicked... \r----------\rThe country selected is: ' + countryToUse +' \r----------\r The indicataor selected is: ' + indicToUse)
        
        
        print('plotting: ' + countryToUse + ' with ' + indicToUse)
        
        #plot a simple chart
        mydata = te.getHistoricalData(country = countryToUse, indicator = indicToUse)

        plt.title(countryToUse + " - " + indicToUse)
        plt.grid(True)
        plt.ylabel("Indicator - " + indicToUse)
        plt.xlabel("Historical dates")
        
        plt.plot(mydata)
        plt.show()
        
        # invoke the chartPage class.
        chartPage(mydata, countryToUse, indicToUse)
Example #4
0
import tradingeconomics as te

te.login('E7B603832B1048B:66EBB7ED5DC548C')

a = te.getHistoricalData(country=['United States', 'china'],
                         indicator=['Imports', 'Exports'],
                         initDate='2011-01-01',
                         endDate='2016-01-01')
print(a)
Example #5
0
import tradingeconomics as te
te.login('guest:guest')

#without a client key only a small sample of data will be given.

#Getting historical data by country, indicator and date. Output type will be a pandas dataframe
mydata = te.getHistoricalData(country='United States',
                              indicator='Exports',
                              initDate='1990-01-01',
                              endDate='2015-01-01')
print(mydata)

print(
    "==============================================================================================================="
)

#Putting country name or indicator name in square brackets the result, by default, will be of the dictionary type for several countries and indicators
mydata = te.getHistoricalData(country=['United States', 'Germany'],
                              indicator=['Exports', 'Imports', 'GDP'],
                              initDate='1990-01-01',
                              endDate='2015-01-01')
print(mydata)
keyGiven = '5C45DD6C810D457:30FB510CFFAA4E7'
keyGuest = 'guest:guest'

#without a client key only a small sample of data will be given.
te.login(keyGiven)



# country and indicator
countrySelect = 'United states'
IndicatorSelect = 'Imports'


#plot a simple chart
mydata = te.getHistoricalData(country = countrySelect, indicator = IndicatorSelect)

plt.title(countrySelect + " - " + IndicatorSelect)
plt.grid(True)
plt.ylabel("Indicator - " + IndicatorSelect)
plt.xlabel("Historical dates")

plt.plot(mydata)
plt.show()






'''
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 20 16:31:08 2018
http://docs.tradingeconomics.com/#introduction
@author: javif
"""

import tradingeconomics as te

# %%
user = '******'
password = '******'
te.login('%s:%s' % (user, password))

# %%
gdpDF = te.getIndicatorData(country='united states', indicators='gdp')

# %% earnings
symbol = 'msft'
country = 'us'
earningsDF = te.getEarnings(symbols='%s:%s' % (symbol, country),
                            initDate='2016-01-01',
                            endDate='2018-12-31')

# %%
hist = te.getHistoricalData(country=['united states', 'china'],
                            indicator=['exports', 'imports'],
                            initDate='1990-01-01',
                            endDate='2015-01-01',
                            output_type='df')
Example #8
0
import matplotlib.pyplot as plt
import numpy as np
import tradingeconomics as te

#without a client key only a small sample of data will be given.
te.login('guest:guest')

#plot a simple chart
mydata = te.getHistoricalData(country='United states', indicator='Imports')

plt.title("United states - Imports")
plt.grid(True)
plt.ylabel("Indicator - Imports")
plt.xlabel("Historical")

plt.plot(mydata)
plt.show()