Administrator
2023-04-24 70f473d20da7532f4cb2f84b7e82b0bcee357700
修复大单bug,优化买入时的档口要求
3个文件已修改
52 ■■■■ 已修改文件
l2/code_price_manager.py 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2_trade_test.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/code_price_manager.py
@@ -11,6 +11,7 @@
class Buy1PriceManager:
    __redisManager = redis_manager.RedisManager(1)
    __latest_data = {}
    __current_buy_1_price = {}
    @classmethod
    def __get_redis(cls):
@@ -30,6 +31,21 @@
        data = json.loads(data)
        return data[0], data[1]
    @classmethod
    def __save_buy1_price(cls, code, buy_1_price):
        cls.__current_buy_1_price[code] = buy_1_price
        cls.__get_redis().setex(f"buy1_price-{code}", tool.get_expire(), buy_1_price)
    @classmethod
    def __get_buy1_price(cls, code):
        return cls.__get_redis().get(f"buy1_price-{code}")
    @classmethod
    def get_buy1_price(cls, code):
        if code in cls.__current_buy_1_price:
            return cls.__current_buy_1_price.get(code)
        return cls.__get_buy1_price(code)
    # 处理
    @classmethod
    def process(cls, code, buy_1_price, time_str, limit_up_price, sell_1_price, sell_1_volumn):
@@ -37,6 +53,9 @@
        if cls.__latest_data.get(code) == data_str:
            return
        cls.__latest_data[code] = data_str
        # 保存买1价格
        cls.__save_buy1_price(code, buy_1_price)
        # 记录日志
        logger_trade_queue_price_info.info(
            f"code={code} data: time_str-{time_str}, buy_1_price-{buy_1_price},limit_up_price-{limit_up_price},sell_1_price-{sell_1_price},sell_1_volumn-{sell_1_volumn}")
l2/l2_data_manager_new.py
@@ -672,6 +672,25 @@
    def __can_buy_first(cls, code):
        if not trade_manager.TradeStateManager.is_can_buy():
            return False, True, f"今日已禁止交易"
        # 判断买1价格档位
        zyltgb = global_util.zyltgb_map.get(code)
        if zyltgb is None:
            global_data_loader.load_zyltgb()
            zyltgb = global_util.zyltgb_map.get(code)
        buy1_price = code_price_manager.Buy1PriceManager.get_buy1_price(code)
        if buy1_price is None:
            return False, True, f"尚未获取到买1价"
        limit_up_price = gpcode_manager.get_limit_up_price(code)
        dif = float(limit_up_price) - float(buy1_price)
        if zyltgb >= 80 * 100000000:
            # 大于2档
            if dif > 0.02001:
                return False, True, f"买1剩余档数大于2档,买一({buy1_price})涨停({limit_up_price})"
        else:
            if dif > 0.03001:
                return False, True, f"买1剩余档数大于3档,买一({buy1_price})涨停({limit_up_price})"
        limit_up_info = code_price_manager.Buy1PriceManager.get_limit_up_info(code)
        if limit_up_info[0] is None and False:
            total_data = local_today_datas.get(code)
@@ -707,10 +726,6 @@
            score = cls.__l2PlaceOrderParamsManagerDict[code].score
            score_info = cls.__l2PlaceOrderParamsManagerDict[code].score_info
            zyltgb = global_util.zyltgb_map.get(code)
            if zyltgb is None:
                global_data_loader.load_zyltgb()
                zyltgb = global_util.zyltgb_map.get(code)
            # 区分大票,小票
            if zyltgb >= 80 * 100000000:
                if cls.volume_rate_info[code][0] < 0.5:
@@ -1132,15 +1147,17 @@
            l2_log.buy_debug(code, "位置-{},总手数:{},目标手数:{}", i,
                             buy_nums, threshold_num)
            max_buy_num_set_count = 0
            for i in max_buy_num_set:
                max_buy_num_set_count += total_datas[i]["re"]
            # 有撤单信号,且小于阈值
            if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy and len(
                    max_buy_num_set) >= big_num_count:
            if buy_nums >= threshold_num and buy_count >= get_threshold_count() and trigger_buy and max_buy_num_set_count >= big_num_count:
                return i, buy_nums, buy_count, None, max_buy_num_set
        l2_log.buy_debug(code, "尚未获取到买入执行点,起始计算位置:{} 统计纯买手数:{} 目标纯买手数:{}  统计纯买单数:{} 目标纯买单数:{} 大单数量:{} 目标大单数量:{}",
                         compute_start_index,
                         buy_nums,
                         threshold_num, buy_count, get_threshold_count(), len(max_buy_num_set), big_num_count)
                         threshold_num, buy_count, get_threshold_count(), max_buy_num_set_count, big_num_count)
        return None, buy_nums, buy_count, None, max_buy_num_set
l2_trade_test.py
@@ -87,7 +87,7 @@
    # @unittest.skip("跳过此单元测试")
    def test_trade(self):
        code = "603843"
        code = "002607"
        clear_trade_data(code)
        l2.l2_data_util.load_l2_data(code)
        total_datas = deepcopy(l2.l2_data_util.local_today_datas[code])