-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.py
34 lines (28 loc) · 958 Bytes
/
fetch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
import json
import datetime
import time
import alpha_vantage.timeseries
import os
with open('env.json', "r") as infile:
env_json = json.load(infile)
with open('stocks.json','r') as infile:
stocks_dict = json.load(infile)
if env_json['Current_day'] > 14:
env_json['Current_day'] = 1
stock_list = stocks_dict[str(env_json['Current_day'])]
ts = alpha_vantage.timeseries.TimeSeries(key='QVEGLYRJUK0ABVMT',output_format='pandas')
day = datetime.date.today().day
month = datetime.date.today().month
year = datetime.date.today().year
for i in stock_list:
try:
data, meta_data = ts.get_intraday(i,'1min','full')
ticker_list = [i] * len(data)
data['Ticker'] = ticker_list
print(f'./data/{i}_{year}_{month}_{day}.csv')
data.to_csv(f'./data/{i}_{year}_{month}_{day}.csv')
except ValueError as e:
print(e.__str__())
pass
time.sleep(20)