Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- today = datetime.datetime.today()
- for x in stocks:
- tws.reqHistoricalData(x)
- for n in periods:
- delta = datetime.timedelta(days=n)
- for _ in range(10): # repeat it only 10 times
- data = pd.DataFrame(reqHistoricalData(today-delta).strftime("%Y%m%d %H:%M:%S %Z"))
- if not data.empty:
- data.to_csv("filename{}@{}.csv".format(x, n))
- break # exit `for _` loop so it doesn't read again for the same period
- else:
- print("empty data for", x, n, '... reading again')
- tws.reqHistoricalData(x) # read again for the same period
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement