startGetStructure.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. from threading import Thread
  2. from time import sleep
  3. import asyncio
  4. from EmQuantAPI import *
  5. import traceback
  6. from StockStructure import StockStructure
  7. from StockHkStructure import StockHkStructure
  8. def mainCallback(quantdata):
  9. print ("mainCallback",str(quantdata))
  10. #登录掉线或者 登陆数达到上线(即登录被踢下线) 这时所有的服务都会停止
  11. if str(quantdata.ErrorCode) == "10001011" or str(quantdata.ErrorCode) == "10001009":
  12. print ("Your account is disconnect. You can force login automatically here if you need.")
  13. #行情登录验证失败(每次连接行情服务器时需要登录验证)或者行情流量验证失败时,会取消所有订阅,用户需根据具体情况处理
  14. elif str(quantdata.ErrorCode) == "10001021" or str(quantdata.ErrorCode) == "10001022":
  15. print ("Your all csq subscribe have stopped.")
  16. #行情服务器断线自动重连连续6次失败(1分钟左右)不过重连尝试还会继续进行直到成功为止,遇到这种情况需要确认两边的网络状况
  17. elif str(quantdata.ErrorCode) == "10002009":
  18. print ("Your all csq subscribe have stopped, reconnect 6 times fail.")
  19. # 行情订阅遇到一些错误(这些错误会导致重连,错误原因通过日志输出,统一转换成EQERR_QUOTE_RECONNECT在这里通知),正自动重连并重新订阅,可以做个监控
  20. elif str(quantdata.ErrorCode) == "10002012":
  21. print ("csq subscribe break on some error, reconnect and request automatically.")
  22. # 资讯服务器断线自动重连连续6次失败(1分钟左右)不过重连尝试还会继续进行直到成功为止,遇到这种情况需要确认两边的网络状况
  23. elif str(quantdata.ErrorCode) == "10002014":
  24. print ("Your all cnq subscribe have stopped, reconnect 6 times fail.")
  25. # 资讯订阅遇到一些错误(这些错误会导致重连,错误原因通过日志输出,统一转换成EQERR_INFO_RECONNECT在这里通知),正自动重连并重新订阅,可以做个监控
  26. elif str(quantdata.ErrorCode) == "10002013":
  27. print ("cnq subscribe break on some error, reconnect and request automatically.")
  28. # 资讯登录验证失败(每次连接资讯服务器时需要登录验证)或者资讯流量验证失败时,会取消所有订阅,用户需根据具体情况处理
  29. elif str(quantdata.ErrorCode) == "10001024" or str(quantdata.ErrorCode) == "10001025":
  30. print("Your all cnq subscribe have stopped.")
  31. else:
  32. pass
  33. # 获取股票列表并生成数据库表
  34. async def getStockStructure():
  35. stockStructure = StockStructure()
  36. stockStructure.toGet()
  37. # 获取港股列表并生成数据库表
  38. async def getStockHkStructure():
  39. stockHkStructure = StockHkStructure()
  40. stockHkStructure.toGet()
  41. async def main():
  42. await asyncio.gather(
  43. getStockStructure(),
  44. getStockHkStructure(),
  45. )
  46. # 获取需要数据的数据结构
  47. try:
  48. #调用登录函数(激活后使用,不需要用户名密码)
  49. loginResult = c.start("ForceLogin=1", '', mainCallback)
  50. if(loginResult.ErrorCode != 0):
  51. print("login in fail")
  52. exit()
  53. asyncio.run(main())
  54. except Exception as ee:
  55. print("error >>>",ee)
  56. #退出
  57. data = logoutResult = c.stop()
  58. traceback.print_exc()
  59. else:
  60. print("demo end")