chongxie_run.py 820 B

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