| | |
| | | if order_begin_pos.mode != OrderBeginPosInfo.MODE_RADICAL: |
| | | # 非扫入下单要判断执行位置与真实下单位的间隔时间 |
| | | total_datas = local_today_datas.get(code) |
| | | if tool.trade_time_sub_with_ms(L2DataUtil.get_time_with_ms(total_datas[index]["val"]), L2DataUtil.get_time_with_ms(total_datas[order_begin_pos.buy_exec_index]["val"])) > 2000: |
| | | if tool.trade_time_sub_with_ms(L2DataUtil.get_time_with_ms(total_datas[index]["val"]), |
| | | L2DataUtil.get_time_with_ms( |
| | | total_datas[order_begin_pos.buy_exec_index]["val"])) > 2000: |
| | | L2TradeDataProcessor.cancel_buy(code, f"真实下单位({index})与执行位({order_begin_pos.buy_exec_index})相差2s以上", |
| | | cancel_type=trade_constant.CANCEL_TYPE_F) |
| | | return |
| | | |
| | | |
| | | # 处理华鑫L2数据 |
| | | @classmethod |
| | |
| | | |
| | | @classmethod |
| | | def start_buy(cls, code, last_data, last_data_index, is_first_code): |
| | | pre_result = cls.__is_pre_can_buy(code) |
| | | if pre_result[0]: |
| | | cls.__buy(code, 0, last_data, last_data_index, is_first_code) |
| | | cls.__buy(code, 0, last_data, last_data_index, is_first_code) |
| | | |
| | | @classmethod |
| | | def get_active_buy_blocks(cls, code): |
| | |
| | | |
| | | @classmethod |
| | | def __buy(cls, code, capture_timestamp, last_data, last_data_index, is_first_code): |
| | | pre_result = cls.__is_pre_can_buy(code) |
| | | if not pre_result[0]: |
| | | return False |
| | | # 添加买入锁 |
| | | if code not in cls.__buy_lock_dict: |
| | | cls.__buy_lock_dict[code] = threading.Lock() |
| | |
| | | |
| | | pre_result = cls.__is_pre_can_buy(code) |
| | | if not pre_result[0]: |
| | | return pre_result[0],pre_result[1], pre_result[2], pre_result[3] |
| | | return pre_result[0], pre_result[1], pre_result[2], pre_result[3] |
| | | |
| | | now_time_int = int(tool.get_now_time_str().replace(":", "")) |
| | | if 130100 >= now_time_int >= 112900 or now_time_int < 93100: |
| | |
| | | # ------------挂单时间约束---------- |
| | | order_begin_pos = cls.__get_order_begin_pos( |
| | | code) |
| | | if not trade_result_manager.can_place_order_for_cancel_time(code, total_data[order_begin_pos.buy_exec_index]) and not gpcode_manager.GreenListCodeManager().is_in_cache(code): |
| | | if not trade_result_manager.can_place_order_for_cancel_time(code, total_data[ |
| | | order_begin_pos.buy_exec_index]) and not gpcode_manager.GreenListCodeManager().is_in_cache(code): |
| | | return False, True, f"距离上次挂单小于时间限制", True |
| | | |
| | | # ------------板块约束------------- |
| | |
| | | |
| | | @classmethod |
| | | def cancel_buy(cls, code, msg=None, source="l2", cancel_index=None, cancel_type=None): |
| | | # 是否是交易队列触发 |
| | | |
| | | finally_can_cancel = True |
| | | total_datas = local_today_datas.get(code) |
| | | order_begin_pos = cls.__get_order_begin_pos( |
| | | code) |
| | | # 扫入下单只有L撤能撤单 |
| | | if order_begin_pos and order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL and cancel_type not in { |
| | | trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP, trade_constant.CANCEL_TYPE_L_DOWN}: |
| | | l2_log.cancel_debug(code, "撤单中断,原因:{}", "扫入下单不是L撤") |
| | | return False |
| | | # 加绿只有L撤生效 |
| | | if gpcode_manager.GreenListCodeManager().is_in_cache(code): |
| | | if cancel_type not in { trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP, trade_constant.CANCEL_TYPE_L_DOWN}: |
| | | l2_log.cancel_debug(code, "撤单中断,原因:{}", "加绿不是L撤") |
| | | if cancel_type != trade_constant.CANCEL_TYPE_HUMAN: |
| | | # 是否是交易队列触发 |
| | | # 扫入下单只有L撤能撤单 |
| | | if order_begin_pos and order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL and cancel_type not in { |
| | | trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP, trade_constant.CANCEL_TYPE_L_DOWN}: |
| | | l2_log.cancel_debug(code, "撤单中断,原因:{}", "扫入下单不是L撤") |
| | | return False |
| | | total_datas = local_today_datas.get(code) |
| | | if not total_datas: |
| | | return False |
| | | if source == "trade_queue": |
| | | # 交易队列触发的需要下单后5s |
| | | if order_begin_pos.buy_exec_index is not None and order_begin_pos.buy_exec_index > 0: |
| | | now_time_str = tool.get_now_time_str() |
| | | if tool.trade_time_sub(now_time_str, total_datas[order_begin_pos.buy_exec_index]["val"]["time"]) < 5: |
| | | # 加绿只有L撤/人撤生效 |
| | | if gpcode_manager.GreenListCodeManager().is_in_cache(code): |
| | | if cancel_type not in {trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP, |
| | | trade_constant.CANCEL_TYPE_L_DOWN}: |
| | | l2_log.cancel_debug(code, "撤单中断,原因:{}", "加绿不是L撤") |
| | | return False |
| | | |
| | | if code in cls.unreal_buy_dict: |
| | | cls.unreal_buy_dict.pop(code) |
| | | # 取消买入标识 |
| | | trade_result_manager.virtual_cancel_success(code, order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index, total_datas) |
| | | else: |
| | | can_cancel, reason = cls.__can_cancel(code) |
| | | if not can_cancel and cancel_type != trade_constant.CANCEL_TYPE_HUMAN: |
| | | # 不能取消且不是人工撤单 |
| | | l2_log.cancel_debug(code, "撤单中断,原因:{}", reason) |
| | | l2_log.debug(code, "撤单中断,原因:{}", reason) |
| | | if not total_datas: |
| | | return False |
| | | if source == "trade_queue": |
| | | # 交易队列触发的需要下单后5s |
| | | if order_begin_pos.buy_exec_index is not None and order_begin_pos.buy_exec_index > 0: |
| | | now_time_str = tool.get_now_time_str() |
| | | if tool.trade_time_sub(now_time_str, |
| | | total_datas[order_begin_pos.buy_exec_index]["val"]["time"]) < 5: |
| | | return False |
| | | |
| | | if code in cls.unreal_buy_dict: |
| | | cls.unreal_buy_dict.pop(code) |
| | | # 取消买入标识 |
| | | trade_result_manager.virtual_cancel_success(code, order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index, total_datas) |
| | | else: |
| | | can_cancel, reason = cls.__can_cancel(code) |
| | | if not can_cancel: |
| | | # 不能取消且不是人工撤单 |
| | | l2_log.cancel_debug(code, "撤单中断,原因:{}", reason) |
| | | l2_log.debug(code, "撤单中断,原因:{}", reason) |
| | | return False |
| | | |
| | | if finally_can_cancel: |
| | | if cancel_index is None: |
| | | cancel_index = total_datas[-1]["index"] |
| | | cls.__LatestCancelIndexManager.set_latest_cancel_index(code, cancel_index) |
| | |
| | | trade_result_manager.real_cancel_success(code, order_begin_pos.buy_single_index, |
| | | order_begin_pos.buy_exec_index, total_datas, |
| | | from_real_cancel=True) |
| | | l2_log.debug(code, "执行撤单结束,原因:{}", msg) |
| | | l2_log.debug(code, "执行撤单结束,原因:{}", msg) |
| | | return True |
| | | |
| | | # 虚拟下单 |
| | |
| | | max_num_set=set(), |
| | | buy_volume_rate=buy_volume_rate, |
| | | mode=OrderBeginPosInfo.MODE_RADICAL, |
| | | mode_desc="激进买入", |
| | | mode_desc="总抛压小扫入", |
| | | sell_info=sell_info, |
| | | threshold_money=threshold_money) |
| | | order_begin_pos_info.at_limit_up = cls.__is_at_limit_up_buy(code) |