startGet.py 3.2 KB

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