Administrator
2024-05-29 bf4e4247e14ec7db5d3490b4bad6f3922917662c
l2/cancel_buy_strategy.py
@@ -16,7 +16,7 @@
from db import redis_manager_delegate as redis_manager
from db.redis_manager_delegate import RedisUtils
from l2.l2_data_manager import OrderBeginPosInfo
from l2.l2_transaction_data_manager import HuaXinBuyOrderManager
from l2.l2_transaction_data_manager import HuaXinBuyOrderManager, HuaXinSellOrderStatisticManager
from trade.sell.sell_rule_manager import TradeRuleManager
from utils import tool
@@ -25,7 +25,7 @@
from l2 import l2_log, l2_data_source_util
from l2.l2_data_util import L2DataUtil, local_today_num_operate_map, local_today_datas, local_today_buyno_map, \
    local_today_canceled_buyno_map
from log_module.log import logger_buy_1_volumn
from log_module.log import logger_buy_1_volumn, logger_l2_error
from utils.tool import CodeDataCacheUtil
@@ -124,6 +124,31 @@
                    return i
        return end_index
    @classmethod
    def compute_max_buy_order_info(cls, code, start_index, end_index):
        """
        计算区间最大买单
        @param code:
        @param start_index:
        @param end_index:
        @return:
        """
        total_datas = local_today_datas.get(code)
        canceled_buyno_map = local_today_canceled_buyno_map.get(code)
        max_info = (0, None)  # 索引,手数
        for i in range(start_index, end_index + 1):
            data = total_datas[i]
            val = data['val']
            if not L2DataUtil.is_limit_up_price_buy(val):
                continue
            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(code, i,
                                                                                                     total_datas,
                                                                                                     canceled_buyno_map)
            if left_count > 0:
                if val["num"] > max_info[0]:
                    max_info = (i, val["num"])
        return total_datas[max_info[0]]
# ---------------------------------D撤-------------------------------
# 计算 成交位->真实下单位置 总共还剩下多少手没有撤单
@@ -194,6 +219,7 @@
    __db = 0
    __redis_manager = redis_manager.RedisManager(0)
    __real_order_index_cache = {}
    __max_buy_order_num_cache = {}
    __instance = None
@@ -245,6 +271,8 @@
    def clear(self, code=None):
        if code:
            self.__del_real_order_index(code)
            if code in self.__max_buy_order_num_cache:
                self.__max_buy_order_num_cache.pop(code)
        else:
            keys = RedisUtils.keys(self.__get_redis(), "f_cancel_real_order_index-*")
            if keys:
@@ -255,6 +283,19 @@
    # 设置真实的下单位置
    def set_real_order_index(self, code, index, is_default):
        self.__set_real_order_index(code, index, is_default)
        if not is_default and code.find("60") == 0:
            try:
                # 统计未成交的最大单
                trade_index = 0
                trade_info = TradeBuyQueue().get_traded_index(code)
                if trade_info and not trade_info[1] and trade_info[0] is not None:
                    trade_index = trade_info[0]
                data = L2DataComputeUtil.compute_max_buy_order_info(code, trade_index, index)
                # 保存最大单
                self.__max_buy_order_num_cache[code] = data["val"]["num"]
                l2_log.f_cancel_debug(code, f"最大单计算:索引-{data['index']} 范围:{trade_index}-{index}")
            except Exception as e:
                logger_l2_error.exception(e)
    def place_order_success(self, code):
        self.clear(code)
@@ -305,6 +346,16 @@
        # 是否是下单1分钟内
        if tool.trade_time_sub(tool.get_now_time_str(), total_datas[real_order_index]['val']['time']) > 1 * 60:
            return False, "下单超过60s"
        try:
            if code in self.__max_buy_order_num_cache:
                max_num = self.__max_buy_order_num_cache[code]
                total_num, details = HuaXinSellOrderStatisticManager.get_latest_2s_continue_deal_volume(code)
                if total_num // 100 > max_num * 0.6:
                    return True, f"连续两秒抛压过大:{total_num // 100}/{max_num}手"
        except Exception as e:
            l2_log.f_cancel_debug(code,f"大抛压撤单计算出错:{str(e)}")
        # 查询最近2秒成交是否超过阈值
        THRESHOLD_MONEY_W, THRESHOLD_COUNT = self.__get_fast_deal_threshold_value(code,
                                                                                  total_datas[real_order_index]['val'][