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)
def main(): st.title("demo data app") te.login() data = te.getIndicatorData(country=['united states', 'china'], output_type='df') df = pd.DataFrame(data) is_usa = df['Country'] == "United States" new_df = df[is_usa] values = new_df['PreviousValue'] values2 = new_df['Category'] st.write(new_df) st.bar_chart(values) st.bar_chart(values2)
import tradingeconomics as te te.login('guest:guest') #without a client key only a small sample of data will be given. #Get Federal Reserve states mydata = te.getFedRStates(county=None, output_type=None) print(mydata) print( "===============================================================================================================" ) #Get Federal Reserve county mydata = te.getFedRStates(county='arkansas', output_type=None) print(mydata) print( "===============================================================================================================" ) #Get Federal Reserve snapshots by symbol mydata = te.getFedRSnaps(symbol='AGEXMAK2A647NCEN') print(mydata) print( "===============================================================================================================" )
import tradingeconomics as te te.login() df = te.getRatings( country=['United states', 'United Kingdom', 'India', 'Japan', 'Russia'], output_type='df') print(df) print(df.columns) print(df[['Country', 'SP', 'Moodys', 'Fitch']])
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)
import tradingeconomics as te import json te.login('yu06vzmlllju1qz:mtvmbg847pwz3jn') te.subscribe('calendar') def on_message(ws, message): data = json.loads(message) print(data) te.run(on_message)
from matplotlib.figure import Figure import matplotlib.pyplot as plt import numpy as np import tradingeconomics as te 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")
def get_countries(indi): """ Gets all countries that has a certain indicator """ countries = te.getIndicatorData("all", indi, output_type="df") if not countries.empty: return list(countries["Country"]) return None 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 if __name__ == "__main__": te.login('guest:guest') #Insert your API Key main()
import tradingeconomics as te import json te.login('') def on_message(ws, message): print(json.loads(message)) #to get multiple symbols te.subscribe(['EURUSD:CUR', 'USDRUB:CUR', 'CL1:COM', 'AAPL:US']) #to get just one symbol #te.subscribe('EURUSD:CUR') te.run(on_message)
# -*- 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')