diff options
author | loit <michael.foiani@gmail.com> | 2025-07-28 22:08:51 -0400 |
---|---|---|
committer | loit <michael.foiani@gmail.com> | 2025-07-28 22:08:51 -0400 |
commit | 2411108fe1783d5f03edaa57dad16804b2ce0445 (patch) | |
tree | 0d126a0fc7af4ef2dfac622d65f26d71d55fe690 /main.py | |
parent | 1ed62b0e315ca1fc97b3ba8752db24e0bebd706f (diff) |
work on functionality to change parameters of charts and refactor some files out
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -2,19 +2,17 @@ import requests import json import datetime -print("hello") - """ First pull data from yahoo api """ params = { #'period1' : '1753487940', #'period2' : '1753725600', - 'interval' : '1d', - 'range' : '1y', + 'interval' : '1wk', # 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 4h, 1d, 5d, 1wk, 1mo, 3mo + 'range' : '5y', # "1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max" 'events' : 'div|split|earn', 'includePrePost' : 'false' } headers = {'User-agent' : 'fin-backtesting-proj'} -r = requests.get("https://query2.finance.yahoo.com/v8/finance/chart/AAPL", headers=headers, params=params) +r = requests.get("https://query2.finance.yahoo.com/v8/finance/chart/SPY", headers=headers, params=params) print(r.url) print("status_code:\t", r.status_code) @@ -28,6 +26,15 @@ timestamps = data_obj['chart']['result'][0]['timestamp'] close_prices = data_obj['chart']['result'][0]['indicators']['quote'][0]['close'] print('close_price len: ', len(close_prices), 'timestamps len: ', len(timestamps)) +# clean out null's and 0s +for i in range(len(timestamps)): + if close_prices[i] == None or close_prices[i] == 0: + del close_prices[i] + del timestamps[i] + i -= 1 + +print('close_price len: ', len(close_prices), 'timestamps len: ', len(timestamps)) + # save timestamps and close prices into separate files timestamps_encoded = json.dumps(timestamps) close_prices_encoded = json.dumps(close_prices) |