admin
2025-04-07 400efb993a97e2aaacb3442d46178a125b26bea6
strategy/kpl_api.py
@@ -17,8 +17,6 @@
from strategy import data_cache
from strategy import basic_methods
from strategy.kpl_data_manager import KPLStockOfMarketsPlateLogManager
from strategy.market_sentiment_analysis import index_trend_expectation
from trade import middle_api_protocol
from utils import hx_qc_value_util, tool
@@ -187,37 +185,60 @@
    return json.dumps({"errcode": 0, "list": fresults})
# if __name__ == "__main__":
# print(f"打板列表t(pidType)====={daBanList(2)}")
# print(f"获取个股代码的板块==={getStockIDPlate('002766')}")
# print((f"获取个股代码的精选板块==={getCodeJingXuanBlocks('002878')}"))
# print(f"获取该概念下的个股代码及其他====={getCodesByPlate(885500)}")   《《《《《《《《《《
# print(f"获取概念中的板块中的子板块====={json.loads(getSonPlate(801085))}")
# 获取涨停信息数据
def get_limit_up_info():
    # 获取涨停信息列表
    limit_up_info = json.loads(getLimitUpInfoNew())['list']
    return limit_up_info
# print(f"获取概念中的板块强度====={getSonPlate(getCodesByPlate(getCodeJingXuanBlocks('002452')[2][0]))}")
# print(f"市场行情-行业板块 数==={len(getMarketIndustryRealRankingInfo(True))}")
# print(f"市场行情-行业板块==={json.loads(getMarketIndustryRealRankingInfo(True))}")
# 返回格式:['板块ID','板块名称','强度','涨幅','未知','成交额','''''''''强度','未知']
# print(f"市场行情-精选板块 数==={getMarketJingXuanRealRankingInfo(True)}")
# print(f"市场行情-精选板块==={json.loads(getMarketJingXuanRealRankingInfo(True))}")
# print(f"股票代码:{Market_situation_selected_sectors_No1[0]}")
# jingxuanbankuai = json.loads(getMarketJingXuanRealRankingInfo(True))
# print(f"jingxuanbankuai==={type(jingxuanbankuai)}")
# print(f"板块代码:{jingxuanbankuai['list'][0][0]},板块名称:{jingxuanbankuai['list'][0][1]},强度:{jingxuanbankuai['list'][0][2]},涨幅:{jingxuanbankuai['list'][0][3]},未知:{jingxuanbankuai['list'][0][4]},成交额:{round(jingxuanbankuai['list'][0][5]/100000000)}亿,主力净额:{round(jingxuanbankuai['list'][0][6]/100000000,2)}亿,主买:{round(jingxuanbankuai['list'][0][7]/100000000,2)}亿,主卖:{round(jingxuanbankuai['list'][0][8]/100000000,2)}亿,未知:{jingxuanbankuai['list'][0][9]},流通值:{round(jingxuanbankuai['list'][0][10]/100000000,2)}亿,未知/或为最大涨跌幅:{round(jingxuanbankuai['list'][0][11],2)},未知:{round(jingxuanbankuai['list'][0][12]/100000000,2)}亿,总市值:{round(jingxuanbankuai['list'][0][13]/100000000,2)}亿,第一季度机构持仓:{round(jingxuanbankuai['list'][0][14]/100000000,2)}亿,未知:{round(jingxuanbankuai['list'][0][15],2)},未知:{round(jingxuanbankuai['list'][0][16],2)},强度:{round(jingxuanbankuai['list'][0][17],2)}")
# # 部分板块没有子板块
# print(f"获取概念中的板块中的子板块====={json.loads(getSonPlate(801248))}")
# 获取市场情绪综合强度【完整】
def changeStatistics():
    """
    获取市场强度
    :return:
    """
    result = __base_request("https://apphwhq.longhuvip.com/w1/api/index.php",
                            f"a=ChangeStatistics&apiv=w35&c=HomeDingPan&PhoneOSNew=1&UserID=0&DeviceID=d6f20ce9-fa08-31c9-a493-536ebb8e9774&VerSion=5.13.0.0&Token=0&")
    # data = result.text
    data = json.loads(result)
    return data["info"][0]
# print(f"自由流通市值==={getZYLTAmount('603319')}")
# print((f"获取个股代码的精选板块列表==={getCodeJingXuanBlocks('002452')}"))
# print((f"获取个股代码的精选第一板块代码==={getCodeJingXuanBlocks('002452')[0][0]}"))
# print(f"获取该概念下的个股代码及其他====={json.loads(getCodesByPlate(getCodeJingXuanBlocks('002452')[0][0]))}")
# print(f"获取该概念下的个股代码及其他dddddd====={json.loads(its_strongest_sector_situation)}")
# print(f"涨停列表及概念板块={json.loads(getLimitUpInfoNew())['list']}")
########################################################################################################################################################################################################################
# 获取市场情绪综合强度
def get_market_strong():
    """
    获取市场强度
    :return:
    """
    result = __base_request("https://apphwhq.longhuvip.com/w1/api/index.php",
                            f"a=DiskReview&apiv=w35&c=HomeDingPan&VerSion=5.13.0.0&PhoneOSNew=1&DeviceID=d6f20ce9-fa08-31c9-a493-536ebb8e9773&")
    data = json.loads(result)
    return int(data["info"]["strong"])
# 市场情绪--涨跌统计
# 数据格式:
# SJZT:实际涨停  SJDT:实际跌停 SZJS:涨数量 ZT:涨停 DT:跌停  XDJS:跌数量  sign:人气概述
def getMarketFelling():
    result = __base_request("https://apphwhq.longhuvip.com/w1/api/index.php",
                            f"a=ZhangFuDetail&apiv=w35&c=HomeDingPan&PhoneOSNew=1&DeviceID=d6f20ce9-fa08-31c9-a493-536ebb8e9774&VerSion=5.13.0.0&")
    data = json.loads(result)
    return data["info"]
# market_strong = get_market_strong()
# print(f"market_strong==={market_strong}")
if __name__ == "__main__":
    MarketFelling = getMarketFelling()
    print(f"MarketFelling==={MarketFelling}")
    changeStatistics = changeStatistics()
    print(f"changeStatistics==={changeStatistics}")
# --------------------------------------------------------------------------------------------------------------------------------------------------------------
# 获取行情精选板块 强度排名
def get_market_sift_plate_its_stock_power():
@@ -332,29 +353,6 @@
            logger.error(f"开盘啦板块强度线程报错An error occurred: {e}")
        finally:
            time.sleep(2)
# 获取涨停信息数据
def get_limit_up_info():
    # 获取涨停信息列表
    limit_up_info = json.loads(getLimitUpInfoNew())['list']
    return limit_up_info
# 获取市场行情情绪综合强度
def get_market_strong():
    """
    获取市场强度
    :return:
    """
    result = __base_request("https://apphwhq.longhuvip.com/w1/api/index.php",
                            f"a=DiskReview&apiv=w35&c=HomeDingPan&VerSion=5.13.0.0&PhoneOSNew=1&DeviceID=d6f20ce9-fa08-31c9-a493-536ebb8e9773&")
    data = json.loads(result)
    return int(data["info"]["strong"])
# market_strong = get_market_strong()
# print(f"market_strong==={market_strong}")
# 获取涨停板块名称列表并存储本地的函数
@@ -742,79 +740,9 @@
    print(f"写入精选板块文件完成!::{now_time}")
