Administrator
2024-04-24 250dea26eab3894551751381b1757ac2b440d09d
删除之前的下单方式
4个文件已修改
258 ■■■■■ 已修改文件
l2/cancel_buy_strategy.py 77 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 177 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
output/code_info_output.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/huaxin/huaxin_trade_server.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/cancel_buy_strategy.py
@@ -318,45 +318,44 @@
        # 判断是否为激进下单
        threash_money_w = 299
        total_fast_num = 0
        if order_begin_pos.mode == OrderBeginPosInfo.MODE_ACTIVE:
            try:
                # 15分钟内真实成交位距离真实下单位,金额≤800万 ,大单阈值变为200w
                trade_index, is_default = TradeBuyQueue().get_traded_index(code)
                if trade_index is None:
                    trade_index = 0
                if real_order_index_info and not real_order_index_info[1]:
                    real_order_index = real_order_index_info[0]
                    # 开始第一笔成交数据
                    fdeal = big_sell_order_info[1][0][3]
                    start_order_no = fdeal[1]
                    sell_time_str = l2_huaxin_util.convert_time(fdeal[0], with_ms=False)
                    if tool.trade_time_sub(sell_time_str, total_datas[real_order_index]['val']['time']) < 15 * 60:
                        total_num = 0
                        # 获取正在成交的数据
                        dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code)
                        for i in range(trade_index, real_order_index):
                            data = total_datas[i]
                            val = data['val']
                            if int(val['orderNo']) < start_order_no:
                                continue
                            if i == trade_index and dealing_info and str(
                                    total_datas[trade_index]["val"]["orderNo"]) == str(
                                dealing_info[0]):
                                # 减去当前正在成交的数据中已经成交了的数据
                                total_num -= dealing_info[1] // 100
                            left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                                code,
                                i,
                                total_datas,
                                local_today_canceled_buyno_map.get(
                                    code))
                            if left_count > 0:
                                total_num += val["num"]
                                total_fast_num += val['num']
                        if total_num * float(limit_up_price) < 800 * 100:
                            threash_money_w = 200
            except Exception as e:
                l2_log.s_cancel_debug(code, f"S撤激进下单计算大单卖阈值出错:{str(e)}")
        try:
            # 15分钟内真实成交位距离真实下单位,金额≤800万 ,大单阈值变为200w
            trade_index, is_default = TradeBuyQueue().get_traded_index(code)
            if trade_index is None:
                trade_index = 0
            if real_order_index_info and not real_order_index_info[1]:
                real_order_index = real_order_index_info[0]
                # 开始第一笔成交数据
                fdeal = big_sell_order_info[1][0][3]
                start_order_no = fdeal[1]
                sell_time_str = l2_huaxin_util.convert_time(fdeal[0], with_ms=False)
                if tool.trade_time_sub(sell_time_str, total_datas[real_order_index]['val']['time']) < 15 * 60:
                    total_num = 0
                    # 获取正在成交的数据
                    dealing_info = HuaXinBuyOrderManager.get_dealing_order_info(code)
                    for i in range(trade_index, real_order_index):
                        data = total_datas[i]
                        val = data['val']
                        if int(val['orderNo']) < start_order_no:
                            continue
                        if i == trade_index and dealing_info and str(
                                total_datas[trade_index]["val"]["orderNo"]) == str(
                            dealing_info[0]):
                            # 减去当前正在成交的数据中已经成交了的数据
                            total_num -= dealing_info[1] // 100
                        left_count = l2_data_source_util.L2DataSourceUtils.get_limit_up_buy_no_canceled_count_v2(
                            code,
                            i,
                            total_datas,
                            local_today_canceled_buyno_map.get(
                                code))
                        if left_count > 0:
                            total_num += val["num"]
                            total_fast_num += val['num']
                    if total_num * float(limit_up_price) < 800 * 100:
                        threash_money_w = 200
        except Exception as e:
            l2_log.s_cancel_debug(code, f"S撤激进下单计算大单卖阈值出错:{str(e)}")
        total_fast_money = int(total_fast_num * 100 * float(limit_up_price))
        if total_fast_money == 0:
            # 防止分母为0
l2/l2_data_manager_new.py
@@ -947,12 +947,13 @@
            # 2.总卖额为0
            if abs(float(limit_up_price) - float(trade_price)) < 0.001:
                sell_data = cls.__L2MarketSellManager.get_current_total_sell_data(code)
                if sell_data and sell_data[1]<=0:
                if sell_data and sell_data[1] <= 0:
                    # 板上放量,判断是否有放量,放量才会下单
                    # 获取最近1s的主动卖金额
                    min_time =  total_data[order_begin_pos.buy_single_index]['val']['time']
                    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,
                                                                                             compute_start_index,
                                                                                             compute_end_index)
            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,25 +1394,8 @@
                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)
                # 总卖额的1倍
                order_begin_pos.threshold_money = int(sell_info[1] * 1.0)
                l2_log.debug(code, "获取到买入信号起始点:{} ,计算范围:{}-{} ,量比:{},是否板上买:{},数据:{} 模式:{}({}) 信号类型:{}",
                             buy_single_index,
@@ -1457,42 +1423,19 @@
        # 买入纯买额统计
        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,
                start_process_index,
                compute_end_index,
                order_begin_pos.num,
                order_begin_pos.count,
                order_begin_pos.threshold_money,
                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)
        # 设置为总卖额
        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,
            start_process_index,
            compute_end_index,
            order_begin_pos.num,
            order_begin_pos.count,
            order_begin_pos.threshold_money,
            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
        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):
output/code_info_output.py
@@ -431,7 +431,7 @@
                                                 f"【{format_l2_data(total_datas[data['buy_single_index']])}】-【{format_l2_data(total_datas[data['buy_exec_index']])}】",
                                                 extra_datas))
                    else:
                        records_new_data.append((time_, "下单",
                        records_new_data.append((time_, "常规下单",
                                                 f"【{format_l2_data(total_datas[data['buy_single_index']])}】-【{format_l2_data(total_datas[data['buy_exec_index']])}】",
                                                 extra_datas))
                elif type == trade_record_log_util.TYPE_REAL_PLACE_ORDER_POSITION:
trade/huaxin/huaxin_trade_server.py
@@ -1754,7 +1754,7 @@
                                                            num=0, count=1,
                                                            max_num_set=set(),
                                                            buy_volume_rate=volume_rate,
                                                            mode=OrderBeginPosInfo.MODE_ACTIVE,
                                                            mode=OrderBeginPosInfo.MODE_FAST,
                                                            sell_info=None,
                                                            threshold_money=0)
                        l2_data_manager_new.L2TradeDataProcessor.save_order_begin_data(code, order_begin_pos)