| | |
| | | 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 |
| | |
| | | |
| | | |
| | | 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): |
| | | # 更新委托队列 |
| | |
| | | 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次,增大加入成功率 |
| | |
| | | # 设置交易通信队列 |
| | | # 暂时不会使用该方法 |
| | | 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_ |
| | | |
| | |
| | | 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) |