Administrator
2025-01-20 e19723b0a243cc4b7ba4a77cc079242f945bd9d5
首封可买入
9个文件已修改
255 ■■■■ 已修改文件
l2/l2_data_manager.py 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager_new.py 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/data_server.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/huaxin_trade_server.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/kpl_data_constant.py 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 195 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_strategy.py 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/current_price_process_manager.py 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/trade_util.py 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/l2_data_manager.py
@@ -23,7 +23,7 @@
    # mode: 0-普通交易  1-快速交易
    def __init__(self, buy_single_index=None, buy_exec_index=-1, buy_compute_index=None, num=0, count=0,
                 max_num_set=None, buy_volume_rate=None, sell_info=None, threshold_money=None, mode=0, mode_desc=None,
                 at_limit_up=False):
                 at_limit_up=False, first_limit_up_buy=False):
        self.buy_single_index = buy_single_index
        self.buy_exec_index = buy_exec_index
        self.buy_compute_index = buy_compute_index
@@ -40,6 +40,8 @@
        self.mode_desc = mode_desc
        # 是否是板上买
        self.at_limit_up = at_limit_up
        # 是否为首封买
        self.first_limit_up_buy = first_limit_up_buy
    def get_max_num_set(self):
        if self.max_num_set:
l2/l2_data_manager_new.py
@@ -956,6 +956,10 @@
            else:
                l2_log.debug(code, "可以下单,原因:{}, 下单模式:{}", reason, order_begin_pos.mode)
                try:
                    # 判断是否为首封下单
                    order_begin_pos.first_limit_up_buy = radical_buy_data_manager.is_first_limit_up_buy(code)
                    l2_log.debug(code, "开始执行买入")
                    trade_manager.start_buy(code, capture_timestamp, last_data,
                                            last_data_index, order_begin_pos.mode, order_begin_pos.buy_exec_index)
servers/data_server.py
@@ -924,7 +924,7 @@
                        deal_big_order_detail_info = None
                        try:
                            # 获取成交大单:(参考大单金额,已成交大单金额,大单要求金额, 已成交涨停买金额, 已成交涨停卖金额)
                            th_buy = BeforeSubDealBigOrderManager().get_big_order_threshold(code)
                            th_buy, is_temp = BeforeSubDealBigOrderManager().get_big_order_threshold_info(code)
                            th_sell = BeforeSubDealBigOrderManager().get_big_sell_order_threshold(code)
                            deal_big_money_info = radical_buy_data_manager.get_total_deal_big_order_info(
                                code, gpcode_manager.get_limit_up_price_as_num(code))
