from threading import Thread from time import sleep import asyncio from EmQuantAPI import * import traceback from StockStructure import StockStructure from StockHkStructure import StockHkStructure from StockUsaStructure import StockUsaStructure from BondStructure import BondStructure from ForexStructure import ForexStructure from FundStructure import FundStructure from IndexStructure import IndexStructure def mainCallback(quantdata): print ("mainCallback",str(quantdata)) #登录掉线或者 登陆数达到上线(即登录被踢下线) 这时所有的服务都会停止 if str(quantdata.ErrorCode) == "10001011" or str(quantdata.ErrorCode) == "10001009": print ("Your account is disconnect. You can force login automatically here if you need.") #行情登录验证失败(每次连接行情服务器时需要登录验证)或者行情流量验证失败时,会取消所有订阅,用户需根据具体情况处理 elif str(quantdata.ErrorCode) == "10001021" or str(quantdata.ErrorCode) == "10001022": print ("Your all csq subscribe have stopped.") #行情服务器断线自动重连连续6次失败(1分钟左右)不过重连尝试还会继续进行直到成功为止,遇到这种情况需要确认两边的网络状况 elif str(quantdata.ErrorCode) == "10002009": print ("Your all csq subscribe have stopped, reconnect 6 times fail.") # 行情订阅遇到一些错误(这些错误会导致重连,错误原因通过日志输出,统一转换成EQERR_QUOTE_RECONNECT在这里通知),正自动重连并重新订阅,可以做个监控 elif str(quantdata.ErrorCode) == "10002012": print ("csq subscribe break on some error, reconnect and request automatically.") # 资讯服务器断线自动重连连续6次失败(1分钟左右)不过重连尝试还会继续进行直到成功为止,遇到这种情况需要确认两边的网络状况 elif str(quantdata.ErrorCode) == "10002014": print ("Your all cnq subscribe have stopped, reconnect 6 times fail.") # 资讯订阅遇到一些错误(这些错误会导致重连,错误原因通过日志输出,统一转换成EQERR_INFO_RECONNECT在这里通知),正自动重连并重新订阅,可以做个监控 elif str(quantdata.ErrorCode) == "10002013": print ("cnq subscribe break on some error, reconnect and request automatically.") # 资讯登录验证失败(每次连接资讯服务器时需要登录验证)或者资讯流量验证失败时,会取消所有订阅,用户需根据具体情况处理 elif str(quantdata.ErrorCode) == "10001024" or str(quantdata.ErrorCode) == "10001025": print("Your all cnq subscribe have stopped.") else: pass # 获取需要数据的数据结构 try: #调用登录函数(激活后使用,不需要用户名密码) loginResult = c.start("ForceLogin=1", '', mainCallback) if(loginResult.ErrorCode != 0): print("login in fail") exit() # asyncio.run(main()) print("开始初始化=======股票表") stockStructure = StockStructure() stockStructure.toGet() print("开始初始化=======债券表") bondStructure = BondStructure() bondStructure.toGet() # print("开始初始化=======港股") # stockHkStructure = StockHkStructure() # stockHkStructure.toGet() # print("开始初始化=======美股") # stockUsaStructure = StockUsaStructure() # stockUsaStructure.toGet() # print("开始初始化=======外汇") # forexStructure = ForexStructure() # forexStructure.toGet() # print("开始初始化=======基金") # fundStructure = FundStructure() # fundStructure.toGet() print("开始初始化=======指数") indexStructure = IndexStructure() indexStructure.toGet() except Exception as ee: print("error >>>",ee) #退出 data = logoutResult = c.stop() traceback.print_exc() else: print("数据库表初始化完成")