Skip to content

Instantly share code, notes, and snippets.

@databyjp
Created April 19, 2020 09:43
Show Gist options
  • Select an option

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

Select an option

Save databyjp/e78335ce996e09247f06a30ff3d708b0 to your computer and use it in GitHub Desktop.
# ========== LOAD TIINGO TOKEN ==========
with open('../../tokens/tiingo_token.txt', 'r') as f:
tiingo_token = f.read().strip()
# ========== 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
amzn_data = get_stock_data(tiingo_token).json()
amzn_df = pd.DataFrame(amzn_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment