Administrator
2023-10-12 e1790699a10fa31e037d60e37f2fea6cf24d8db2
真实下单位置的延时处理
1个文件已修改
36 ■■■■■ 已修改文件
trade/huaxin/huaxin_trade_order_processor.py 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_order_processor.py
@@ -13,6 +13,7 @@
from trade import trade_manager, trade_record_log_util
from trade.huaxin.huaxin_trade_record_manager import TradeOrderIdManager
from utils import huaxin_util, tool
import concurrent.futures
class HuaxinOrderEntity:
@@ -108,9 +109,26 @@
class TradeResultProcessor:
    __TradeOrderIdManager = TradeOrderIdManager()
    __processed_keys = set()
    __thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=50)
    @classmethod
    def process_order(cls, order: HuaxinOrderEntity):
        # 处理下单成功
        def process_order_success(order_: HuaxinOrderEntity, delay_s=0.0):
            if delay_s > 0:
                time.sleep(delay_s)
            new_place_order_index = cls.order_success(order_)
            if new_place_order_index:
                buy_single_index, buy_exec_index, compute_index, num, count, max_num_set, volume_rate = TradePointManager().get_buy_compute_start_data_cache(
                    order.code)
                cancel_buy_strategy.set_real_place_position(order.code,
                                                            new_place_order_index,
                                                            buy_single_index)
                trade_record_log_util.add_real_place_order_position_log(order.code,
                                                                        new_place_order_index,
                                                                        buy_single_index)
            return new_place_order_index
        # 只处理买入单
        if order.direction != str(huaxin_util.TORA_TSTP_D_Buy):
            return
@@ -124,17 +142,10 @@
            cls.__processed_keys.add(key)
            if huaxin_util.is_can_cancel(order.orderStatus):
                # 设置下单成功
                new_place_order_index = cls.order_success(order)
                if new_place_order_index:
                    buy_single_index, buy_exec_index, compute_index, num, count, max_num_set, volume_rate = TradePointManager().get_buy_compute_start_data_cache(
                        order.code)
                    cancel_buy_strategy.set_real_place_position(order.code,
                                                                new_place_order_index,
                                                                buy_single_index)
                    trade_record_log_util.add_real_place_order_position_log(order.code,
                                                                            new_place_order_index,
                                                                            buy_single_index)
                new_place_order_index_ = process_order_success(order)
                if not new_place_order_index_:
                    # 有可能由于L2数据还没有来,导致正确的下单位置尚未获取到,需要延时200ms再进行处理
                    cls.__thread_pool.submit(lambda: process_order_success(order, delay_s=0.2))
            elif huaxin_util.is_canceled(order.orderStatus) or huaxin_util.is_deal(
                    order.orderStatus):
                # 已经撤单/已经成交,需要处理临时保存的系统订单号
@@ -168,8 +179,7 @@
                        # 4s内才会校验
                        volume = total_datas[place_index]["val"]["num"]
                        for i in range(place_index + 1, len(total_datas)):
                            if total_datas[i]["val"]["num"] == volume and order.acceptTime == total_datas[i]["val"][
                                "time"]:
                            if total_datas[i]["val"]["num"] == volume and order.acceptTime == total_datas[i]["val"]["time"]:
                                huaxin_delegate_postion_manager.set_place_order_position(order.code, i)
                                async_log_util.info(hx_logger_trade_debug, "{}校验真实下单成功,{}->{}", order.code, place_index,
                                                    i)