Administrator
2025-03-16 672cc66070f30468222bfcfd527d9090d08f8cce
新版下单方式修改
3个文件已修改
183 ■■■■■ 已修改文件
l2/l2_data_manager_new.py 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/huaxin_trade_server.py 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py
@@ -1314,14 +1314,14 @@
            # 扫入下单只有L撤能撤单
            if order_begin_pos and order_begin_pos.mode == OrderBeginPosInfo.MODE_RADICAL and cancel_type not in {
                trade_constant.CANCEL_TYPE_L_DOWN, trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_RD,
                trade_constant.CANCEL_TYPE_P}:
                trade_constant.CANCEL_TYPE_P, trade_constant.CANCEL_TYPE_F}:
                l2_log.cancel_debug(code, "撤单中断,原因:{}", "扫入下单不是L撤")
                return False
            # 加绿只有L撤/人撤生效
            if gpcode_manager.GreenListCodeManager().is_in_cache(code):
                if cancel_type not in {trade_constant.CANCEL_TYPE_L, trade_constant.CANCEL_TYPE_L_UP,
                                       trade_constant.CANCEL_TYPE_L_DOWN, trade_constant.CANCEL_TYPE_RD,
                                       trade_constant.CANCEL_TYPE_P}:
                                       trade_constant.CANCEL_TYPE_P, trade_constant.CANCEL_TYPE_F}:
                    l2_log.cancel_debug(code, "撤单中断,原因:{}", "加绿不是L撤")
                    return False
@@ -1474,7 +1474,8 @@
                RDCancelBigNumComputer().set_watch_indexes(code, radical_result[4])
            return
        else:
            radical_result = cls.__compute_radical_order_begin_pos_for_many_sell(code, compute_start_index, compute_end_index)
            radical_result = cls.__compute_radical_order_begin_pos_for_many_sell(code, compute_start_index,
                                                                                 compute_end_index)
            if radical_result[0]:
                buy_single_index, buy_exec_index = radical_result[0][0], radical_result[0][1]
                buy_volume_rate = cls.volume_rate_info[code][0]
@@ -1928,6 +1929,103 @@
            limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
            bigger_money = l2_data_util.get_big_money_val(limit_up_price, tool.is_ge_code(code))
            min_num = int(bigger_money / limit_up_price / 100)
            refer_sell_data = L2MarketSellManager().get_refer_sell_data(code, radical_data[3])
            # 参考总卖额
            refer_sell_money = 0
            if refer_sell_data:
                refer_sell_money = refer_sell_data[1]
            big_order_deal_enough_result = radical_buy_data_manager.is_big_order_deal_enough(code,
                                                                                             code_volumn_manager.CodeVolumeManager().get_volume_rate_refer_in_5days(
                                                                                                 code),
                                                                                             refer_sell_money,
                                                                                             for_buy=True,
                                                                                             is_almost_open_limit_up=
                                                                                             radical_data[5])
            # 缺乏的大单金额
            lack_money = big_order_deal_enough_result[3]
            # 如果有大单成交就不需要看大单
            if constant.CAN_RADICAL_BUY_NEED_BIG_ORDER_EVERYTIME:
                # 每次下单都需要大单
                current_big_order_deal_money_info = EveryLimitupBigDealOrderManager.get_big_buy_deal_order_money_info(
                    code)
                if current_big_order_deal_money_info and tool.trade_time_sub(tool.get_now_time_str(),
                                                                             current_big_order_deal_money_info[1]) > 60:
                    # 60s以上就不下单了
                    return False, None, "距离上次统计大单时间过去60s", set()
            if lack_money == 0:
                if not tool.is_sh_code(code):
                    # 非上证的票看50w
                    min_num = int(5000 / limit_up_price)
            # 需要监听的大单
            watch_indexes = set()
            # 总委托大单金额
            total_delegating_big_money = 0
            single_index = None
            # 从成交进度位开始看
            trade_index, is_default = cls.__TradeBuyQueue.get_traded_index(code)
            if trade_index is None:
                trade_index = 0
            canceled_buyno_map = local_today_canceled_buyno_map.get(code)
            for i in range(trade_index, end_index + 1):
                data = total_datas[i]
                val = data["val"]
                if not L2DataUtil.is_limit_up_price_buy(val):
                    continue
                if val["num"] < min_num:
                    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:
                    continue
                # 上证有可能是部分成交的大单
                if i == start_index and tool.is_sh_code(code):
                    dealing_active_order_info = HuaXinBuyOrderManager().get_dealing_active_order_info(code)
                    if dealing_active_order_info and dealing_active_order_info[0] == int(val["orderNo"]):
                        # 判断是否为大单
                        order_money = dealing_active_order_info[2] + round(val["price"], 2) * val["num"] * 100
                        if order_money >= bigger_money:
                            lack_money -= order_money
                            watch_indexes.add(i)
                            if lack_money < 0:
                                single_index = i
                                break
                if int(val["orderNo"]) <= radical_data[1]:
                    # 主动买单后的数据不算
                    continue
                watch_indexes.add(i)
                lack_money -= round(val["price"], 2) * val["num"] * 100
                if lack_money < 0:
                    single_index = i
                    break
            if single_index is not None:
                return True, single_index, "有大单", watch_indexes
            return False, None, f"大单不足:{trade_index}-{end_index}  缺少的大单-{lack_money}", watch_indexes
        def __can_order_v2():
            # 判断是否是板上放量
            if cls.__is_at_limit_up_buy(code, start_index):
                return False, None, "板上放量", None
            total_datas = local_today_datas[code]
            limit_up_price = gpcode_manager.get_limit_up_price_as_num(code)
            bigger_money = l2_data_util.get_big_money_val(limit_up_price, tool.is_ge_code(code))
            min_num = int(bigger_money / limit_up_price / 100)
            # 统计委托大买单
            bigger_money_delegate_list = []
            for i in range(start_index, end_index + 1):
                val = total_datas[i]
                if val["num"] < min_num:
                    continue
                if not L2DataUtil.is_limit_up_price_buy(val):
                    continue
                bigger_money_delegate_list.append(
                    (val["orderNo"], int(float(val["price"]) * val["num"] * 100), val["time"]))
            radical_buy_data_manager.EveryLimitupBigDelegateOrderManager.add_big_buy_order_delegate(code,
                                                                                                    bigger_money_delegate_list)
            refer_sell_data = L2MarketSellManager().get_refer_sell_data(code, radical_data[3])
            # 参考总卖额
