Administrator
2024-04-24 250dea26eab3894551751381b1757ac2b440d09d
l2/l2_data_manager_new.py
@@ -952,7 +952,8 @@
                    # 获取最近1s的主动卖金额
                    min_time =  total_data[order_begin_pos.buy_single_index]['val']['time']
                    min_time = tool.trade_time_add_second(min_time, -1)
                    sell_orders = HuaXinSellOrderStatisticManager.get_latest_transaction_datas(code, min_deal_time=min_time)
                    sell_orders = HuaXinSellOrderStatisticManager.get_latest_transaction_datas(code,
                                                                                               min_deal_time=min_time)
                    sell_order_num = sum([x[1] for x in sell_orders])
                    sell_money = int(float(limit_up_price) * sell_order_num)
                    if sell_money < 2990000:
@@ -1337,37 +1338,17 @@
            # if code.find('60') == 0:
            # 激进买
            continue_count = 1
            has_single, _index, sell_info, single_msg = cls.__compute_active_order_begin_pos(code, continue_count,
            has_single, _index, sell_info, single_msg, mode = cls.__compute_active_order_begin_pos(code, continue_count,
                                                                                             compute_start_index,
                                                                                             compute_end_index)
            fast_msg = None
            if has_single:
                order_begin_pos.mode = OrderBeginPosInfo.MODE_ACTIVE
                order_begin_pos.mode = mode
                order_begin_pos.sell_info = sell_info
                fast_msg = sell_info
                # 用了信号就必须清除掉原有信号
                place_order_single_data_manager.L2TradeSingleDataManager.clear_data(code)
            # if not has_single:
            #     # 第二步:计算闪电下单信号
            #     has_single, _index, sell_info = cls.__compute_fast_order_begin_pos(code, compute_start_index,
            #                                                                        compute_end_index)
            #     fast_msg = None
            #     if has_single:
            #         order_begin_pos.mode = OrderBeginPosInfo.MODE_FAST
            #         order_begin_pos.sell_info = sell_info
            #     elif _index is not None and _index < 0:
            #         fast_msg = sell_info
            #         # 第三步: 计算常规买入信号
            #         has_single, _index = cls.__compute_order_begin_pos(code, max(
            #             (compute_start_index - continue_count - 1) if new_add else compute_start_index, 0),
            #                                                            continue_count,
            #                                                            compute_end_index)
            #         order_begin_pos.mode = OrderBeginPosInfo.MODE_NORMAL
            #         # 获取最新的买信息
            #         sell_info = cls.__L2MarketSellManager.get_current_total_sell_data(code)
            #         order_begin_pos.sell_info = sell_info
            # 如果买入信号与上次的买入信号一样就不能算新的信号
            if cls.__last_buy_single_dict.get(code) == _index:
                has_single = None
                _index = None
@@ -1377,32 +1358,34 @@
                order_begin_pos.at_limit_up = cls.__is_at_limit_up_buy(code)
                # -------------计算信号位到成交位的纯买额(过远则为无效位置)-------------------
                if order_begin_pos.at_limit_up:
                    # 信号位是否有效
                    pass
                    # 获取成交进度位置
                    trade_index, is_default = TradeBuyQueue().get_traded_index(code)
                    if trade_index and not is_default:
                        m_base_val = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
                        thresh_hold_num = m_base_val * 4 // (float(gpcode_manager.get_limit_up_price(code)) * 100)
                        # 真实下单位到成交位置的纯买额 * 3
                        total_num = 0
                        for i in range(trade_index + 1, buy_single_index):
                            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,
                                data["index"],
                                total_datas,
                                local_today_canceled_buyno_map.get(
                                    code))
                            total_num += left_count * val["num"]
                            if total_num > thresh_hold_num:
                                break
                        if total_num > thresh_hold_num:
                            # 距离成交进度位置过远
                            l2_log.debug(code,
                                         f"获取的信号位无效(板上买,范围:{trade_index + 1}-{order_begin_pos.buy_single_index} 未成交总手{total_num}/阈值{thresh_hold_num})")
                            return None
                    # trade_index, is_default = TradeBuyQueue().get_traded_index(code)
                    # if trade_index and not is_default:
                    #     m_base_val = l2_trade_factor.L2PlaceOrderParamsManager.get_base_m_val(code)
                    #     thresh_hold_num = m_base_val * 4 // (float(gpcode_manager.get_limit_up_price(code)) * 100)
                    #     # 真实下单位到成交位置的纯买额 * 3
                    #     total_num = 0
                    #     for i in range(trade_index + 1, buy_single_index):
                    #         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,
                    #             data["index"],
                    #             total_datas,
                    #             local_today_canceled_buyno_map.get(
                    #                 code))
                    #         total_num += left_count * val["num"]
                    #         if total_num > thresh_hold_num:
                    #             break
                    #     if total_num > thresh_hold_num:
                    #         # 距离成交进度位置过远
                    #         l2_log.debug(code,
                    #                      f"获取的信号位无效(板上买,范围:{trade_index + 1}-{order_begin_pos.buy_single_index} 未成交总手{total_num}/阈值{thresh_hold_num})")
                    #         return None
                # -----------------------------买入计算初始化,计算纯买额阈值-----------------------
                cls.__last_buy_single_dict[code] = buy_single_index
@@ -1411,23 +1394,6 @@
                order_begin_pos.count = 0
                order_begin_pos.buy_single_index = buy_single_index
                # 调整闪电下单的买入阈值
                if order_begin_pos.sell_info and order_begin_pos.mode == OrderBeginPosInfo.MODE_FAST:
                    situation = cls.__MarketSituationManager.get_situation_cache()
                    if sell_info[1] > 2000 * 10000 and situation != MarketSituationManager.SITUATION_GOOD:
                        # 市场行情好时不打折
                        if code.find('00') == 0:
                            # 深圳首次下单打折
                            place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
                            if place_order_count is not None and place_order_count == 0:
                                order_begin_pos.threshold_money = int(sell_info[1])
                            else:
                                order_begin_pos.threshold_money = int(sell_info[1] * 0.6)
                        else:
                            order_begin_pos.threshold_money = int(sell_info[1] * 0.8)
                    else:
                        order_begin_pos.threshold_money = int(sell_info[1])
                if order_begin_pos.sell_info and order_begin_pos.mode == OrderBeginPosInfo.MODE_ACTIVE:
                    # 总卖额的1倍
                    order_begin_pos.threshold_money = int(sell_info[1] * 1.0)
@@ -1457,7 +1423,7 @@
        # 买入纯买额统计
        new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new, not_buy_msg = None, None, None, None, [], ""
        if order_begin_pos.mode == OrderBeginPosInfo.MODE_ACTIVE:
            # 设置为总卖额
            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(
                code,
@@ -1469,30 +1435,7 @@
                order_begin_pos.buy_single_index, order_begin_pos.max_num_set, order_begin_pos.sell_info[1])
            threshold_money = threshold_money_new
            order_begin_pos.threshold_money = threshold_money
        elif order_begin_pos.mode == OrderBeginPosInfo.MODE_FAST:
            threshold_money = order_begin_pos.threshold_money
            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_fast(
                code,
                start_process_index,
                compute_end_index,
                order_begin_pos.num,
                order_begin_pos.count,
                threshold_money,
                order_begin_pos.buy_single_index, order_begin_pos.max_num_set)
            threshold_money = threshold_money_new
            order_begin_pos.threshold_money = threshold_money
        else:
            new_buy_exec_index, buy_nums, buy_count, rebegin_buy_pos, max_num_set_new, not_buy_msg = cls.__sum_buy_num_for_order_3(
                code,
                start_process_index,
                compute_end_index,
                order_begin_pos.num,
                order_begin_pos.count,
                threshold_money,
                order_begin_pos.buy_single_index,
                order_begin_pos.max_num_set,
                order_begin_pos.at_limit_up)
        l2_log.debug(code, "m值-{} 量比:{} rebegin_buy_pos:{}", threshold_money, cls.volume_rate_info[code][0],
                     rebegin_buy_pos)
