Administrator
2025-01-02 d957e0dc6dcfb15304a6499e1b9ddee4e18be531
拆单初步规划/禁止交易板块管理
9个文件已修改
212 ■■■■■ 已修改文件
l2/huaxin/huaxin_delegate_postion_manager.py 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2_test.py 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/data_server.py 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
servers/huaxin_trade_server.py 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/code_plate_key_manager.py 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
third_data/custom_block_in_money_manager.py 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_money_count_setting.py 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/buy_radical/radical_buy_data_manager.py 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
trade/current_price_process_manager.py 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
l2/huaxin/huaxin_delegate_postion_manager.py
@@ -14,6 +14,7 @@
import concurrent.futures
_place_order_info_dict = {}
_place_order_info_dict_new = {}
__place_order_position = {}
@@ -27,6 +28,20 @@
        price, volume, latest_data, time.time(), order_ref, shadow_price, exec_index, shadow_volume)
def place_order_new(code, oredr_info_list, exec_index, latest_data):
    """
    设置的下单信息
    @param code:
    @param oredr_info_list: 例如-[(量,价格, order_ref)], 先下单的在前
    @param exec_index:
    @param latest_data:
    @return:
    """
    async_log_util.info(logger_real_place_order_position,
                        f"新版下单:code-{code} oredr_info_list-{oredr_info_list}  exec-index-{exec_index}")
    _place_order_info_dict_new[code] = (oredr_info_list, latest_data, time.time(), exec_index)
# 获取下单信息
def get_order_info(code):
    info = _place_order_info_dict.get(code)
l2_test.py
@@ -48,6 +48,13 @@
                response_data = json.dumps({"code": 0, "data": fdatas})
            except Exception as e:
                response_data = json.dumps({"code": 1, "msg": str(e)})
        elif url.path == "/get_code_money_info":
            # 获取代码金额
            ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()])
            code = ps_dict.get('code')
            money_info = CodeInMoneyManager().get_money_info(code)
            response_data = json.dumps({"code": 0, "data": money_info})
        self.send_response(200)
        # 发给请求客户端的响应数据
        self.send_header('Content-type', 'application/json')
servers/data_server.py
@@ -52,7 +52,6 @@
    __IgnoreCodeManager = IgnoreCodeManager()
    __KPLPlatManager = KPLPlatManager()
    __KPLCodeLimitUpReasonManager = KPLCodeLimitUpReasonManager()
    __KPLPlateForbiddenManager = KPLPlateForbiddenManager()
    # 历史板块
    __history_plates_dict = {}
    # 板块
@@ -436,7 +435,7 @@
                # 精选,主力净额顺序
                result = kpl_api.getMarketJingXuanRealRankingInfo(False)
                result = kpl_util.parseMarketJingXuan(result)
            forbidden_plates = self.__KPLPlateForbiddenManager.list_all()
            forbidden_plates = KPLPlateForbiddenManager().list_all()
            fresult = []
            for d in result:
                if type_ == 2 or type_ == 3:
@@ -454,11 +453,24 @@
            self.__IgnoreCodeManager.ignore_code(type_, code)
            response_data = json.dumps({"code": 0})
        elif url.path == "/kpl/forbidden_plate":
            # 添加不能买的板块
            ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()])
            plate = ps_dict["plate"]
            # 加入禁止
            self.__KPLPlateForbiddenManager.save_plate(plate)
            KPLPlateForbiddenManager().save_plate(plate)
            response_data = json.dumps({"code": 0})
        elif url.path == "/kpl/del_forbidden_plate":
            # 删除不能买的板块
            ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()])
            plate = ps_dict["plate"]
            # 加入禁止
            KPLPlateForbiddenManager().delete_plate(plate)
            response_data = json.dumps({"code": 0})
        elif url.path == "/kpl/list_forbidden_plate":
            # 不能买的板块列表
            results = KPLPlateForbiddenManager().list_all_cache()
            response_data = json.dumps({"code": 0, "data": list(results)})
        elif url.path == "/kpl/get_plate_codes":
            # 获取涨停原因下面的代码
            ps_dict = dict([(k, v[0]) for k, v in parse_qs(url.query).items()])