@@ -2018,13 +2116,15 @@
            # 板上放量可扫入
            if t.time() > radical_data[0] and not is_radical_buy:
                # 没扫入过才需要判断时间
                radical_buy_data_manager.EveryLimitupBigDelegateOrderManager.clear(code, '超过生效时间')
                return False, None, "超过生效时间"
        else:
            # 板上放量不可扫入
            if t.time() > radical_data[0]:
                radical_buy_data_manager.EveryLimitupBigDelegateOrderManager.clear(code, '超过生效时间')
                return False, None, "超过生效时间"
        result = __can_order()
        result = __can_order_v2()
        l2_log.debug(code, f"L2扫入判断:{result}")
        if result[0]:
            # 已经扫入下过单且允许板上放量扫入的就需要判断板上放量的距离
@@ -2065,6 +2165,8 @@
        @param end_index:
        @return: 信号信息(信号位,执行位), 消息, 可买入的板块
        """
        if True:
            return None, "暂不生效", None
        if not tool.is_sz_code(code):
            return None, "非深证的票", None
        # 判断抛压是否大于5000w
servers/huaxin_trade_server.py
@@ -52,8 +52,9 @@
from api.outside_api_command_callback import OutsideApiCommandCallback
from trade.huaxin.huaxin_trade_record_manager import DelegateRecordManager
from trade.order_statistic import DealAndDelegateWithBuyModeDataManager
from trade.buy_radical.radical_buy_data_manager import RadicalBuyDataManager, RadicalBuyBlockManager, \
    EveryLimitupBigDealOrderManager, RadicalCodeMarketInfoManager, BeforeSubDealBigOrderManager
from trade.buy_radical.radical_buy_data_manager import RadicalBuyDataManager, \
    EveryLimitupBigDealOrderManager, RadicalCodeMarketInfoManager, BeforeSubDealBigOrderManager, \
    EveryLimitupBigDelegateOrderManager
from trade.sell.sell_rule_manager import TradeRuleManager
from trade.trade_data_manager import RadicalBuyDealCodesManager
from trade.trade_manager import CodesTradeStateManager
@@ -969,6 +970,8 @@
        # 根据L2下单
        latest_buy_no = data[6]
        latest_deal_time = l2_huaxin_util.convert_time(data[3])
        # 清除大单委托数据
        EveryLimitupBigDelegateOrderManager.clear(code, '')
        RadicalBuyDealCodesManager.buy_by_l2_delegate_expire_time_dict[code] = (
            time.time() + 1, latest_buy_no, buy_blocks,
trade/buy_radical/radical_buy_data_manager.py
@@ -1641,6 +1641,15 @@
                temp_info = BeforeSubDealBigOrderManager().get_temp_deal_big_order_threshold_info(code)
                if temp_info:
                    THRESHOLD_MONEY = temp_info[0]
        else:
            # 没有临时大单就取L2前2个委托数据
            money_info_list = EveryLimitupBigDelegateOrderManager.get_big_buy_delegate_order_money_info(code)
            if money_info_list and len(money_info_list) >= 2:
                THRESHOLD_MONEY = sum(x[1] for x in money_info_list[:2]) // 2
            else:
                # 如果委托订单不足2个就取1亿
                THRESHOLD_MONEY = 1e8
        if THRESHOLD_MONEY < 600e4 and current_threshold_count < 3:
            # 均大单金额≤600万,则就需要加倍大单数
            current_threshold_count *= 2
@@ -1669,6 +1678,8 @@
            total_lack_money = int(total_threshold_money - total_deal_money)
        if total_lack_money < 0:
            total_lack_money = 0
    total_lack_money = 0
    # 不考虑总大单
    if current_lack_money == 0 and total_lack_money == 0:
        return True, f"量比-{volume_rate}, 瞬时大单成交-({current_big_order_deal_money}/{current_threshold_money}),总大单成交-({total_lack_money_info[1]}/{total_lack_money_info[2]})", before_time, 0
    return False, f"量比-{volume_rate}, 瞬时大单成交-({current_big_order_deal_money}/{current_threshold_money}),总大单成交-({total_lack_money_info[1]}/{total_lack_money_info[2]})", before_time, max(
@@ -1677,7 +1688,7 @@
class EveryLimitupBigDealOrderManager:
    """
    每次上板的大单管理
    每次上板的成交大单管理
    """
    # 成交大单的订单号:{"code":{"order_no",...}}
    __deal_big_order_infos_dict = {}
@@ -1734,6 +1745,59 @@
        return None
class EveryLimitupBigDelegateOrderManager:
    """
    每次上板的委托大单管理
    """
    # 成交大单的订单号:{"code":{"order_no",...}}
    __delegate_big_order_infos_dict = {}
    # 成交大单号
    __delegate_big_order_no_dict = {}
    @classmethod
    def clear(cls, code, msg=""):
        if code in cls.__delegate_big_order_infos_dict:
            cls.__delegate_big_order_infos_dict.pop(code)
        if code in cls.__delegate_big_order_no_dict:
            cls.__delegate_big_order_no_dict.pop(code)
    @classmethod
    def add_big_buy_order_delegate(cls, code, order_infos: list):
        """
        加入大单成交
        @param code:
        @param order_infos:[(订单号,金额, 最后成交时间)]
        @return:
        """
        if code not in cls.__delegate_big_order_infos_dict:
            cls.__delegate_big_order_infos_dict[code] = []
        if code not in cls.__delegate_big_order_no_dict:
            cls.__delegate_big_order_no_dict[code] = set()
        for order_info in order_infos:
            if order_info[0] not in cls.__delegate_big_order_no_dict[code]:
                cls.__delegate_big_order_infos_dict[code].append(order_info)
                cls.__delegate_big_order_no_dict[code].add(order_info[0])
                async_log_util.info(logger_l2_radical_buy_data, f"添加每次上板的大单委托:{code}-{order_info}")
    @classmethod
    def get_big_buy_delegate_order_count(cls, code):
        if code in cls.__delegate_big_order_infos_dict:
            return len(cls.__delegate_big_order_infos_dict[code])
        return 0
    @classmethod
    def get_big_buy_delegate_order_money(cls, code):
        if code in cls.__delegate_big_order_infos_dict:
            return sum([x[1] for x in cls.__delegate_big_order_infos_dict[code]])
        return 0
    @classmethod
    def get_big_buy_delegate_order_money_info(cls, code):
        return cls.__delegate_big_order_infos_dict.get(code)
def __get_deal_reasons(code):
    """
    获取成交的原因