Skip to content

Instantly share code, notes, and snippets.

@databyjp
Created March 20, 2021 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save databyjp/eefe9b63ddacd5b6fae35cb191525566 to your computer and use it in GitHub Desktop.
Save databyjp/eefe9b63ddacd5b6fae35cb191525566 to your computer and use it in GitHub Desktop.
# ========== Get token ==========
with open("../../tokens/iex_token.txt", "r") as f:
iex_tkn = f.read().strip()
# ========== Get symbols to use ==========
symbol_list = ["MSFT", "AAPL", "NVDA", "JNJ", "KHC", "ALL"]
# ========== Get symbols to use ==========
date_range = '3m'
symbol_dict = dict()
for symbol in symbol_list:
outpath = f"data/{symbol}_{date_range}.json"
if not os.path.exists(outpath): # Check that the file isn't already there
resp = get_prices(symbol, iex_tkn, date_param=date_range)
if resp is not None:
prices_obj = parse_resp(resp)
with open(outpath, "w") as f:
json.dump(prices_obj, f)
symbol_dict[symbol] = prices_obj
else:
logger.info(f"Data exists for {outpath}, skipping")
with open(outpath, "r") as f:
data_obj = json.load(f)
symbol_dict[symbol] = data_obj
df = utils.symbol_dict_to_df(symbol_dict)
fig = px.line(df, x="date", y="close",
color="symbol", facet_col="symbol", facet_col_wrap=4,
category_orders={"symbol": list(np.sort(df["symbol"].unique()))},
template="plotly_white")
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment