| | |
| | | def subscribe(self, codes: set): |
| | | del_codes = self.__subscribed_codes - codes |
| | | add_codes = codes - self.__subscribed_codes |
| | | logger_local_huaxin_l1.info(f"新增订阅:{add_codes} 减少订阅:{del_codes}") |
| | | if add_codes: |
| | | codes_sh, codes_sz = self.__seperate_codes(add_codes) |
| | | if codes_sh: |
| | |
| | | def OnRspSubMarketData(self, pSpecificSecurityField, pRspInfoField): |
| | | if pRspInfoField.ErrorID == 0: |
| | | print('OnRspSubMarketData: OK!') |
| | | logger_local_huaxin_l1.debug(f"订阅:{pSpecificSecurityField['SecurityID']}") |
| | | logger_local_huaxin_l1.info(f"订阅:{pSpecificSecurityField['SecurityID']}") |
| | | self.__subscribed_codes.add(pSpecificSecurityField["SecurityID"]) |
| | | else: |
| | | print('OnRspSubMarketData: Error! [%d] [%s]' |
| | |
| | | def OnRspUnSubMarketData(self, pSpecificSecurityField, pRspInfoField): |
| | | if pRspInfoField.ErrorID == 0: |
| | | print('OnRspUnSubMarketData: OK!') |
| | | logger_local_huaxin_l1.debug(f"取消订阅:{pSpecificSecurityField['SecurityID']}") |
| | | logger_local_huaxin_l1.info(f"取消订阅:{pSpecificSecurityField['SecurityID']}") |
| | | self.__subscribed_codes.discard(pSpecificSecurityField["SecurityID"]) |
| | | else: |
| | | print('OnRspUnSubMarketData: Error! [%d] [%s]' |
| | |
| | | codes = set(data["data"]) |
| | | spi.subscribe(codes) |
| | | logger_local_huaxin_l1.info(f"收到策略消息:{data}", ) |
| | | except: |
| | | pass |
| | | except Exception as e: |
| | | logger_local_huaxin_l1.exception(e) |
| | | finally: |
| | | time.sleep(1) |
| | | |