@@ -1522,11 +1465,6 @@
            l2_log.debug(code, "delete_buy_cancel_point")
            # 直接下单
            ordered = cls.__buy(code, capture_time, total_datas[-1], total_datas[-1]["index"], is_first_code)
            # 保存闪电下单的买入信息
            if order_begin_pos.mode == OrderBeginPosInfo.MODE_FAST:
                cls.__latest_fast_place_order_info_dict[code] = (
                    order_begin_pos.sell_info[0], order_begin_pos.sell_info[1])
            # 数据是否处理完毕
            if new_buy_exec_index < compute_end_index:
@@ -1733,7 +1671,7 @@
        total_datas = local_today_datas[code]
        start_time_str = total_datas[start_index]["val"]["time"]
        if end_index - start_index + 1 < continue_count:
            return False, -1, "信号不连续", ''
            return False, -1, "信号不连续", '', OrderBeginPosInfo.MODE_NORMAL
        # 获取最近的总卖信息
        # (time_str, round(money), volume, sell_1_info)
        refer_sell_data = cls.__L2MarketSellManager.get_refer_sell_data(code, start_time_str)
@@ -1752,12 +1690,12 @@
                # 金额要大于50万
                if _val["num"] * float(_val["price"]) < 5000:
                    continue
                return True, i, [refer_sell_data[0], 0], '上证买入'
            return False, -1, "未获取到激进买的起始信号", ''
                return True, i, [refer_sell_data[0], 0], '上证买入', OrderBeginPosInfo.MODE_FAST
            return False, -1, "未获取到激进买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL
        else:
            # 深证
            if refer_sell_data is None:
                return False, -1, "总卖为空", ''
                return False, -1, "总卖为空", '', OrderBeginPosInfo.MODE_NORMAL
            if refer_sell_data is None:
                refer_sell_data = (start_time_str, 0, 0, (round(float(total_datas[start_index]["val"]["price"]), 2), 0))
                l2_log.debug(code, f"丢失总卖额,设置默认为0,计算范围:{start_index}-{end_index}")
@@ -1793,22 +1731,23 @@
                    buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count,
                                                                           valid_single=False)
                    if buy_single_index is not None:
                        return True, buy_single_index, [refer_sell_data[0], threshold_money], "上板无涨停卖"
                        return True, buy_single_index, [refer_sell_data[0],
                                                        threshold_money], "上板无涨停卖", OrderBeginPosInfo.MODE_NORMAL
                else:
                    # 按照成交买入信号计算
                    buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count,
                                                                           valid_single=True)
                    if buy_single_index is not None:
                        return True, buy_single_index, [refer_sell_data[0], 0], "上板有成交买入信号"
                        return True, buy_single_index, [refer_sell_data[0], 0], "上板有成交买入信号", OrderBeginPosInfo.MODE_FAST
            else:
                # 板上放量:只需要一笔涨停买可作为信号
                buy_single_index = cls.__get_active_single_start_index(code, start_index, end_index, continue_count,
                                                                       valid_single=False)
                if buy_single_index is not None:
                    return True, buy_single_index, [refer_sell_data[0], 0], "板上放量"
                    return True, buy_single_index, [refer_sell_data[0], 0], "板上放量", OrderBeginPosInfo.MODE_NORMAL
        return False, -1, "未获取到激进买的起始信号", ''
        return False, -1, "未获取到激进买的起始信号", '', OrderBeginPosInfo.MODE_NORMAL
    @classmethod
    def test__compute_active_order_begin_pos(cls, code, continue_count, start_index, end_index):