forked from yacoubb/stock-trading-ml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_data_to_csv.py
33 lines (25 loc) · 1.14 KB
/
save_data_to_csv.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
from alpha_vantage.timeseries import TimeSeries
from pprint import pprint
import json
import argparse
def save_dataset(symbol, time_window):
credentials = json.load(open('creds.json', 'r'))
api_key = credentials['av_api_key']
print(symbol, time_window)
ts = TimeSeries(key=api_key, output_format='pandas')
if time_window == 'intraday':
data, meta_data = ts.get_intraday(
symbol='MSFT', interval='1min', outputsize='full')
elif time_window == 'daily':
data, meta_data = ts.get_daily(symbol, outputsize='full')
elif time_window == 'daily_adj':
data, meta_data = ts.get_daily_adjusted(symbol, outputsize='full')
pprint(data.head(10))
data.to_csv(f'./{symbol}_{time_window}.csv')
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('symbol', type=str, help="the stock symbol you want to download")
parser.add_argument('time_window', type=str, choices=[
'intraday', 'daily', 'daily_adj'], help="the time period you want to download the stock history for")
namespace = parser.parse_args()
save_dataset(**vars(namespace))