@@ -902,18 +914,24 @@
                    codes = huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.get_subscript_codes()
                if codes:
                    for code in codes:
                        deal_big_order_detail_info = None
                        try:
                            # 获取成交大单:(参考大单金额,已成交大单金额,大单要求金额)
                            th = BeforeSubDealBigOrderManager().get_big_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))
                            # 大单成交信息
                            deal_big_order_info = (
                                output_util.money_desc(th), output_util.money_desc(deal_big_money_info[1]),
                                output_util.money_desc(deal_big_money_info[2]))
                            if len(codes) ==1:
                                # 加载大单详情
                                deal_big_order_detail_info = radical_buy_data_manager.get_l2_big_order_deal_info(code)
                        except:
                            deal_big_order_info = None
                        code_name = gpcode_manager.get_code_name(code)
                        fresults.append((code, code_name, deal_big_order_info))
                        fresults.append((code, code_name, deal_big_order_info, deal_big_order_detail_info))
                response_data = json.dumps({"code": 0, "data": fresults})
            except  Exception as e:
                response_data = json.dumps({"code": 1, "data": str(1)})
servers/huaxin_trade_server.py
@@ -39,8 +39,10 @@
    hx_logger_l2_orderdetail, hx_logger_l2_market_data, logger_l2_g_cancel, logger_debug, \
    logger_system, logger_trade, logger_l2_radical_buy
from third_data import block_info, kpl_data_manager, history_k_data_manager, huaxin_l1_data_manager, kpl_api, kpl_util
from third_data.code_plate_key_manager import KPLCodeJXBlockManager, CodePlateKeyBuyManager, RealTimeKplMarketData
from third_data.code_plate_key_manager import KPLCodeJXBlockManager, CodePlateKeyBuyManager, RealTimeKplMarketData, \
    KPLPlateForbiddenManager
from third_data.history_k_data_util import JueJinApi, HistoryKDatasUtils
from third_data.kpl_limit_up_data_manager import LatestLimitUpBlockManager
from trade import l2_trade_util, \
    trade_data_manager, trade_constant, buy_open_limit_up_strategy
from trade.buy_radical import radical_buy_data_manager, radical_buy_strategy
@@ -1031,6 +1033,17 @@
    L2TradeSingleDataManager.set_callback(l2_trade_single_callback)
    # 加载自由流通量
    global_data_loader.load_zyltgb_volume_from_db()
    # 获取最近7天涨停数最多的板块
    try:
        if not KPLPlateForbiddenManager().list_all_cache():
            # 没有添加过的时候需要重新添加
            datas_ = LatestLimitUpBlockManager().statistics_limit_up_block_infos()
            if datas_:
                plates = [d[0] for d in datas_[:3]]
                for p in plates:
                    KPLPlateForbiddenManager().save_plate(p)
    except:
        pass
def run(queue_strategy_r_trade_w, queue_strategy_w_trade_r, queue_strategy_w_trade_r_for_read, trade_ipc_addr):
third_data/code_plate_key_manager.py
@@ -222,7 +222,10 @@
# 开盘啦禁止交易板块管理
class KPLPlateForbiddenManager:
    __redisManager = redis_manager.RedisManager(3)
    """
    不能买的板块管理
    """
    __redis_manager = redis_manager.RedisManager(3)
    __kpl_forbidden_plates_cache = set()
    __instance = None
@@ -237,17 +240,22 @@
    def __load_datas(cls):
        __redis = cls.__get_redis()
        try:
            __kpl_forbidden_plates_cache = RedisUtils.smembers(__redis, "kpl_forbidden_plates")
            cls.__kpl_forbidden_plates_cache = RedisUtils.smembers(__redis, "kpl_forbidden_plates")
        finally:
            RedisUtils.realse(__redis)
    @classmethod
    def __get_redis(cls):
        return cls.__redisManager.getRedis()
        return cls.__redis_manager.getRedis()
    def save_plate(self, plate):
        self.__kpl_forbidden_plates_cache.add(plate)
        RedisUtils.sadd(self.__get_redis(), "kpl_forbidden_plates", plate)
        RedisUtils.expire(self.__get_redis(), "kpl_forbidden_plates", tool.get_expire())
    def delete_plate(self, plate):
        self.__kpl_forbidden_plates_cache.discard(plate)
        RedisUtils.srem(self.__get_redis(), "kpl_forbidden_plates", plate)
        RedisUtils.expire(self.__get_redis(), "kpl_forbidden_plates", tool.get_expire())
    def list_all(self):
@@ -255,6 +263,11 @@
    def list_all_cache(self):
        return self.__kpl_forbidden_plates_cache
    def is_in_cache(self, plate):
        if self.__kpl_forbidden_plates_cache and plate in self.__kpl_forbidden_plates_cache:
            return True
        return False
class LimitUpCodesPlateKeyManager:
@@ -416,7 +429,7 @@
                    strong = cls.get_market_strong()
                    if strong is None:
                        strong = 60
                    THRESHOLD_MONEY = int((1 - strong/200) * data[3])
                    THRESHOLD_MONEY = int((1 - strong / 200) * data[3])
            # if count >= MAX_COUNT:
            #     break
        # 记录精选流出日志
