-
Notifications
You must be signed in to change notification settings - Fork 34
/
download_stocks_ohlcv.py
36 lines (30 loc) · 1.09 KB
/
download_stocks_ohlcv.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
35
36
"""
Download stocks open, close, high, low and volume data for all available stocks.
Make sure you have downloaded the list of tickers using download_stocklist.py script.
"""
from argparse import ArgumentParser
from datetime import datetime
from common.market import download_tickers_data
from common.market import load_all_tickers
def parse_args():
parser = ArgumentParser(description=__doc__)
parser.add_argument(
"-s",
"--back-period-in-years",
type=int,
default=2,
help="Look back period in years. By default the value is 2 so the script will collect previous 2 years of data.",
)
parser.add_argument("-t", "--tickers", help="Ticker symbol")
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
tickers = args.tickers
back_period_in_years = args.back_period_in_years
end = datetime.now()
start = datetime(end.year - back_period_in_years, end.month, end.day)
if not tickers:
tickers = load_all_tickers()
else:
tickers = tickers.split(",")
download_tickers_data(tickers, start, end)