# 获取实时大盘行情情绪综合强度 [分数] 函数 并 计算当日计划持仓数量
def get_real_time_market_strong():
    while True:
        try:
            if data_cache.position_automatic_management_switch is True:
                now_time = tool.get_now_time_str()
                if data_cache.L1_DATA_START_TIME < now_time < data_cache.CLOSING_TIME:
                    # 获取大盘综合强度分数
                    data_cache.real_time_market_strong = get_market_strong()
                    # data_cache.time_sharing_market_strong_dirt = time_sharing_market_strong_dirt.update({now: data_cache.real_time_market_strong})
                    # 该logger.info的的日志不再需要打印,后续将转入到GUI客户端上直接显示,该数据的打印交由下方的打印机制异步执行单独存储,以便后续可视化呈现后进行更高效的数据分析
                    # logger.info(f"大盘行情情绪综合强度 [分数]==={data_cache.real_time_market_strong}分")
                    if data_cache.MORN_MARKET_CLOSING_TIME < now_time < data_cache.NOON_MARKET_OPENING_TIME:
                        pass
                        logger.info(f"午间休市时间内 不打印大盘综合强度分数")
                    else:
                        # 大盘综合强度分数 的 异步日志
                        # logger_Overall_market_strength_score.info(data_cache.real_time_market_strong)
                        async_log_util.info(logger_Overall_market_strength_score,
                                            f"{data_cache.real_time_market_strong}")
                    usefulMoney = data_cache.account_finance_dict[0].get('usefulMoney', 0)
                    logger.info(f"账户可用资金==={usefulMoney}元")
                    # 低迷情绪比例
                    low_emotion_mood_ratio = 1
                    # 33分是个两级分化阶梯不好,目前不好拿捏,暂时不用
                    # if data_cache.real_time_market_strong <= 33:
                    if data_cache.real_time_market_strong < 30:
                        # 如果大盘综合强度分数小于30,将低迷情绪分数比例设置为0.01,可用资金缩小一百倍
                        low_emotion_mood_ratio = 0.01
                        if data_cache.real_time_market_strong <= 10:
                            low_emotion_mood_ratio = 0
                    logger.info(f"极端低迷情绪比例===={low_emotion_mood_ratio * 100}%")
                    data_cache.index_trend_expectation_score = index_trend_expectation()
                    logger.info(f"大盘指数情绪预期分数==={data_cache.index_trend_expectation_score}分")
                    # # 目前大盘指数情绪预期分数 尚不科学 强制设置为初始0值
                    # index_trend_expectation_score = 0
                    # 获取计算今天新增的持仓数量
                    addition_position_number = len(data_cache.addition_position_symbols_set)
                    # 定义一个今日的剩余新增持仓数量的变量
                    Unfinished_opening_plan_number = 3 - addition_position_number
                    logger.info(f"今日的剩余新增持仓数量==={Unfinished_opening_plan_number}")
                    if Unfinished_opening_plan_number != 0:
                        # 如果GUI看盘上没有手动设置具体的下单金额,就按照评分策略的金额下单,否则就按照GUI设置的金额下单。
                        if data_cache.BUY_MONEY_PER_CODE < 0:
                            # 根据账户可用金额 计算今日计划下单金额
                            # 账户可用金额 默认乘以0.9,永远留一点钱,一方面也冗余一些计算误差
                            #  ((大盘综合强度分数 + 大盘指数情绪预期分数) * 0.01) * (账户可用金额 * 0.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)
                            data_cache.today_planned_order_amount = (usefulMoney * 0.95 * low_emotion_mood_ratio / Unfinished_opening_plan_number)
                            logger.info(f"采用开仓策略计算方式=》今日计划下单金额:{data_cache.today_planned_order_amount},")
                        else:
                            data_cache.today_planned_order_amount = data_cache.BUY_MONEY_PER_CODE
                            logger.info(f"采用GUI设置方式=》今日计划下单金额:{data_cache.today_planned_order_amount}")
        except Exception as error:
            logger.error(f"获取实时大盘行情情绪综合强度[分数] 函数报错: {error}")
        finally:
            time.sleep(3)
# kpl_stocks_list_selected_blocks_process()   #在 kpl_api.py中可以调用
# stocks_list_selected_blocks(min_stocks)   #在 kpl_api.py中可以调用
# list = ['SHSE.600805','SHSE.600804']
#
# all_stocks_plate_dict(list)
if __name__ == "__main__":
    # start_time = time.time()
    # get_market_sift_plate_its_stock_power()
    # print("耗时:", time.time() - start_time)
    get_market_sift_plate_its_stock_power()
    # get_market_sift_plate_its_stock_power_process(None)