Administrator
2025-05-27 223f6e21672cdea10ba138638a3636861fd933f6
servers/data_server.py
@@ -12,7 +12,8 @@
from code_attribute.gpcode_manager import BlackListCodeManager, HumanRemoveForbiddenManager
from l2.huaxin import huaxin_target_codes_manager
from l2.l2_transaction_data_manager import HuaXinBuyOrderManager
from log_module.log import logger_system, logger_debug, logger_kpl_limit_up, logger_request_api
from log_module.log import logger_system, logger_debug, logger_kpl_limit_up, logger_request_api, \
    logger_kpl_market_strong, logger_kpl_new_blocks
from third_data.custom_block_in_money_manager import CodeInMoneyManager
from third_data.kpl_data_constant import LimitUpCodesBlockRecordManager, LimitUpDataConstant, \
    ContainsLimitupCodesBlocksManager
@@ -808,8 +809,9 @@
                deals_month = trade_data_manager.AccountMoneyManager().get_deal_count_info(start_date, end_date)
                cost_month = sum([round(0.1 * x[1], 2) for x in delegates_month])
                make_month = 0
                make_month += max(1 * deals_month[0][1] if deals_month[0][1] else 0, deals_month[0][2] * 1.854 / 10000 if deals_month[0][2] else 0) + 1 * deals_month[1][
                    1] + 0 * deals_month[2][1]
                make_month += max(1 * deals_month[0][1] if deals_month[0][1] else 0,
                                  deals_month[0][2] * 1.854 / 10000 if deals_month[0][2] else 0) + 1 * deals_month[1][
                                  1] + 0 * deals_month[2][1]
                fdata["month_commission"] = round(make_month - cost_month, 2)
                # 计算当日手续费详情
                delegates = trade_data_manager.AccountMoneyManager().get_delegated_count_info()
@@ -975,7 +977,7 @@
                        except Exception as e:
                            logger_debug.error(f"可能没有获取到涨停价:{code}")
                            # logger_debug.exception(e)
                            logger_debug.exception(e)
                            deal_big_order_info = None
                        code_name = gpcode_manager.get_code_name(code)
                        fresults.append((code, code_name, deal_big_order_info, deal_big_order_detail_info))
@@ -986,6 +988,13 @@
        elif url.path == "/get_all_special_codes":
            # 获取所有辨识度的代码
            code_blocks_dict = BlockSpecialCodesManager().get_code_blocks_dict()
            fdata = {}
            for k in code_blocks_dict:
                fdata[k] = list(code_blocks_dict[k])
            response_data = json.dumps({"code": 0, "data": fdata})
        elif url.path == "/get_new_blocks_special_codes":
            # 获取所有辨识度的代码
            code_blocks_dict = BlockSpecialCodesManager().get_temp_code_blocks_dict()
            fdata = {}
            for k in code_blocks_dict:
                fdata[k] = list(code_blocks_dict[k])
@@ -1023,14 +1032,18 @@
        def do_limit_up(result_list_):
            def request_new_blocks_codes(blocks_info):
            def request_new_blocks_codes(blocks_info, all_new_blocks):
                """
                请求新板块的代码
                @param blocks_info:[(板块名称,板块代码)]
                @return:
                """
                yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes()
                blocks = set()
                for bi in blocks_info:
                    if bi[0] in blocks:
                        continue
                    blocks.add(bi[0])
                    result = kpl_api.getCodesByPlate(bi[1])
                    result = json.loads(result)
                    code_info_list = []
@@ -1039,15 +1052,18 @@
                            continue
                        # 涨幅要大于5%
                        rate = d[6] / int(round((tool.get_limit_up_rate(d[0]) - 1) * 10))
                        if rate < 5:
                        if rate / ((tool.get_limit_up_rate(d[0]) - 1) * 10) < 5:
                            continue
                        # 格式:(代码,涨幅)
                        code_info_list.append((d[0], d[6]))
                    # 保存新题材
                    datas = [(d[0], d[6]) for d in result["list"]]
                    async_log_util.info(logger_kpl_new_blocks, f"{(tool.get_thread_id() ,bi, datas)}")
                    if code_info_list:
                        # 将代码加入新题材
                        for x in code_info_list:
                            new_block_processor.process_new_block(x[0], bi[0])
                        new_block_processor.process_new_block_by_component_codes(bi[0],
                                                                                 set([x[0] for x in code_info_list]),
                                                                                 all_new_blocks)
            try:
                if result_list_:
@@ -1122,41 +1138,31 @@
                        pass
                    try:
                        records = KPLLimitUpDataRecordManager.total_datas
                        # 计算今日新增的题材概念
                        block_codes = {}
                        # 统计板块的代码
                        block_plate_code_dict = {}
                        for x in records:
                            bs = {kpl_util.filter_block(x[2])}
                            block_plate_code_dict[kpl_util.filter_block(x[2])] = x[15]
                            # if x[6]:
                            #     bs |= set(x[6].split("、"))
                            for b in bs:
                                if b not in block_codes:
                                    block_codes[b] = set()
                                block_codes[b].add(x[3])
                        # 所有代码的涨停原因
                        reasons = set(block_codes.keys())
                        reasons -= constant.KPL_INVALID_BLOCKS
                        # 原来的老题材
                        reasons -= BeforeBlocksComputer().get_old_blocks()
                        if reasons:
                        # 新题材
                        new_block_processor.process_limit_up_list({x[0]: x[5] for x in result_list_})
                        new_block_codes = new_block_processor.screen_new_blocks_with_limit_up_datas(
                            [(x[0], x[5]) for x in result_list_])
                        if new_block_codes:
                            # 统计板块的代码
                            records = KPLLimitUpDataRecordManager.total_datas
                            block_plate_code_dict = {}
                            for x in records:
                                block_plate_code_dict[kpl_util.filter_block(x[2])] = x[15]
                            # 新板块
                            update_new_block_plates = []
                            for r in reasons:
                                for c in block_codes[r]:
                                    new_block_processor.process_new_block(c, r)
                            for b in new_block_codes:
                                for c in new_block_codes[b]:
                                    new_block_processor.process_new_block_by_limit_up_list(c, b)
                            for r in reasons:
                            for r in new_block_codes:
                                if r in block_plate_code_dict:
                                    update_new_block_plates.append((r, block_plate_code_dict[r]))
                            if update_new_block_plates:
                                # 需要获取板块下的代码
                                self.__new_blocks_codes_request_thread_pool.submit(
                                    lambda: request_new_blocks_codes(update_new_block_plates))
                    except:
                        pass
                                    lambda: request_new_blocks_codes(update_new_block_plates, new_block_codes.keys()))
                    except Exception as e:
                        logger_debug.exception(e)
                    self.__kplDataManager.save_data(type_, result_list_)
            except Exception as e:
                logger_debug.exception(e)
@@ -1236,11 +1242,10 @@
                RealTimeKplMarketData.set_market_jingxuan_out_blocks(result_list)
        elif type_ == KPLDataType.MARKET_STRONG.value:
            strong = data["data"]
            logger_debug.debug("开盘啦市场强度:{}", strong)
            logger_kpl_market_strong.info(strong)
            # 保存市场热度
            if strong is not None:
                RealTimeKplMarketData.set_market_strong(strong)
        return json.dumps({"code": 0})
    def __send_response(self, data):