Administrator
2024-06-05 cd830d988be0dfacd4fd5fac30630ae509fdb71b
l2/l2_data_manager_new.py
@@ -11,7 +11,7 @@
from db.redis_manager_delegate import RedisUtils
from l2.huaxin import l2_huaxin_util, huaxin_delegate_postion_manager
from l2.l2_sell_manager import L2MarketSellManager, L2LimitUpSellManager
from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager
from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager, BigOrderDealManager
from l2.place_order_single_data_manager import L2TradeSingleDataProcessor
from log_module import async_log_util, log_export
from third_data import kpl_data_manager, block_info
@@ -497,7 +497,8 @@
                    cls.__process_order(code, start_index, end_index, capture_timestamp, is_first_code)
                else:
                    # 未挂单,时间相差不大才能挂单
                    if tool.trade_time_sub(latest_time, "09:32:00") < 0 or l2.l2_data_util.L2DataUtil.is_same_time(
                    # tool.trade_time_sub(latest_time, "09:32:00") < 0
                    if l2.l2_data_util.L2DataUtil.is_same_time(
                            now_time_str, latest_time):
                        cls.__process_not_order(code, start_index, end_index, capture_timestamp, is_first_code)
            l2_log.info(code, logger_l2_process, "code:{} 处理数据范围: {}-{} 处理时间:{} 线程ID:{}", code,
@@ -964,7 +965,7 @@
        now_time_int = int(tool.get_now_time_str().replace(":", ""))
        if now_time_int >= 145700:
            return False, True, f"14:57后不能交易"
        if 130100 >= now_time_int >= 112900 or now_time_int<93100:
        if 130100 >= now_time_int >= 112900 or now_time_int < 93100:
            return False, True, f"09:31:00之前,11:29:00-13:01:00不能交易"
        # place_order_count = cls.__PlaceOrderCountManager.get_place_order_count(code)
@@ -1054,41 +1055,26 @@
                not_cancel_money = not_cancel_num * 100 * float(gpcode_manager.get_limit_up_price(code))
                if m_base_val > not_cancel_money:
                    return False, False, f"成交位置距离当前位置纯买额({not_cancel_money})小于m值({m_base_val})"
        else:
            # 判断买1价格档位
            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 >= 200 * 100000000:
                buy1_price = cls.__Buy1PriceManager.get_buy1_price(code)
                if buy1_price is None:
                    return False, True, f"尚未获取到买1价"
                dif = float(limit_up_price) - float(buy1_price)
                # 大于10档
                if dif > 0.10001:
                    return False, True, f"自由流通200亿以上,买1剩余档数大于10档,买一({buy1_price})涨停({limit_up_price})"
            # 上证下单需要有成交大单(包含主动买与被动买)或者挂买的大单
            if code.find("60") == 0:
                deal_big_order_count = BigOrderDealManager().get_total_buy_count(code)
                if deal_big_order_count < 1:
                    # 统计挂买大单
                    trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code)
                    if trade_index is None:
                        trade_index = 0
                    limit_up_price = round(float(gpcode_manager.get_limit_up_price(code)), 2)
                    # 从成交进度位到截至位置计算大单
                    min_money = l2_data_util.get_big_money_val(limit_up_price)
                    left_count, left_money = cancel_buy_strategy.L2DataComputeUtil.compute_left_buy_order(code, trade_index, total_data[-1]["index"],
                                                                                      limit_up_price,
                                                                                      min_money=min_money)
                    if left_count < 1:
                        return False, False, f"没有已挂或者成交的大单"
        open_limit_up_lowest_price = cls.__Buy1PriceManager.get_open_limit_up_lowest_price(code)
        # price_pre_close = gpcode_manager.CodePrePriceManager.get_price_pre_cache(code)
        # if open_limit_up_lowest_price and (
        #         float(open_limit_up_lowest_price) - price_pre_close) / price_pre_close < 0.05:
        #     return False, True, f"炸板后最低价跌至5%以下"
        # 回封的票,下13:15买入需要判断板块是否为独苗
        # if open_limit_up_lowest_price and int(total_data[-1]["val"]["time"].replace(":", "")) > 131500:
        #     # 获取当前票的涨停原因
        #     if code in LimitUpCodesPlateKeyManager.today_total_limit_up_reason_dict:
        #         limit_up_reason = kpl_data_manager.KPLLimitUpDataRecordManager.get_current_block(code)
        #         if limit_up_reason and limit_up_reason not in constant.KPL_INVALID_BLOCKS:
        #             # 判断是否是独苗
        #             codes = kpl_data_manager.KPLLimitUpDataRecordManager.get_current_codes_by_block(limit_up_reason)
        #             if codes:
        #                 codes = copy.deepcopy(codes)
        #                 codes.discard(code)
        #             if not codes:
        #                 return False, True, f"13:15以后炸板之后下单,({limit_up_reason}) 为独苗"
        # 暂时注释想买单功能
        if not cls.__WantBuyCodesManager.is_in_cache(code):
            # if cls.__TradeTargetCodeModeManager.get_mode_cache() == TradeTargetCodeModeManager.MODE_ONLY_BUY_WANT_CODES:
@@ -1302,8 +1288,6 @@
    @classmethod
    def can_buy_first_new(cls, code, limit_up_price):
        if 1>0:
            return True, False, "买所有"
        now_timestamp = int(tool.get_now_time_str().replace(":", ""))
        # 判断板块
@@ -1320,11 +1304,14 @@
        zylt_threshold_as_yi = buy_condition_util.get_zyltgb_threshold(situation)
        zyltgb_as_yi = round(global_util.zyltgb_map.get(code) / 100000000, 2)
        if zyltgb_as_yi >= zylt_threshold_as_yi[1]:
            return False, True, f"{zylt_threshold_as_yi[1]}亿以上的都不买({zyltgb_as_yi})"
        if zyltgb_as_yi < zylt_threshold_as_yi[0]:
            return False, True, f"{zylt_threshold_as_yi[0]}亿以下的都不买({zyltgb_as_yi})"
        if 1 > 0:
            return True, False, "买所有"
        if zyltgb_as_yi >= zylt_threshold_as_yi[1]:
            return False, True, f"{zylt_threshold_as_yi[1]}亿以上的都不买({zyltgb_as_yi})"
        msg_list = []
        if is_in_strong_time_30:
@@ -1514,7 +1501,7 @@
        # _start_time = l2_data_log.l2_time(code, tool.get_now_timestamp() - _start_time, "m值阈值计算")
        # 设置为总卖额
        new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg = cls.__sum_buy_num_for_order_active(
        new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, threshold_money_new, max_num_set_new, not_buy_msg, clear_buy_single = cls.__sum_buy_num_for_order_active(
            code,
            start_process_index,
            compute_end_index,
@@ -1525,8 +1512,9 @@
        threshold_money = threshold_money_new
        order_begin_pos.threshold_money = threshold_money
        l2_log.debug(code, "m值-{} 量比:{} rebegin_buy_pos:{}", threshold_money, cls.volume_rate_info[code][0],
                     rebegin_buy_pos)
        l2_log.debug(code, "范围:{}-{} m值-{} 量比:{} rebegin_buy_pos:{} clear_buy_single:{}", compute_start_index, compute_end_index,
                     threshold_money, cls.volume_rate_info[code][0],
                     rebegin_buy_pos, clear_buy_single)
        # 买入信号位与计算位置间隔2s及以上了
        if rebegin_buy_pos is not None:
@@ -1568,16 +1556,18 @@
        else:
            # 未达到下单条件,保存纯买额,设置纯买额
            # 记录买入信号位置
            cls.__save_order_begin_data(code, OrderBeginPosInfo(buy_single_index=buy_single_index, buy_exec_index=-1,
                                                                buy_compute_index=compute_end_index, num=buy_nums,
                                                                count=buy_count,
                                                                mode_desc=order_begin_pos.mode_desc,
                                                                max_num_set=max_num_set_new, mode=order_begin_pos.mode,
                                                                sell_info=order_begin_pos.sell_info,
                                                                threshold_money=threshold_money))
            # 记录没下单原因
            async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{not_buy_msg}")
            _start_time = t.time()
            if not clear_buy_single:
                # 没有清除信号位置就保存下单位置信息
                cls.__save_order_begin_data(code, OrderBeginPosInfo(buy_single_index=buy_single_index, buy_exec_index=-1,
                                                                    buy_compute_index=compute_end_index, num=buy_nums,
                                                                    count=buy_count,
                                                                    mode_desc=order_begin_pos.mode_desc,
                                                                    max_num_set=max_num_set_new, mode=order_begin_pos.mode,
                                                                    sell_info=order_begin_pos.sell_info,
                                                                    threshold_money=threshold_money))
                # 记录没下单原因
                async_log_util.info(logger_l2_not_buy_reasons, f"{code}#{not_buy_msg}")
                _start_time = t.time()
    # 获取下单起始信号
    @classmethod
@@ -2245,15 +2235,16 @@
            trigger_buy = False
            # 必须为连续2秒内的数据
            if L2DataUtil.time_sub_as_ms(_val, total_datas[buy_single_index]["val"]) > max_space_time_ms:
                # 清除买点数据
                cls.__TradePointManager.delete_buy_point(code)
                if i == compute_end_index:
                    # 数据处理完毕
                    return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms"
                    return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms", True
                else:
                    # 计算买入信号,不能同一时间开始计算
                    for ii in range(buy_single_index + 1, compute_end_index + 1):
                        if total_datas[buy_single_index]["val"]["time"] != total_datas[ii]["val"]["time"]:
                            return None, buy_nums, buy_count, ii, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms"
                            return None, buy_nums, buy_count, ii, threshold_money, max_buy_num_set, f"【{i}】信号不连续,囊括时间-{max_space_time_ms}ms", True
            # if L2DataUtil.is_sell(_val):
            #     threshold_money += _val["num"] * int(float(_val["price"]) * 100)
            #     threshold_num = round(threshold_money / (limit_up_price * 100))
@@ -2357,14 +2348,14 @@
                async_log_util.error(logger_l2_error, f"记录交易因子出错:{str(e)}")
            l2_log.buy_debug(code, f"激进买主动卖手数:{sell_order_num}")
            return i, buy_nums, buy_count, None, threshold_money, max_buy_num_set, "可以下单"
            return i, buy_nums, buy_count, None, threshold_money, max_buy_num_set, "可以下单", False
        l2_log.buy_debug(code, "尚未获取到买入执行点(激进买入),起始计算位置:{} 统计纯买手数:{} 目标纯买手数:{}  统计纯买单数:{} ",
                         compute_start_index,
                         buy_nums,
                         threshold_num, buy_count)
        return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, not_buy_msg
        return None, buy_nums, buy_count, None, threshold_money, max_buy_num_set, not_buy_msg, False
def test_trade_record():