| | |
| | | |
| | | |
| | | class HuaxinOrderEntity: |
| | | def __init__(self, code, orderStatus, orderRef, accountID, orderSysID, insertDate=None, insertTime=None, |
| | | def __init__(self, code, orderStatus, orderRef, accountID, orderSysID,direction=None, insertDate=None, insertTime=None, |
| | | acceptTime=None): |
| | | self.code = code |
| | | self.orderStatus = orderStatus |
| | |
| | | self.insertTime = insertTime |
| | | self.insertDate = insertDate |
| | | self.acceptTime = acceptTime |
| | | self.direction = direction |
| | | |
| | | |
| | | class CancelOrderManager: |
| | |
| | | |
| | | @classmethod |
| | | def process_order(cls, order: HuaxinOrderEntity): |
| | | # 只处理买入单 |
| | | if order.direction != str(huaxin_util.TORA_TSTP_D_Buy): |
| | | return |
| | | |
| | | # 同一订单号只有状态变化了才需要处理 |
| | | key = f"{order.insertDate}_f{order.code}_{order.orderSysID}_{order.orderStatus}" |
| | | key = f"{order.insertDate}_{order.code}_{order.orderSysID}_{order.orderStatus}" |
| | | if key in cls.__processed_keys: |
| | | return |
| | | async_log_util.info(hx_logger_trade_debug, f"处理华鑫订单:{key}") |
| | | 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) |
| | | elif huaxin_util.is_canceled(order.orderStatus) or huaxin_util.is_deal( |
| | | order.orderStatus): |
| | | # 已经撤单/已经成交,需要处理临时保存的系统订单号 |
| | | cls.__TradeOrderIdManager.remove_order_id(order.code, |
| | | order.accountID, |
| | | order.orderSysID) |
| | | if huaxin_util.is_deal(order.orderStatus): |
| | | # 成交之后处理 |
| | | trade_manager.buy_success(order.orderStatus) |
| | | CancelOrderManager().buy_success(order.code, order.orderRef, order.orderSysID) |
| | | elif huaxin_util.is_canceled(order.orderStatus): |
| | | CancelOrderManager().cancel_success(order.code, order.orderRef, order.orderSysID) |
| | | try: |
| | | async_log_util.info(hx_logger_trade_debug, f"处理华鑫订单:{key}") |
| | | 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) |
| | | elif huaxin_util.is_canceled(order.orderStatus) or huaxin_util.is_deal( |
| | | order.orderStatus): |
| | | # 已经撤单/已经成交,需要处理临时保存的系统订单号 |
| | | cls.__TradeOrderIdManager.remove_order_id(order.code, |
| | | order.accountID, |
| | | order.orderSysID) |
| | | if huaxin_util.is_deal(order.orderStatus): |
| | | # 成交之后处理 |
| | | trade_manager.buy_success(order.code) |
| | | CancelOrderManager().buy_success(order.code, order.orderRef, order.orderSysID) |
| | | elif huaxin_util.is_canceled(order.orderStatus): |
| | | CancelOrderManager().cancel_success(order.code, order.orderRef, order.orderSysID) |
| | | except Exception as e: |
| | | async_log_util.exception(hx_logger_trade_debug, e) |
| | | |
| | | @classmethod |
| | | def order_success(cls, order: HuaxinOrderEntity): |