Skip to content

Instantly share code, notes, and snippets.

@databyjp
Last active May 6, 2020 18:57
Show Gist options
  • Select an option

  • Save databyjp/939ee071619c5d0f71758f408f47016b to your computer and use it in GitHub Desktop.

Select an option

Save databyjp/939ee071619c5d0f71758f408f47016b to your computer and use it in GitHub Desktop.
# ========== FUNCTION TO GET STOCK DATA ==========
def get_stock_data(tkn, sym='amzn', start_date='2020-01-01'):
headers = {'Content-Type': 'application/json'}
requestResponse = requests.get("https://api.tiingo.com/tiingo/daily/" + sym + "/prices?startDate=" + start_date + "&token=" + tkn, headers=headers)
if requestResponse.status_code == 200:
logger.info(f'Success fetching {sym} data from {start_date} to today')
else:
logger.warning(f'Something looks wrong - status code {requestResponse.status_code}')
return requestResponse
# ========== GET STOCK DATA ==========
symbols_ser = ['AAPL', 'MSFT', 'JNJ', 'WMT', 'TSM', 'XOM'] # For testing
ticker_datas = []
for sym in symbols_ser:
temp_data = get_stock_data(tiingo_token, sym=sym, start_date='2015-01-01').json()
temp_df = pd.DataFrame(temp_data)
temp_df['sym'] = sym
ticker_datas.append(temp_df)
# Concatenate stock data
total_ticker_df = pd.concat(ticker_datas)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment