| | |
| | | return False, None |
| | | watch_indexes = set([int(i) for i in watch_indexes]) |
| | | # 计算监听的总条数 |
| | | total_count = 0 |
| | | total_num = 0 |
| | | for wi in watch_indexes: |
| | | total_count += total_data[wi]["re"] |
| | | total_num += total_data[wi]["val"]["num"]*total_data[wi]["re"] |
| | | # 判断撤单中是否有监听中的索引 |
| | | need_compute = False |
| | | for i in range(start_index, end_index + 1): |
| | |
| | | # 计算撤单比例 |
| | | watch_indexes_list = list(watch_indexes) |
| | | watch_indexes_list.sort() |
| | | canceled_count = 0 |
| | | canceled_num = 0 |
| | | for wi in watch_indexes: |
| | | left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count(code, |
| | | wi, |
| | | total_data, |
| | | _local_today_num_operate_map) |
| | | canceled_count += total_data[wi]["re"] - left_count |
| | | canceled_num += (total_data[wi]["re"] - left_count)*total_data[wi]["val"]["num"] |
| | | # if wi == watch_indexes_list[-1] and left_count == 0: |
| | | # # 离下单位置最近的一个撤单,必须触发撤单 |
| | | # l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},临近撤单:{wi}") |
| | | # return True, total_data[-1] |
| | | |
| | | rate = round(canceled_count / total_count, 3) |
| | | rate = round(canceled_num / total_num, 3) |
| | | l2_log.l_cancel_debug(code, f"计算范围:{start_index}-{end_index},已撤单比例:{rate}") |
| | | if rate >= constant.L_CANCEL_RATE: |
| | | return True, total_data[-1] |
| | |
| | | insertTime = data.get("insertTime") |
| | | acceptTime = data.get("acceptTime") |
| | | insertDate = data.get("insertDate") |
| | | direction = data.get("direction") |
| | | |
| | | order = HuaxinOrderEntity(code, orderStatus, orderRef, accountID, orderSysID, |
| | | insertTime=insertTime, acceptTime=acceptTime, |
| | | insertDate=insertDate) |
| | | insertDate=insertDate, direction=direction) |
| | | TradeResultProcessor.process_order(order) |
| | | # 订单相关回调 |
| | | # 重新请求委托列表与资金 |
| | |
| | | raise Exception(resultJSON['statusMsg']) |
| | | else: |
| | | # code, orderStatus, orderRef, accountID, orderSysID, insertTime=None |
| | | order = HuaxinOrderEntity(resultJSON['securityId'],statusCode,resultJSON['orderRef'],resultJSON['accountID'],resultJSON['orderSysID'],resultJSON['insertTime']) |
| | | order = HuaxinOrderEntity(resultJSON['securityId'], statusCode, |
| | | resultJSON['orderRef'], resultJSON['accountID'], |
| | | resultJSON['orderSysID'], |
| | | resultJSON['insertTime'], |
| | | acceptTime=resultJSON['acceptTime'], |
| | | direction=resultJSON['direction']) |
| | | TradeResultProcessor.order_success(order) |
| | | return_str = json.dumps({"code": 0}) |
| | | finally: |
| | |
| | | insertTime = d.get('insertTime') |
| | | acceptTime = d.get('acceptTime') |
| | | insertDate = d.get('insertDate') |
| | | direction = data.get("direction") |
| | | |
| | | order = HuaxinOrderEntity(code, orderStatus, orderRef, accountID, orderSysID, |
| | | insertTime=insertTime, acceptTime=acceptTime, |
| | | insertDate=insertDate) |
| | | insertDate=insertDate, direction=direction) |
| | | TradeResultProcessor.process_order(order) |
| | | if huaxin_util.is_can_cancel(orderStatus): |
| | | codes.append(code) |
| | |
| | | |
| | | |
| | | 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): |