admin
2025-05-06 8242a0c7a7fe85feaa4e652ddb3a1385173a5288
bug修复
5个文件已修改
69 ■■■■ 已修改文件
data_server.py 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.py 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/buying_strategy.py 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/data_cache.py 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
strategy/market_sentiment_analysis.py 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
data_server.py
@@ -14,7 +14,7 @@
import constant
from db import redis_manager_delegate as redis_manager, mysql_data_delegate as mysql_data
from db.redis_manager_delegate import RedisUtils
from log_module import log_export
from log_module import log_export, async_log_util
from log_module.log import hx_logger_l2_transaction, logger_debug, logger_request_api
from strategy import data_cache
from strategy.kpl_data_manager import KPLStockOfMarketsPlateLogManager
@@ -308,6 +308,12 @@
                            raise Exception("没有获取到L1数据")
                        pre_price = data[1]
                        current_price = data[2] if data[2] else data[5][0][0]
                        # 获取最新成交价格
                        latest_deal_price = data_cache.latest_deal_price_dict.get(code)
                        if latest_deal_price:
                            current_price = round(float(latest_deal_price), 2)
                            async_log_util.info(logger_debug, f"根据成交价卖出:{code}-{latest_deal_price}")
                        price = tool.get_buy_min_price(current_price)
                        price = max(price, tool.get_limit_down_price(code, pre_price))
                    else:
main.py
@@ -187,6 +187,7 @@
                logger_debug.exception(e)
            finally:
                self.__last_price_dict[code] = price
                data_cache.latest_deal_price_dict[code] = price
    def OnMarketData(self, code, datas):
        # logger_debug.info(f"收到L2Market数据:{datas}")
