Last active
May 6, 2020 18:57
-
-
Save databyjp/939ee071619c5d0f71758f408f47016b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ========== 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