| | |
| | | from huaxin_client import socket_util, l1_subscript_codes_manager |
| | | import xmdapi |
| | | from huaxin_client import tool, constant |
| | | from huaxin_client.client_network import SendResponseSkManager |
| | | from log_module.log import logger_system, logger_local_huaxin_l1, logger_l2_codes_subscript |
| | | |
| | | level1_data_dict = { |
| | |
| | | login_req = xmdapi.CTORATstpReqUserLoginField() |
| | | self.__api.ReqUserLogin(login_req, 1) |
| | | |
| | | def subscribe_codes(self, codes_sh, codes_sz): |
| | | # 重新订阅代码 |
| | | print(f"订阅数量:sh-{len(codes_sh)} sz-{len(codes_sz)}") |
| | | if codes_sh: |
| | | ret = self.__api.SubscribeMarketData(codes_sh, xmdapi.TORA_TSTP_EXD_SSE) |
| | | if ret != 0: |
| | | print('SubscribeMarketData fail, ret[%d]' % ret) |
| | | else: |
| | | print('SubscribeMarketData success, ret[%d]' % ret) |
| | | |
| | | if codes_sz: |
| | | ret = self.__api.SubscribeMarketData(codes_sz, xmdapi.TORA_TSTP_EXD_SZSE) |
| | | if ret != 0: |
| | | print('SubscribeMarketData fail, ret[%d]' % ret) |
| | | else: |
| | | print('SubscribeMarketData success, ret[%d]' % ret) |
| | | |
| | | def OnRspUserLogin(self, pRspUserLoginField, pRspInfoField, nRequestID): |
| | | if pRspInfoField.ErrorID == 0: |
| | | print('Login success! [%d]' % nRequestID) |
| | |
| | | 其它情况,订阅sub_arr集合中的合约行情 |
| | | ''' |
| | | |
| | | print(f"订阅数量:sh-{len(self.codes_sh)} sz-{len(self.codes_sz)}") |
| | | if self.codes_sh: |
| | | ret = self.__api.SubscribeMarketData(self.codes_sh, xmdapi.TORA_TSTP_EXD_SSE) |
| | | if ret != 0: |
| | | print('SubscribeMarketData fail, ret[%d]' % ret) |
| | | else: |
| | | print('SubscribeMarketData success, ret[%d]' % ret) |
| | | |
| | | if self.codes_sz: |
| | | ret = self.__api.SubscribeMarketData(self.codes_sz, xmdapi.TORA_TSTP_EXD_SZSE) |
| | | if ret != 0: |
| | | print('SubscribeMarketData fail, ret[%d]' % ret) |
| | | else: |
| | | print('SubscribeMarketData success, ret[%d]' % ret) |
| | | |
| | | self.subscribe_codes(self.codes_sh, self.codes_sz) |
| | | # sub_arr = [b'600004'] |
| | | # ret = self.__api.UnSubscribeMarketData(sub_arr, xmdapi.TORA_TSTP_EXD_SSE) |
| | | # if ret != 0: |
| | |
| | | logger_local_huaxin_l1.info(f"({request_id})新增加订阅的代码:{add_codes}") |
| | | |
| | | |
| | | is_re_subscript = False |
| | | |
| | | |
| | | # 重新订阅代码 |
| | | def re_subscript(spi: MdSpi): |
| | | try: |
| | | global is_re_subscript |
| | | if is_re_subscript: |
| | | return |
| | | is_re_subscript = True |
| | | codes_sh, codes_sz = l1_subscript_codes_manager.request_l1_subscript_target_codes() |
| | | if len(codes_sh) > 100 and len(codes_sz) > 100: |
| | | logger_local_huaxin_l1.info(f"重新订阅 sh-{len(codes_sh)} sz-{len(codes_sz)}") |
| | | spi.subscribe_codes(codes_sh, codes_sz) |
| | | except: |
| | | pass |
| | | |
| | | |
| | | def run(pipe_l2): |
| | | logger_local_huaxin_l1.info("运行l1订阅服务") |
| | | codes_sh = [] |
| | |
| | | for i in range(15): |
| | | try: |
| | | codes_sh, codes_sz = l1_subscript_codes_manager.get_codes() |
| | | |
| | | logger_local_huaxin_l1.info(f"获取上证,深证代码数量:sh-{len(codes_sh)} sz-{len(codes_sz)}") |
| | | break |
| | | except Exception as e: |
| | |
| | | logging.exception(e) |
| | | finally: |
| | | time.sleep(3) |
| | | # 判断是否需要重新订阅 |
| | | if tool.is_pre_trade_time(): |
| | | re_subscript(spi) |
| | | else: |
| | | global is_re_subscript |
| | | is_re_subscript = False |
| | | |
| | | # 释放接口对象 |
| | | api.Release() |
| | | |