def get_stock_quotes():
# Get real time quotes of the stock list
global sched_time
while True:
now = dt.datetime.now().time()
#now = dt.time(9, 25, 1)
if is_market_open(now):
try:
raw_data = ts.get_realtime_quotes(stock_list)
raw_data = process_raw_data(raw_data)
#print(raw_data)
for index, row in raw_data.iterrows():
data_list[index] = pd.concat([data_list[index], raw_data[index:index + 1]])
#print(data_list[index])
print('Get real time quotes of stock list done!')
time.sleep(seconds_per_tick_data)
except KeyboardInterrupt:
print('Interrupt occur!')
break
except Exception:
print('Error in reading!')
continue
else:
if now > market_close_time3:
break
else:
sleep_time = (sched_time.hour - now.hour) * 60 * 60 + (sched_time.minute - now.minute) * 60 + (sched_time.second - now.second)
print(sleep_time)
time.sleep(sleep_time)
save_to_csv(data_list)
get_stocks_realtime_quotes.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录