Administrator
2024-02-01 a0b392779fab69eee750497fd55ca2e7ddade96a
09:30之后下的卖单没成交主动撤单机制修改
3个文件已修改
27 ■■■■ 已修改文件
trade/huaxin/huaxin_sell_util.py 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_api.py 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_order_processor.py 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_sell_util.py
@@ -36,7 +36,4 @@
        order_ref = huaxin_util.create_order_ref()
    result = huaxin_trade_api.order(2, code, volume, price, order_ref=order_ref,
                                    blocking=blocking, request_id=request_id)
    # 如果是在正常交易时间提交的2s之内还未成交的需要撤单
    if int("092958") <= int(tool.get_now_time_str().replace(":", "")) <= int("145655"):
        __cancel_sell_thread_pool.submit(lambda: __cancel_sell_order(code, order_ref))
    return result
trade/huaxin/huaxin_trade_api.py
@@ -38,6 +38,13 @@
def __run_recv_queue_trade(queue: multiprocessing.Queue):
    def __cancel_order(code, order_ref):
        # 2s没成交就撤单
        time.sleep(2)
        order_: HuaxinOrderEntity = TradeResultProcessor.get_huaxin_order_by_order_ref(order_ref)
        if order_ is not None:
            if huaxin_util.is_can_cancel(order_.orderStatus):
                cancel_order(2, code, order_.orderSysID)
    def __process_order(data):
        # 更新委托队列
@@ -65,11 +72,13 @@
                                  insertDate=insertDate, direction=direction,
                                  is_shadow_order=is_shadow_order)
        try:
            if order.direction == str(huaxin_util.TORA_TSTP_D_Sell):
            if str(order.direction) == str(huaxin_util.TORA_TSTP_D_Sell):
                # 刷新持仓列表
                huaxin_trade_data_update.add_position_list()
            TradeResultProcessor.process_buy_order(order)
            TradeResultProcessor.process_sell_order(order)
            need_watch_cancel = TradeResultProcessor.process_sell_order(order)
            if need_watch_cancel:
                threading.Thread(target=lambda: __cancel_order(order.code, order.orderRef), daemon=True).start()
        finally:
            try:
                # 加入2次,增大加入成功率
@@ -133,7 +142,7 @@
# 设置交易通信队列
# 暂时不会使用该方法
def run_pipe_trade(queue_strategy_r_trade_w_, queue_strategy_w_trade_r_, queue_strategy_w_trade_r_for_read_):
    global queue_strategy_w_trade_r, queue_strategy_w_trade_r_for_read,queue_l1_trade_r_strategy_w
    global queue_strategy_w_trade_r, queue_strategy_w_trade_r_for_read, queue_l1_trade_r_strategy_w
    queue_strategy_w_trade_r = queue_strategy_w_trade_r_
    queue_strategy_w_trade_r_for_read = queue_strategy_w_trade_r_for_read_
trade/huaxin/huaxin_trade_order_processor.py
@@ -170,13 +170,20 @@
        except Exception as e:
            async_log_util.exception(hx_logger_trade_debug, e)
    # 返回是否要监控撤单
    @classmethod
    def process_sell_order(cls, order: HuaxinOrderEntity):
        # 处理卖单
        if order.direction != str(huaxin_util.TORA_TSTP_D_Sell):
            return
            return False
        cls.order_ref_dict[order.orderRef] = order
        # 下单时间在9:30以后的如果2s没成交就撤单
        if tool.trade_time_sub(order.insertTime, "09:30:00") >= 0 and str(
                order.orderStatus) == huaxin_util.TORA_TSTP_OST_Accepted:
            return True
        return False
    @classmethod
    def get_huaxin_order_by_order_ref(cls, order_ref) -> HuaxinOrderEntity:
        return cls.order_ref_dict.get(order_ref)