| | |
| | | from log_module import log, async_log_util |
| | | from log_module.async_log_util import huaxin_l2_log |
| | | from log_module.log import logger_local_huaxin_l2_subscript, logger_system, logger_l2_codes_subscript, \ |
| | | logger_local_huaxin_l2_transaction, logger_local_huaxin_l2_upload |
| | | logger_local_huaxin_l2_transaction, logger_local_huaxin_l2_upload, logger_local_huaxin_l2_error |
| | | from utils import tool |
| | | |
| | | ###B类### |
| | |
| | | self.set_codes_data(self.codes) |
| | | |
| | | def OnRspSubTransaction(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast): |
| | | logger_local_huaxin_l2_subscript.info(f"订阅:{pSpecificSecurity['SecurityID']}") |
| | | |
| | | if pRspInfo["ErrorID"] == 0: |
| | | self.subscripted_codes.add(pSpecificSecurity['SecurityID']) |
| | | if bIsLast == 1: |
| | | l2_data_manager.add_subscript_codes(self.subscripted_codes) |
| | | logger_local_huaxin_l2_subscript.info(f"订阅成功:{len(self.subscripted_codes)}") |
| | | |
| | | def OnRspUnSubTransaction(self, pSpecificSecurity, pRspInfo, nRequestID, bIsLast): |
| | | try: |
| | |
| | | logging.exception(e) |
| | | |
| | | def OnRtnTransaction(self, pTransaction): |
| | | # 输出逐笔成交数据 |
| | | if pTransaction['ExecType'] == b"2": |
| | | # 撤单 |
| | | item = {"SecurityID": pTransaction['SecurityID'], "Price": pTransaction['TradePrice'], |
| | | "Volume": pTransaction['TradeVolume'], |
| | | "OrderType": "2", |
| | | "OrderTime": pTransaction['TradeTime'], "MainSeq": pTransaction['MainSeq'], |
| | | "SubSeq": pTransaction['SubSeq'], |
| | | "OrderStatus": "D"} |
| | | buyNo = pTransaction['BuyNo'] |
| | | sellNo = pTransaction['SellNo'] |
| | | if buyNo > 0: |
| | | # 买 |
| | | item["OrderNO"] = buyNo |
| | | item["Side"] = "1" |
| | | elif sellNo > 0: |
| | | # 卖 |
| | | item["OrderNO"] = sellNo |
| | | item["Side"] = "2" |
| | | else: |
| | | item = {"SecurityID": pTransaction['SecurityID'], "TradePrice": pTransaction['TradePrice'], |
| | | "TradeVolume": pTransaction['TradeVolume'], |
| | | "OrderTime": pTransaction['TradeTime'], "MainSeq": pTransaction['MainSeq'], |
| | | "SubSeq": pTransaction['SubSeq'], "BuyNo": pTransaction['BuyNo'], |
| | | "SellNo": pTransaction['SellNo'], |
| | | "ExecType": pTransaction['ExecType'].decode()} |
| | | |
| | | logger_local_huaxin_l2_transaction.info(f"{item}") |
| | | |
| | | if pTransaction['TradePrice'] == self.limit_up_price_dict.get(pTransaction['SecurityID']): |
| | | # TODO 成交价是涨停价才输出 |
| | | huaxin_l2_log.info(logger_local_huaxin_l2_transaction, f"{item}") |
| | | if not self.__is_limit_up_dict.get(pTransaction['SecurityID']): |
| | | huaxin_l2_log.info(logger_local_huaxin_l2_upload, |
| | | f"{pTransaction['TradeTime']} {pTransaction['SecurityID']} 下单") |
| | | self.__is_limit_up_dict[pTransaction['SecurityID']] = True |
| | | try: |
| | | # 输出逐笔成交数据 |
| | | if pTransaction['ExecType'] == b"2": |
| | | # 撤单 |
| | | item = {"SecurityID": pTransaction['SecurityID'], "Price": pTransaction['TradePrice'], |
| | | "Volume": pTransaction['TradeVolume'], |
| | | "OrderType": "2", |
| | | "OrderTime": pTransaction['TradeTime'], "MainSeq": pTransaction['MainSeq'], |
| | | "SubSeq": pTransaction['SubSeq'], |
| | | "OrderStatus": "D"} |
| | | buyNo = pTransaction['BuyNo'] |
| | | sellNo = pTransaction['SellNo'] |
| | | if buyNo > 0: |
| | | # 买 |
| | | item["OrderNO"] = buyNo |
| | | item["Side"] = "1" |
| | | elif sellNo > 0: |
| | | # 卖 |
| | | item["OrderNO"] = sellNo |
| | | item["Side"] = "2" |
| | | else: |
| | | self.__is_limit_up_dict[pTransaction['SecurityID']] = False |
| | | item = {"SecurityID": pTransaction['SecurityID'], "TradePrice": pTransaction['TradePrice'], |
| | | "TradeVolume": pTransaction['TradeVolume'], |
| | | "OrderTime": pTransaction['TradeTime'], "MainSeq": pTransaction['MainSeq'], |
| | | "SubSeq": pTransaction['SubSeq'], "BuyNo": pTransaction['BuyNo'], |
| | | "SellNo": pTransaction['SellNo'], |
| | | "ExecType": pTransaction['ExecType'].decode()} |
| | | |
| | | logger_local_huaxin_l2_transaction.info(f"{item}") |
| | | |
| | | if pTransaction['TradePrice'] == self.limit_up_price_dict.get(pTransaction['SecurityID']): |
| | | # TODO 成交价是涨停价才输出 |
| | | huaxin_l2_log.info(logger_local_huaxin_l2_transaction, f"{item}") |
| | | if not self.__is_limit_up_dict.get(pTransaction['SecurityID']): |
| | | huaxin_l2_log.info(logger_local_huaxin_l2_upload, |
| | | f"{pTransaction['TradeTime']} {pTransaction['SecurityID']} 下单") |
| | | self.__is_limit_up_dict[pTransaction['SecurityID']] = True |
| | | else: |
| | | self.__is_limit_up_dict[pTransaction['SecurityID']] = False |
| | | except Exception as e: |
| | | logger_local_huaxin_l2_error.exception(e) |
| | | |
| | | |
| | | class MyL2ActionCallback(L2ActionCallback): |