| | |
| | | self.__process_codes_data(codes_data) |
| | | except Exception as e: |
| | | logger_l2_codes_subscript.exception(e) |
| | | finally: |
| | | # 保存一份最新的数据 |
| | | self.__set_latest_datas(codes_data) |
| | | |
| | | @classmethod |
| | | def __set_latest_datas(cls, codes_data): |
| | | data_str = json.dumps([tool.get_now_date_str(), codes_data]) |
| | | with open(constant.L2_CODES_INFO_PATH, mode='w') as f: |
| | | f.write(data_str) |
| | | |
| | | @classmethod |
| | | def __get_latest_datas(cls): |
| | | if os.path.exists(constant.L2_CODES_INFO_PATH): |
| | | with open(constant.L2_CODES_INFO_PATH, mode='r') as f: |
| | | str_ = f.readline() |
| | | data_json = json.loads(str_) |
| | | if data_json[0] == tool.get_now_date_str(): |
| | | return data_json[1] |
| | | return [] |
| | | |
| | | def set_code_special_watch_volume(self, code, volume): |
| | | # 有效期为2s |
| | |
| | | if pRspInfo['ErrorID'] == 0: |
| | | print("----L2行情登录成功----") |
| | | self.is_login = True |
| | | # t1 = threading.Thread(target=lambda: self.__set_codes_data(), daemon=True) |
| | | # # 后台运行 |
| | | # t1.start() |
| | | # 初始设置值 |
| | | t1 = threading.Thread(target=lambda: self.__process_codes_data(self.__get_latest_datas()), daemon=True) |
| | | # 后台运行 |
| | | t1.start() |
| | | |
| | | def OnRspSubMarketData(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast): |
| | | print("OnRspSubMarketData") |
| | |
| | | # try: |
| | | print("订阅结果:", pSpecificSecurity["ExchangeID"], pSpecificSecurity["SecurityID"], pRspInfo["ErrorID"], |
| | | pRspInfo["ErrorMsg"]) |
| | | async_log_util.info(logger_local_huaxin_l2_subscript, f"订阅结果:{pSpecificSecurity['SecurityID']} {pRspInfo['ErrorID']} {pRspInfo['ErrorMsg']}") |
| | | async_log_util.info(logger_local_huaxin_l2_subscript, |
| | | f"订阅结果:{pSpecificSecurity['SecurityID']} {pRspInfo['ErrorID']} {pRspInfo['ErrorMsg']}") |
| | | if pRspInfo["ErrorID"] == 0: |
| | | print("订阅成功") |
| | | self.subscripted_codes.add(pSpecificSecurity['SecurityID']) |