strategy/buying_strategy.py
@@ -357,7 +357,9 @@
                                        elif data_cache.have_plate_buy_times >= 3:
                                            logger_info(f"【不利】有概念买入已经 3 次了!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                        elif len(data_cache.addition_position_symbols_set) >= 3:
                                            L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                            logger_info(f"【不利】当日已经买了3只票!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                            L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                        elif now_time < data_cache.OPENING_TIME or now_time > data_cache.NOON_MARKET_TIME:
                                            logger_info(f"【不利】不在9:30-13:05时间内!不买!!")
                                        else:
@@ -448,8 +450,10 @@
                                                    f"【不利】同概念只买一次,不买了,公司名称:{k_line_data[0]['sec_name']},重复相交概念==={intersection_plate}")
                                            elif data_cache.have_plate_buy_times >= 1:
                                                logger_info(f"【不利】有概念无强度买入已经1次了!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                                L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                            elif len(data_cache.addition_position_symbols_set) >= 4:
                                                logger_info(f"【不利】当日已经买了3只票!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                                L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                            elif now_time < data_cache.OPENING_TIME or now_time > data_cache.NOON_MARKET_TIME:
                                                logger_info(f"【不利】不在9:30-13:05时间内!不买!!")
                                            else:
@@ -542,8 +546,10 @@
                                                        f"【不利】自由市值小于6亿!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                                elif data_cache.have_strength_buy_times >= 1:
                                                    logger_info(f"【不利】有强度买入 1 次了!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                                    L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                elif len(data_cache.addition_position_symbols_set) >= 3:
                                                    logger_info(f"【不利】当日已经买了3只票!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                                    L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                elif now_time < data_cache.OPENING_TIME or now_time > data_cache.NOON_MARKET_TIME:
                                                    logger_info(f"【不利】不在9:30-13:05时间内!不买!!")
                                                else:
@@ -648,9 +654,11 @@
                                                        f"【不利】自由市值小于6亿!不买!! 公司名称:{k_line_data[0]['sec_name']},最新价: {current_price}")
                                                elif data_cache.have_small_turn_large_buy_times >= 1:
                                                    logger_info(f"【不利】有小量换大涨幅买入已经 1 次了!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                                    L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                elif len(data_cache.addition_position_symbols_set) >= 4:
                                                    logger_info(
                                                        f"【不利】当日已经买了4只票!不买了!!公司名称:{k_line_data[0]['sec_name']},")
                                                    L2_data_analysis.find_L2_big_order_of_code(symbol_code)
                                                elif (
                                                        data_cache.MORN_MARKET_TIME < now_time < data_cache.NOON_MARKET_TIME) is False or free_market_value < 100 or (
                                                        today_open_growth < 5 or today_growth < 5):
@@ -665,9 +673,9 @@
                                                        f"目前获取的精选板块股票强度数据  ==  {data_cache.market_sift_plate_stock_dict}")
                                                    # buying_ratio = basic_methods.maximum_buying_ratio(len(data_cache.addition_position_symbols_set))
                                                    # 调用下单方法下单
                                                    order_methods.buy_order_by_value(symbol, 1000,
                                                                                     k_line_data[0]['sec_name'],
                                                                                     current_price)
                                                    # order_methods.buy_order_by_value(symbol, 1000,
                                                    #                                  k_line_data[0]['sec_name'],
                                                    #                                  current_price)
                                                    # # 将有小量换大涨幅买入次数自加1
                                                    # data_cache.have_small_turn_large_buy_times += 1
                                                    # # 将买入个股的当时概念添加到全局变量中存储
strategy/data_cache.py
@@ -270,6 +270,9 @@
# 最新的L1数据: {代码: L1数据}
current_l1_dict = {}
# 最新成交价格
latest_deal_price_dict = {}
logging.info(f"全局初始化数据  完成《《《 - {os.getpid()}")
strategy/market_sentiment_analysis.py
@@ -411,7 +411,11 @@
# 计算市场分布形态因子 函数
# ====================== 输入数据 ======================
data = {'-1': '2676', '-10': '4', '-2': '769', '-3': '181', '-4': '59', '-5': '43', '-6': '18', '-7': '11', '-8': '5', '-9': '4', '0': '219', '1': '714', '10': '6', '2': '214', '3': '69', '4': '45', '5': '23', '6': '9', '7': '9', '8': '7', '9': '6', 'DT': 17, 'SJDT': '8', 'SJZT': '17', 'STDT': '9', 'STZT': '4', 'SZJS': 1123, 'XDJS': 3787, 'ZSZDFB': '480,1639,112,123,351,26,76,202,15,17,32,1,15,30,5,78,204,18,', 'ZT': 21, 'sign': '市场人气一般', 'szln': 2591290, 'qscln': 6629612, 's_zrcs': 2604433, 'q_zrcs': 6660830, 's_zrtj': 38031347, 'q_zrtj': 91465597}
data = {'-1': '2676', '-10': '4', '-2': '769', '-3': '181', '-4': '59', '-5': '43', '-6': '18', '-7': '11', '-8': '5',
        '-9': '4', '0': '219', '1': '714', '10': '6', '2': '214', '3': '69', '4': '45', '5': '23', '6': '9', '7': '9',
        '8': '7', '9': '6', 'DT': 17, 'SJDT': '8', 'SJZT': '17', 'STDT': '9', 'STZT': '4', 'SZJS': 1123, 'XDJS': 3787,
        'ZSZDFB': '480,1639,112,123,351,26,76,202,15,17,32,1,15,30,5,78,204,18,', 'ZT': 21, 'sign': '市场人气一般',
        'szln': 2591290, 'qscln': 6629612, 's_zrcs': 2604433, 'q_zrcs': 6660830, 's_zrtj': 38031347, 'q_zrtj': 91465597}
# ====================== 总手涨跌分布数据预处理 ======================
@@ -437,7 +441,9 @@
    # 2. 定义区间划分(假设从-9%到+9%,1%间隔)
    bins = [
           "[+9%, +8%)", "[+8%, +7%)", "[+7%, +6%)", "[+6%, +5%)", "[+5%, +4%)", "[+4%, +3%)", "[+3%, +2%)", "[+2%, +1%)", "[+1%, 0%)", "[0%, -1%)", "[-1%, -2%)", "[-2%, -3%)", "[-3%, -4%)", "[-4%, -5%)", "[-5%, -6%)", "[-6%, -7%)", "[-7%, -8%)", "[ -8%, -9%)"
        "[+9%, +8%)", "[+8%, +7%)", "[+7%, +6%)", "[+6%, +5%)", "[+5%, +4%)", "[+4%, +3%)", "[+3%, +2%)", "[+2%, +1%)",
        "[+1%, 0%)", "[0%, -1%)", "[-1%, -2%)", "[-2%, -3%)", "[-3%, -4%)", "[-4%, -5%)", "[-5%, -6%)", "[-6%, -7%)",
        "[-7%, -8%)", "[ -8%, -9%)"
        ]
    # 3. 验证数据长度
@@ -455,6 +461,7 @@
    }
    return result
# ====================== 核心因子计算 ======================
def calculate_factors(data):
@@ -637,15 +644,20 @@
        signals.append("高情绪热度:涨停股多且人气向好")
    # 信号5:涨跌分布综合
    if factors['top_three']['top1']['value']+factors['top_three']['top2']['value']+factors['top_three']['top3']['value'] > 50:
        value = factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + factors['top_three']['top3']['value']
    if factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + factors['top_three']['top3'][
        'value'] > 50:
        value = factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + \
                factors['top_three']['top3']['value']
        signals.append(f"涨跌分布:长尾分布{value}")
        if factors['top_three']['top1']['value']/factors['top_three']['top2']['value'] > 1.25:
            signals.append(f"涨跌分布:强势聚集{factors['top_three']['top1']['key']}:{factors['top_three']['top1']['value']}%")
            signals.append(
                f"涨跌分布:强势聚集{factors['top_three']['top1']['key']}:{factors['top_three']['top1']['value']}%")
        else:
            signals.append(f"涨跌分布:中度聚集{factors['top_three']['top1']['key']}:{factors['top_three']['top1']['value']}%")
            signals.append(
                f"涨跌分布:中度聚集{factors['top_three']['top1']['key']}:{factors['top_three']['top1']['value']}%")
    else:
        value = factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + factors['top_three']['top3']['value']
        value = factors['top_three']['top1']['value'] + factors['top_three']['top2']['value'] + \
                factors['top_three']['top3']['value']
        signals.append(f"涨跌分布:均匀分布{value}")
    return signals if signals else ["无显著信号:维持当前策略"]
@@ -752,7 +764,9 @@
                    # data_cache.today_planned_order_amount = ((data_cache.real_time_market_strong + data_cache.index_trend_expectation_score) * 0.01) * (
                    #                                                 usefulMoney * 0.9 * low_emotion_mood_ratio / Unfinished_opening_plan_number)
                    # 除以3应该是一个常量,如果以Unfinished_opening_plan_number,会出现float division by zero 错误
                    if not data_cache.today_planned_order_amount or data_cache.today_planned_order_amount <= 0:
                    data_cache.today_planned_order_amount = usefulMoney * 0.95 * ideal_trading_market_score / 3
                        logger.info(f"第一次计划下单金额==={data_cache.today_planned_order_amount}元")
                    # 开仓计划运行时间段
                    if data_cache.OPENING_TIME < now_time < data_cache.NOON_MARKET_TIME:
                        # # 如果一日三仓的计划还未完成 且 首次开仓金额为0
@@ -768,7 +782,8 @@
                            #         logger.info(f"采用开仓策略计算方式=》今日计划下单金额:{data_cache.today_planned_order_amount}")
                            if addition_position_number > 0:
                                # 下过一次单过后再计算动态下单金额
                                data_cache.today_first_planned_order_amount = float(data_cache.today_planned_order_amount)
                                data_cache.today_first_planned_order_amount = float(
                                    data_cache.today_planned_order_amount)
                                logger.info(
                                    f"采用开仓策略计算方式--》今日(首个)新增持仓产生,将实时计算金额赋值给首笔持仓金额=》今日计划下单金额:{data_cache.today_planned_order_amount}")
@@ -806,10 +821,14 @@
    print(f"资金净流入(元): {round(factors['capital_flow']['net']/10000, 2)}万")
    print(f"涨停股占比: {factors['sentiment']['zt_ratio']:.2%}")
    print(f"聚集前三名情况字典=={factors['top_three']}")
    print(f"上涨幅段最大:{factors['rise_vs_fall']['rise_max_key']}:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['rise_max_key'])}%")
    print(f"下跌幅段最大:{factors['rise_vs_fall']['fall_max_key']}:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['fall_max_key'])}%")
    print(f"聚集区域:{factors['rise_vs_fall']['gather_area']},聚集区域的比例值:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['gather_area'])}%")
    print(f"零散区域:{factors['rise_vs_fall']['scattered_area']},聚集区域的比例值:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['scattered_area'])}%")
    print(
        f"上涨幅段最大:{factors['rise_vs_fall']['rise_max_key']}:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['rise_max_key'])}%")
    print(
        f"下跌幅段最大:{factors['rise_vs_fall']['fall_max_key']}:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['fall_max_key'])}%")
    print(
        f"聚集区域:{factors['rise_vs_fall']['gather_area']},聚集区域的比例值:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['gather_area'])}%")
    print(
        f"零散区域:{factors['rise_vs_fall']['scattered_area']},聚集区域的比例值:{factors['rise_vs_fall']['percentages'].get(factors['rise_vs_fall']['scattered_area'])}%")
    print(f"市场情绪量化: {'积极' if factors['sentiment']['sign'] else '谨慎'}")
    print(f"涨跌因子字典={factors['rise_vs_fall']}")