third_data/custom_block_in_money_manager.py
@@ -18,6 +18,11 @@
    def __init__(self):
        # 总的净流入
        self.__code_money_dict = {}
        # 总买单信息:{"code":[金额, 数量]}
        self.__code_buy_money_dict = {}
        # 总卖单信息:{"code":[金额, 数量]}
        self.__code_sell_money_dict = {}
        # 净流入大单金额
        self.__code_big_buy_mmoney_list_dict = {}
        self.__latest_price = {}
@@ -37,6 +42,13 @@
        code = item[0]
        if code not in self.__code_money_dict:
            self.__code_money_dict[code] = 0
        if code not in self.__code_buy_money_dict:
            self.__code_buy_money_dict[code] = [0, 0]
        if code not in self.__code_sell_money_dict:
            self.__code_sell_money_dict[code] = [0, 0]
        if not tool.is_ge_code(code) and item[2][2] < 299e4:
            return
        if tool.is_ge_code(code) and item[2][2] < 299e4 and item[2][1] < 290000:
@@ -44,6 +56,9 @@
        if item[1] == 0:
            # item[2]的数据结构:  (买单号, 量, 金额, 时间, 最新成交价格)
            self.__code_money_dict[code] += item[2][2]
            self.__code_buy_money_dict[code][0] += item[2][2]
            self.__code_buy_money_dict[code][1] += 1
            if code not in self.__code_big_buy_mmoney_list_dict:
                self.__code_big_buy_mmoney_list_dict[code] = []
            # 大买单信息:(金额,最后价格)
@@ -51,6 +66,8 @@
                self.__code_big_buy_mmoney_list_dict[code].append((item[2][2], item[2][4], item[2][0]))
        else:
            self.__code_money_dict[code] -= item[2][2]
            self.__code_sell_money_dict[code][0] += item[2][2]
            self.__code_sell_money_dict[code][1] += 1
        self.__latest_price[code] = item[2][4]
    def get_code_money_dict(self):
@@ -61,6 +78,15 @@
            return self.__code_money_dict.get(code)
        return 0
    def get_money_info(self, code):
        """
        获取代码流入信息
        @param code: 代码信息
        @return: 净流入金额,[大单买金额, 大单买数量],[大单卖金额,大单卖数量]
        """
        return self.__code_money_dict.get(code), self.__code_buy_money_dict.get(code), self.__code_sell_money_dict.get(
            code)
    def set_money(self, code, money):
        self.__code_money_dict[code] = money