servers/huaxin_trade_server.py
@@ -226,7 +226,7 @@
                                for code in codes:
                                    try:
                                        # 获取成交大单:(参考大单金额,已成交大单金额,大单要求金额)
                                        th = BeforeSubDealBigOrderManager().get_big_order_threshold(code)
                                        th, is_temp = BeforeSubDealBigOrderManager().get_big_order_threshold_info(code)
                                        deal_big_money_info = radical_buy_data_manager.get_total_deal_big_order_info(
                                            code, gpcode_manager.get_limit_up_price_as_num(code))
                                        deal_big_order_info = (
third_data/kpl_data_constant.py
@@ -113,7 +113,7 @@
                kpl_block_dict[code] = []
            kpl_block_dict[code].append((r[2], r[1]))  # (板块, 日期)
        for code in kpl_block_dict:
            if code =='002361':
            if code == '002361':
                print("")
            block_infos = kpl_block_dict.get(code)
            cls.__radical_buy_reasons_dict[code] = cls.__compute_limit_up_reasons(code, block_infos)
@@ -321,6 +321,16 @@
    def get_history_limit_up_block_codes(cls, block):
        return cls.__history_limit_up_block_codes.get(block)
    @classmethod
    def get_history_limit_up_codes(cls):
        """
        获取今日历史涨停代码
        @return:
        """
        if not cls.__history_code_data_dict:
            return set()
        return cls.__history_code_data_dict.keys()
if __name__ == "__main__":
    ContainsLimitupCodesBlocksManager()
trade/buy_radical/radical_buy_data_manager.py
@@ -16,6 +16,7 @@
from db import redis_manager_delegate as redis_manager
from db.redis_manager_delegate import RedisUtils
from l2.huaxin import l2_huaxin_util
from l2.l2_data_manager import TradePointManager
from l2.l2_data_util import L2DataUtil
from l2.l2_transaction_data_manager import BigOrderDealManager, HuaXinBuyOrderManager
from log_module import async_log_util
@@ -25,11 +26,11 @@
from third_data.kpl_data_constant import LimitUpDataConstant, LimitUpCodesBlockRecordManager
from third_data.kpl_data_manager import CodeHighLevel
from third_data.third_blocks_manager import BlockMapManager
from trade import trade_record_log_util
from trade import trade_record_log_util, trade_data_manager, trade_manager, trade_constant
from trade.buy_money_count_setting import RadicalBuyBlockCodeCountManager
from trade.buy_radical.block_special_codes_manager import BlockSpecialCodesManager
from trade.trade_data_manager import RadicalBuyDealCodesManager
from utils import tool, global_util
from utils import tool, global_util, trade_util
# RadicalBigOrderThresholdManager
@@ -46,6 +47,8 @@
    # 已经成交的累计大卖单金额:用于初次上板尚未订阅的情况
    __already_total_sell_deal_big_order_money = {}
    __redis_manager = redis_manager.RedisManager(3)
    # 临时大单阈值,初次上板使用
    __temp_big_order_threshold = {}
    def __init__(self):
        self.__load_data()
@@ -164,11 +167,26 @@
        """
        获取大单阈值
        @param code:
        @return:
        @return: 大单金额, 是否默认
        """
        if code in self.__big_order_threshold:
            return self.__big_order_threshold.get(code)
        return 2990000
            return self.__big_order_threshold.get(code), False
        return 2990000, True
    def get_big_order_threshold_info(self, code):
        """
        获取大单阈值
        @param code:
        @return:大单阈值,是否是临时大单
        """
        if not is_first_limit_up_buy(code):
            return self.get_big_order_threshold(code), False
        else:
            money = self.get_temp_deal_big_order_threshold(code)
            if not money:
                # 默认阈值为 1个亿
                money = int(round(1e8))
            return money, True
    def __get_base_big_order_threshold(self, code):
        """
@@ -232,6 +250,25 @@
            # 没有大单成交
            return False
        return True
    def set_temp_deal_big_orders(self, code, money_list):
        """
        设置临时大单
        @param code:
        @param money_list: 成交的大买单
        @return:
        """
        if code in self.__temp_big_order_threshold:
            return
        if not money_list or len(money_list) < 2:
            return
        # 计算大单: 前2个大单的均值
        self.__temp_big_order_threshold[code] = int(sum(money_list[:2]) // 2)
        async_log_util.info(logger_l2_radical_buy_data,
                            f"首次上板临时买大单:{code}-{self.__temp_big_order_threshold[code]}-{money_list[:2]}")
    def get_temp_deal_big_order_threshold(self, code):
        return self.__temp_big_order_threshold.get(code)
@tool.singleton
@@ -1193,8 +1230,8 @@
        @param code:
        @return: {激进买的板块}, 原因
        """
        # =========计算代码买入的目标板块===========
        # 获取开1的板块
        open_limit_up_code_dict = kpl_data_constant.open_limit_up_code_dict_for_radical_buy
        open_limit_up_blocks = set()
        if open_limit_up_code_dict:
@@ -1214,73 +1251,75 @@
        for k in keys_:
            block_info = cls.is_block_can_buy_with_block_in(code, k, yesterday_limit_up_codes, is_for_buy=True)
            if block_info[0]:
                if block_info[1] and False:
                    # 暂时不需要: 要求大单够了才买
                    big_deal_info = get_total_deal_big_order_info(code, gpcode_manager.get_limit_up_price_as_num(code))
                    if big_deal_info[0] <= 0:
                        keys_in_jx.add(k)
                    else:
                        msgs.append(f"【{k}】大单不够")
                else:
                    keys_in_jx.add(k)
                # if block_info[1] and False:
                #     # 暂时不需要: 要求大单够了才买
                #     big_deal_info = get_total_deal_big_order_info(code, gpcode_manager.get_limit_up_price_as_num(code), is_for_buy=True)
                #     if big_deal_info[0] <= 0:
                #         keys_in_jx.add(k)
                #     else:
                #         msgs.append(f"【{k}】大单不够")
                # else:
                keys_in_jx.add(k)
        if not keys_in_jx:
            msgs.append(f"【{keys_}】板块未在精选流入中:")
            # 板块尚未精选流入,且板块涨停代码个数是否<5个
            return set(), ",".join(msgs)
        keys_ = keys_in_jx
        match_blocks = open_limit_up_blocks & keys_
        can_buy_blocks = set()
        today_history_limit_up_codes = set([d[3] for d in LimitUpDataConstant.history_limit_up_datas])
        # 初次上板买入方式
        fmsges = []
        msges = []
        for b in match_blocks:
            # 判断板块是否该激进买
            result = cls.__is_radical_buy_with_open_limitup(code, b, yesterday_limit_up_codes)
            if result[0]:
                can_buy_blocks.add(b)
            msges.append(f"【{b}】:{result[1]}")
        fmsges.append("开1判断##" + ",".join(msges))
        if not can_buy_blocks:
            msges.clear()
            for b in keys_:
                # 板块快速启动
                result = cls.__is_radical_buy_with_block_up(code, b, yesterday_limit_up_codes)
        can_buy_blocks = set()
        if code in today_history_limit_up_codes:
            # 回封买入方式
            match_blocks = open_limit_up_blocks & keys_
            for b in match_blocks:
                # 判断板块是否该激进买
                result = cls.__is_radical_buy_with_open_limitup(code, b, yesterday_limit_up_codes)
                if result[0]:
                    can_buy_blocks.add(b)
                msges.append(f"【{b}】:{result[1]}")
            fmsges.append("板块快速启动判断##" + ",".join(msges))
            fmsges.append("开1判断##" + ",".join(msges))
            if not can_buy_blocks:
                msges.clear()
                for b in keys_:
                    # 板块快速启动
                    result = cls.__is_radical_buy_with_block_up(code, b, yesterday_limit_up_codes)
                    if result[0]:
                        can_buy_blocks.add(b)
        if not can_buy_blocks:
            msges.clear()
            for b in keys_:
                result = cls.__is_first_can_buy(code, b)
                if result[0]:
                    can_buy_blocks.add(b)
                    msges.append(f"【{b}】:{result[1]}")
            fmsges.append("板块回封判断##" + ",".join(msges))
                fmsges.append("板块快速启动判断##" + ",".join(msges))
        if not can_buy_blocks:
            msges.clear()
            for b in keys_:
                result = cls.__block_special_codes(code, b, yesterday_limit_up_codes)
                if result[0]:
                    can_buy_blocks.add(b)
                    msges.append(f"【{b}】:{result[1]}")
            fmsges.append("板块辨识度判断##" + ",".join(msges))
            if not can_buy_blocks:
                msges.clear()
                for b in keys_:
                    result = cls.__is_first_can_buy(code, b)
                    if result[0]:
                        can_buy_blocks.add(b)
                        msges.append(f"【{b}】:{result[1]}")
                fmsges.append("板块回封判断##" + ",".join(msges))
        # 如果能扫入就需要获取代码在板块中的身位
        # if can_buy_blocks:
        #     excude_codes = set()
        #     if kpl_data_constant.open_limit_up_code_dict_for_radical_buy:
        #         excude_codes |= kpl_data_constant.open_limit_up_code_dict_for_radical_buy.keys()
        #     # 剔除开1的代码
        #     for b in keys_:
        #         history_index, history_before_codes_info = cls.__get_history_index(code, b, yesterday_limit_up_codes,
        #                                                                            excude_codes)
        #         if history_index >= 4:
        #             return set(), f"在【{b}】中身位({history_index + 1})靠后"
            if not can_buy_blocks:
                msges.clear()
                for b in keys_:
                    result = cls.__block_special_codes(code, b, yesterday_limit_up_codes)
                    if result[0]:
                        can_buy_blocks.add(b)
                        msges.append(f"【{b}】:{result[1]}")
                fmsges.append("板块辨识度判断##" + ",".join(msges))
        else:
            # 首次上板, 只买辨识度
            if not can_buy_blocks:
                msges.clear()
                for b in keys_:
                    result = cls.__block_special_codes(code, b, yesterday_limit_up_codes)
                    if result[0]:
                        can_buy_blocks.add(b)
                        msges.append(f"【{b}】:{result[1]}")
                fmsges.append("板块辨识度判断##" + ",".join(msges))
        # 判断板块是否不能买
        if can_buy_blocks:
            msges.clear()
@@ -1395,13 +1434,15 @@
    return buy_money, before_buy_money, sell_money, before_sell_money
def get_total_deal_big_order_info(code, limit_up_price):
def get_total_deal_big_order_info(code, limit_up_price, is_for_buy=False):
    """
    总成交大单啊是否足够
    @param code:
    @return:(缺少的资金,总成交金额, 要求的大单金额)
    """
    THRESHOLD_MONEY = BeforeSubDealBigOrderManager().get_big_order_threshold(code)
    THRESHOLD_MONEY, is_temp_threshold_money = BeforeSubDealBigOrderManager().get_big_order_threshold_info(code)
    TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT = round(
        code_volumn_manager.CodeVolumeManager().get_radical_buy_refer_volume(code,
                                                                             limit_up_price) * limit_up_price / 1e8,
@@ -1410,6 +1451,10 @@
        TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT *= 3.3
    TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY = TOTAL_BIG_DEAL_MONEY_THRESHOLD_COUNT * THRESHOLD_MONEY
    if is_for_buy and is_temp_threshold_money:
        # 首次上板买入,大单阈值打3折
        TOTAL_BIG_DEAL_MONEY_THRESHOLD_MONEY //= 3
    big_order_detail_info = get_total_detal_big_order_details(code)
    deal_big_order_money = big_order_detail_info[0] + big_order_detail_info[1] - big_order_detail_info[2] - \
@@ -1456,7 +1501,7 @@
    current_threshold_money = current_threshold_count * 2990000
    # ==========判断总大单成交================
    total_lack_money_info = get_total_deal_big_order_info(code, limit_up_price)
    total_lack_money_info = get_total_deal_big_order_info(code, limit_up_price, is_for_buy=for_buy)
    total_lack_money, total_deal_money, total_threshold_money = total_lack_money_info[0], total_lack_money_info[1], \
                                                                total_lack_money_info[2]
    # ===========判断单次大单成交==============
@@ -1651,6 +1696,9 @@
    @param code_:
    @return:
    """
    # 只有涨停过的代码才需要拉大单
    if code_ not in LimitUpDataConstant.get_history_limit_up_codes():
        return
    response_data = requests.get(
        "http://127.0.0.1:9005/get_big_order_list?code=" + code_)
    r_str = response_data.text
@@ -1681,5 +1729,30 @@
    return None
def is_first_limit_up_buy(code):
    """
    是否是首封下单: (下单次数为0+没在涨停代码中) 或者 (处于下单状态 + 下单次数为1,且下单为首次下单)
    @param code:
    @return:
    """
    is_limit_up = code in LimitUpDataConstant.get_history_limit_up_codes()
    place_order_count = trade_data_manager.PlaceOrderCountManager().get_place_order_count(code)
    if place_order_count is None:
        place_order_count = 0
    if not is_limit_up and place_order_count == 0:
        return True
    # 如果当前代码处于下单状态,就判断下单参数中是否为首封下单
    trade_state = trade_manager.CodesTradeStateManager().get_trade_state_cache(code)
    if place_order_count == 1:
        if trade_state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or trade_state == trade_constant.TRADE_STATE_BUY_DELEGATED:
            # 处于下单状态, 需要计算是否为首封下单
            order_begin_pos = TradePointManager().get_buy_compute_start_data_cache(code)
            if order_begin_pos and order_begin_pos.first_limit_up_buy:
                return True
    return False
if __name__ == '__main__':
    pass
trade/buy_radical/radical_buy_strategy.py
@@ -6,9 +6,10 @@
from l2.huaxin import l2_huaxin_util
from l2.l2_limitup_sell_data_manager import L2LimitUpSellDataManager
from l2.l2_sell_manager import L2MarketSellManager
from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager
from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager, BigOrderDealManager
from log_module import async_log_util
from log_module.log import logger_l2_radical_buy, hx_logger_l2_transaction
from third_data.kpl_data_constant import LimitUpDataConstant
from trade.buy_radical import radical_buy_data_manager
from trade.trade_data_manager import RadicalBuyDealCodesManager
from utils import tool
@@ -72,7 +73,7 @@
    """
    涨停主动买成交
    @param code:
    @param transaction_datas:   # q.append((data['SecurityID'], data['TradePrice'], data['TradeVolume'],
    @param transaction_datas:   # ((data['SecurityID'], data['TradePrice'], data['TradeVolume'],
        #           data['OrderTime'], data['MainSeq'], data['SubSeq'], data['BuyNo'],
        #           data['SellNo'], data['ExecType']))
    @param is_almost_open_limit_up: 是否即将炸板,如果即将炸板就按照上板无大单处理
@@ -123,6 +124,13 @@
            #     __deal_active_buy_total_money[code] = 0
            #     return BUY_MODE_NONE, f"距离上个大单成交超过{THRESHOLD_TIME}ms"
    # 初次上板需要计算临时大单
    if radical_buy_data_manager.is_first_limit_up_buy(code):
        # 首封下单
        money_list = BigOrderDealManager().get_total_buy_money_list(code)
        radical_buy_data_manager.BeforeSubDealBigOrderManager().set_temp_deal_big_orders(code, money_list)
    price = transaction_datas[-1][1]
    huaxin_timestamp = transaction_datas[-1][3]
trade/current_price_process_manager.py
@@ -110,7 +110,27 @@
                special_codes = BlockSpecialCodesManager().get_block_codes(b)
                if special_codes and code in special_codes:
                    return index + 1
    else:
        # 尚未涨停过的代码,订阅板块有辨识度的前6
        for b in blocks:
            # 如果当前板块不能买则不订阅
            if KPLPlateForbiddenManager().is_in_cache(b):
                continue
            if b not in top_in_blocks:
                continue
            index = top_in_blocks.index(b)
            special_codes = BlockSpecialCodesManager().get_block_codes(b)
            if not special_codes or code not in special_codes:
                continue
            # 查询在板块中的排序
            info = RadicalBuyBlockManager().get_history_index(code, b, yesterday_limit_up_codes)
            if info[0] > 0:
                info = RadicalBuyBlockManager().filter_before_codes(code, b, info[0], info[1],
                                                                    yesterday_limit_up_codes)
            if info[0] >= 6:
                continue
            # 净流入 + 辨识度 + 整体身位老6之前
            return index + 1
    return 10000
utils/trade_util.py
@@ -9,4 +9,4 @@
    """
    if state == trade_constant.TRADE_STATE_BUY_DELEGATED or state == trade_constant.TRADE_STATE_BUY_PLACE_ORDER or state == trade_constant.TRADE_STATE_BUY_SUCCESS:
        return False
    return True
    return True