1234567891011121314151617181920212223242526 |
- from xtquant.xttrader import XtQuantTrader, XtQuantTraderCallback
- from xtquant.xttype import StockAccount
- from xtquant import xtdata, xtconstant
- from datetime import datetime as dt
- def run():
- '''阻塞线程接收行情回调'''
- import time
- client = xtdata.get_client()
- while True:
- time.sleep(3)
- now_date = dt.now()
- if not client.is_connected() or dt.now() > now_date.replace(hour=11, minute=30, second=0):
- raise Exception('行情服务连接断开')
- break
- return
- def trader(data):
- print(dt.now(), len(data.keys()), data.keys())
- # stocks = stocks = xtdata.get_stock_list_in_sector('沪深A股')
- stocks = ['000001.SZ', '600000.SH', '300389.SZ', '001229.SZ', '600674.SH', '000895.SZ']
- xtdata.subscribe_whole_quote(stocks, callback=trader)
- run()
|