trade/buy_money_count_setting.py
@@ -202,6 +202,54 @@
            return True, end_info[
                1], f"时间段:{start_time}-{end_info[0]} 已成交/委托数量({codes})没有超过{end_info[2]}个,委托金额为:{end_info[1]}"
    @classmethod
    def __get_possible_buy_moneys(cls):
        """
        获取可能的买入金额
        @return:
        """
        moneys = set()
        radical_buy_setting = BuyMoneyAndCountSetting().get_radical_buy_setting()
        if radical_buy_setting:
            moneys |= set([x[1] for x in radical_buy_setting[1]])
        normal_buy_setting = BuyMoneyAndCountSetting().get_normal_buy_setting()
        if normal_buy_setting:
            moneys |= set([x[1] for x in normal_buy_setting[1]])
        moneys.add(constant.BUY_MONEY_PER_CODE)
        print(moneys)
        return moneys
    @classmethod
    def get_possible_buy_volumes(cls, limit_up_price):
        """
        获取所有可能下单的量
        @param limit_up_price: 涨停价
        @return:
        """
        moneys = cls.__get_possible_buy_moneys()
        total_volumes = set()
        for money in moneys:
            volumes = cls.get_possible_buy_volumes_by_money(limit_up_price, money)
            if volumes:
                total_volumes |= set(list(volumes))
        return total_volumes
    @classmethod
    def get_possible_buy_volumes_by_money(cls, limit_up_price, money):
        """
        获取所有可能下单的量
        @param money: 金额
        @param limit_up_price: 涨停价
        @return:
        """
        total_volume_unit_100 = tool.get_buy_volume_by_money(limit_up_price, money)//100
        if total_volume_unit_100 % 2 == 0:
            return 100 * (total_volume_unit_100 // 2 - 1), 100 * (total_volume_unit_100 // 2 + 1)
        else:
            return 100 * (total_volume_unit_100 // 2), 100 * (total_volume_unit_100 // 2 + 1)
if __name__ == '__main__':
    print(RadicalBuyBlockCodeCountManager().get_block_code_count("测试"))
    print(BuyMoneyUtil.get_possible_buy_volumes(14.38))
    # print(json.dumps(list(BuyMoneyUtil.get_possible_buy_moneys())))
trade/buy_radical/radical_buy_data_manager.py
@@ -19,7 +19,7 @@
from log_module import async_log_util
from log_module.log import logger_l2_radical_buy, logger_debug, logger_l2_radical_buy_data
from third_data import kpl_block_util, huaxin_l1_data_manager, kpl_data_constant
from third_data.code_plate_key_manager import RealTimeKplMarketData
from third_data.code_plate_key_manager import RealTimeKplMarketData, KPLPlateForbiddenManager
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
@@ -1155,6 +1155,18 @@
        #                                                                            excude_codes)
        #         if history_index >= 4:
        #             return set(), f"在【{b}】中身位({history_index + 1})靠后"
        # 判断板块是否不能买
        if can_buy_blocks:
            msges.clear()
            for b in can_buy_blocks:
                if KPLPlateForbiddenManager().is_in_cache(b):
                    msges.append(b)
            if msges:
                fmsges.append("禁止买入的板块##" + ",".join(msges))
                # 排除禁止买入的板块
                can_buy_blocks -= set(msges)
        return can_buy_blocks, " **** ".join(fmsges)
@@ -1359,7 +1371,6 @@
                cls.__deal_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_deal_order_count(cls, code):
        if code in cls.__deal_big_order_infos_dict:
@@ -1503,5 +1514,21 @@
                                                                   gpcode_manager.get_limit_up_price_as_num(code_))
def get_l2_big_order_deal_info(code_):
    """
    获取成交大单信息
    @param code_:
    @return:(净流入金额, (大单买金额, 大单买数量), (大单卖金额, 大单卖数量))
    """
    response_data = requests.get(
        "http://127.0.0.1:9005/get_code_money_info?code=" + code_)
    r_str = response_data.text
    response_data = json.loads(r_str)
    if response_data["code"] == 0:
        datas = response_data["data"]
        return datas
    return None
if __name__ == '__main__':
    pass
trade/current_price_process_manager.py
@@ -10,7 +10,9 @@
from log_module.log import logger_l2_codes_subscript, logger_debug
import constant
from code_attribute import gpcode_manager
from third_data.code_plate_key_manager import KPLPlateForbiddenManager
from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager, LimitUpDataConstant
from trade.buy_money_count_setting import BuyMoneyUtil
from trade.buy_radical import radical_buy_data_manager
from trade.buy_radical.block_special_codes_manager import BlockSpecialCodesManager
from trade.buy_radical.radical_buy_data_manager import RadicalBuyBlockManager, RadicalBuyDataManager
@@ -83,10 +85,16 @@
        # 涨停过的代码才会计算板块身位
        for b in blocks:
            index = None
            # 如果当前板块不能买则不订阅
            if KPLPlateForbiddenManager().is_in_cache(b):
                continue
            if b in top_in_blocks:
                index = top_in_blocks.index(b)
            else:
                if RadicalBuyBlockManager.is_block_can_buy_with_block_in(code, b, yesterday_limit_up_codes=yesterday_limit_up_codes)[0]:
                if RadicalBuyBlockManager.is_block_can_buy_with_block_in(code, b,
                                                                         yesterday_limit_up_codes=yesterday_limit_up_codes)[
                    0]:
                    index = 100
            if index is None:
                continue
@@ -215,15 +223,16 @@
                    latest_add_codes = add_code_set
                    add_datas = []
                    for d in add_code_list:
                        limit_up_price = gpcode_manager.get_limit_up_price(d)
                        limit_up_price = round(float(limit_up_price), 2)
                        limit_up_price = gpcode_manager.get_limit_up_price_as_num(d)
                        min_volume = int(round(50 * 10000 / limit_up_price))
                        # 传递笼子价
                        # 需要订阅的特殊的量
                        special_volumes = BuyMoneyUtil.get_possible_buy_volumes(limit_up_price)
                        special_volumes |= set([tool.get_buy_volume_by_money(limit_up_price, x) for x in
                                                constant.AVAILABLE_BUY_MONEYS])
                        add_datas.append(
                            # (代码, 最小量, 涨停价,影子订单价格,买量, 特殊价格)
                            (d, min_volume, limit_up_price, round(tool.get_shadow_price(limit_up_price), 2),
                             tool.get_buy_volume(limit_up_price),
                             [tool.get_buy_volume_by_money(limit_up_price, x) for x in constant.AVAILABLE_BUY_MONEYS]))
                             tool.get_buy_volume(limit_up_price), list(special_volumes)))
                    huaxin_target_codes_manager.HuaXinL2SubscriptCodesManager.push(add_datas, request_id)
            except Exception as e:
                logging.exception(e)