From bc1913abfdc364d97facb3edcd2d54130c8e1ce2 Mon Sep 17 00:00:00 2001 From: admin <admin@example.com> Date: 星期一, 23 六月 2025 10:30:59 +0800 Subject: [PATCH] bug修复 --- strategy/kpl_api.py | 587 +++------------------------------------------------------ 1 files changed, 38 insertions(+), 549 deletions(-) diff --git a/strategy/kpl_api.py b/strategy/kpl_api.py index e04ab3b..6e0362a 100644 --- a/strategy/kpl_api.py +++ b/strategy/kpl_api.py @@ -6,19 +6,21 @@ import time import datetime +import dask import requests import constant -# import requests +from log_module.log import logger_common, logger_kpl_jingxuan_in, logger_Overall_market_strength_score, \ + logger_stock_of_markets_plate, logger_debug + from strategy import data_cache from strategy import basic_methods - -from strategy.logging_config import get_logger +from strategy.kpl_data_manager import KPLMarketsSiftPlateLogManager from trade import middle_api_protocol -from utils import hx_qc_value_util +from utils import hx_qc_value_util, tool # 鑾峰彇logger瀹炰緥 -logger = get_logger() +logger = logger_common now = time.time() print(f"kpl_api寮�濮嬭繍琛�--{now}") @@ -35,7 +37,7 @@ DABAN_TYPE_EVER_LIMIT_DOWN = 5 -def __base_request(url, data, timeout=10): +def __base_request(url, data, timeout=10): DELEGATE = True if not DELEGATE: headers = { @@ -112,11 +114,10 @@ return result.get("ListJX") -# 鑾峰彇璇ユ蹇典笅鐨勪釜鑲′唬鐮佸強鍏朵粬 +# 鑾峰彇璇ユ蹇典笅鐨勪釜鑲′唬鐮佸強鍏朵粬 st=100 鑾峰彇鍓嶆帓100鍙偂绁� 銆愯幏鍙栨暟閲忋�戠敱浜庤繖閲岀洿鎺ユ帶鍒跺己搴︾殑鏁板�兼暟閲忥紝鏆備笉杞绘槗淇敼銆傜洰鏍囪瀹氫负鍏ㄩ儴锛屾垨100 def getCodesByPlate(plate_code): - data = f"Order=1&a=ZhiShuStockList_W8&st=30&c=ZhiShuRanking&PhoneOSNew=1&old=1&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&VerSion=5.8.0.2&IsZZ=0&Token=0&Index=0&apiv=w32&Type=6&IsKZZType=0&UserID=0&PlateID={plate_code}&" + data = f"Order=1&a=ZhiShuStockList_W8&st=100&c=ZhiShuRanking&PhoneOSNew=1&old=1&DeviceID=a38adabd-99ef-3116-8bb9-6d893c846e23&VerSion=5.8.0.2&IsZZ=0&Token=0&Index=0&apiv=w32&Type=6&IsKZZType=0&UserID=0&PlateID={plate_code}&" return __base_request("https://apphq.longhuvip.com/w1/api/index.php", data=data) - # 鑾峰彇姒傚康涓殑鏉垮潡涓殑瀛愭澘鍧� @@ -183,108 +184,6 @@ return json.dumps({"errcode": 0, "list": fresults}) -# if __name__ == "__main__": - - -# print(f"鎵撴澘鍒楄〃t(pidType)====={daBanList(2)}") -# print(f"鑾峰彇涓偂浠g爜鐨勬澘鍧�==={getStockIDPlate('002766')}") -# print((f"鑾峰彇涓偂浠g爜鐨勭簿閫夋澘鍧�==={getCodeJingXuanBlocks('002878')}")) -# print(f"鑾峰彇璇ユ蹇典笅鐨勪釜鑲′唬鐮佸強鍏朵粬====={getCodesByPlate(885500)}") 銆娿�娿�娿�娿�娿�娿�娿�娿�娿�� -# print(f"鑾峰彇姒傚康涓殑鏉垮潡涓殑瀛愭澘鍧�====={json.loads(getSonPlate(801085))}") - -# 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"鑲$エ浠g爜锛歿Market_situation_selected_sectors_No1[0]}") -# jingxuanbankuai = json.loads(getMarketJingXuanRealRankingInfo(True)) -# print(f"jingxuanbankuai==={type(jingxuanbankuai)}") -# print(f"鏉垮潡浠g爜锛歿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)}浜匡紝绗竴瀛e害鏈烘瀯鎸佷粨锛歿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))}") - -# print(f"鑷敱娴侀�氬競鍊�==={getZYLTAmount('603319')}") -# print((f"鑾峰彇涓偂浠g爜鐨勭簿閫夋澘鍧楀垪琛�==={getCodeJingXuanBlocks('002452')}")) -# print((f"鑾峰彇涓偂浠g爜鐨勭簿閫夌涓�鏉垮潡浠g爜==={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_sift_plate_its_stock_power(): - data = (getMarketJingXuanRealRankingInfo()) - market_sift_plate = json.loads(data) - # print(f"market_sift_plate 鏁� ======{len(market_sift_plate['list'])}") - # logger.info(f"market_sift_plate['list']======{market_sift_plate['list']}") - # logger.info(f"market_sift_plate['list'][0] ======{market_sift_plate['list'][0]}") - # 鍒濆鍖栫簿閫夋澘鍧楀搴斾釜鑲″瓧鍏� - market_sift_plate_stock_dict = {} - if 'list' in market_sift_plate: - for i in market_sift_plate['list']: - plate_name = i[1] - # 灏濊瘯杩囨护鎺夋棤鎰忎箟鐨勬蹇垫澘鍧�(plate_name not in ['绉戝垱鏉�', '鍖椾氦鎵�', '娆℃柊鑲�', '鏃�', 'ST鏉垮潡', 'ST鎽樺附', '骞惰喘閲嶇粍', '鍥戒紒鏀归潻','瓒呰穼', '澹宠祫婧�', '鑲℃潈杞', '閫佽浆濉潈']) and '澧為暱' in plate_name - if (plate_name not in ['绉戝垱鏉�', '鍖椾氦鎵�', '娆℃柊鑲�', '鏃�', 'ST鏉垮潡', 'ST鎽樺附', '骞惰喘閲嶇粍', '鍥戒紒鏀归潻', '瓒呰穼', - '澹宠祫婧�', '鑲℃潈杞', '閫佽浆濉潈']) or ('澧為暱' in plate_name): - # print(f"{i[1]} 寮哄害:{i[2]}") - # 閫氳繃鏉垮潡ID鑾峰彇鍏朵笅闈㈢殑涓偂寮哄害鍒楄〃 - its_stock = getCodesByPlate(i[0]) - its_stock = json.loads(its_stock) - # print(f"its_stock['list'] === {its_stock['list']}") - # print(f"its_stock['list'][0] === {its_stock['list'][0]}") - # 鑾峰彇璇ユ蹇垫澘鍧楃殑鐨勫瓙鐗堝潡 - # its_son_plate = json.loads(getSonPlate(i[0])) - # logger.info(f"its_son_plate=={its_son_plate['List']}") - # if its_son_plate['List'][0][2] > 0: - # print(f"its_son_plate=={its_son_plate['List'][0]}") - # for son in its_son_plate['List']: - # if son[2] > 0: - # print(f"son===={son}") - # 鍒濆鍖栬偂绁ㄥ己搴﹀垪琛� - stock_power_list = [] - for s in its_stock['list']: - # 杩囨护鎺夋定骞呭ぇ浜� and s[6] < 6.5 涓斿皬浜�0%鐨� 鍜� 鍚嶇О涓寘鍚玈T鐨� 鍜� 娑ㄩ�熷皬浜庣瓑浜�0%鐨� 鍜� 鍙鏄ㄦ棩鏈定鍋� 鍜� 涓婅瘉鎴栨繁璇佺殑姝h偂 and s[9] > 0.0025 - if s[6] > 0 and s[1].find("ST") < 0 and s[1].find("XD") < 0 and s[23].find("鏉�") < 0 and s[24].find( - "鏉�") < 0 and (s[0].startswith('60') or s[0].startswith('00')) and s[9] > 1: - # print(f"{s[1]}锛屼釜鑲′唬鐮侊細{s[0]}锛� 娑ㄥ箙锛歿s[6]}% 娑ㄩ�燂細{s[9]}% 姒傚康锛歿s[4]} 涓诲姏璧勯噾鎺ㄦ祴锛歿s[2]} 棰嗘定娆℃暟锛歿s[40]} 浠婃棩绗嚑鏉匡細{s[23]} 鏄惁鐮寸増{s[24]}") - # 瀵逛釜鑲″己搴﹀睘鎬у垪琛ㄨ繘琛屽垵濮嬪寲 - its_stock_power = [s[1], s[0], s[6], s[9], s[4], s[2], s[40]] - # 閫愪釜閫夋嫨鎬ф坊鍔爄ts_stock涓殑鍏冪礌鍒颁釜鑲″己搴﹀垪琛ㄤ腑 - # print(f"its_stock_power===={its_stock_power}") - # 鏁翠綋灏嗘坊鍔犲畬鍠勭殑涓偂寮哄害鍒楄〃娣诲姞鍒拌偂绁ㄥ垪琛ㄤ腑 - stock_power_list.append(its_stock_power) - # print(f"stock_power_list===={stock_power_list}") - # 杩囨护鎺夋病鏈夌灛鏃堕珮寮哄害涓偂鐨勭┖姒傚康 - if len(stock_power_list) != 0: - # 灏嗗搴旀澘鍧楃殑鑲$エ寮哄害鍒楄〃鏂板缓涓�涓瓧鍏� - stock_power_item = {i[1]: stock_power_list} - # 骞舵洿鏂板埌绮鹃�夋澘鍧椾釜鑲″瓧鍏镐腑 - market_sift_plate_stock_dict.update(stock_power_item) - logger.info(f"绮鹃�夋澘鍧楄偂绁ㄥ己搴︽暟鎹洿鏂� == {market_sift_plate_stock_dict}") - return market_sift_plate_stock_dict - - -# 璋冪敤涓�涓嬭幏鍙栫簿閫夋澘鍧楄偂绁ㄥ己搴︽暟鎹嚱鏁� 銆愭湰妯″潡鍐呬娇鐢ㄦ椂璋冪敤銆� -# get_market_sift_plate_its_stock_power() - -def get_market_sift_plate_its_stock_power_process(callback): - while True: - try: - # now = time.time() - # print(f"kpl_limit_up_process寮�濮嬩簡{now}") - its_stock_power = get_market_sift_plate_its_stock_power() - callback(its_stock_power) - # print(f"绮鹃�夋澘鍧楁媺鍗囦釜鑲℃洿鏂�===={its_stock_power}") - except Exception as e: - logger.error(f"寮�鐩樺暒鏉垮潡寮哄害绾跨▼鎶ラ敊An error occurred: {e}") - finally: - time.sleep(2) - - # 鑾峰彇娑ㄥ仠淇℃伅鏁版嵁 def get_limit_up_info(): # 鑾峰彇娑ㄥ仠淇℃伅鍒楄〃 @@ -292,7 +191,20 @@ return limit_up_info -# 鑾峰彇甯傚満琛屾儏鎯呯华缁煎悎寮哄害 +# 鑾峰彇甯傚満鎯呯华缁煎悎寮哄害銆愬畬鏁淬�� +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] + + +# 鑾峰彇甯傚満鎯呯华缁煎悎寮哄害 def get_market_strong(): """ 鑾峰彇甯傚満寮哄害 @@ -303,444 +215,21 @@ 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}") -# 鑾峰彇娑ㄥ仠鏉垮潡鍚嶇О鍒楄〃骞跺瓨鍌ㄦ湰鍦扮殑鍑芥暟 -def get_limit_up_block_names(): - # 鑾峰彇娑ㄥ仠淇℃伅鍒楄〃 - limit_up_info = get_limit_up_info() - # print(f"limit_up_info=={limit_up_info}") - data_cache.limit_up_info = get_limit_up_info() - # 鎻愬彇娑ㄥ仠鍒楄〃涓殑鏉垮潡鍚嶇О - limit_up_block_names = [] - # 璁惧畾褰撳墠鏃堕棿鐐� - now_time = datetime.datetime.now().strftime("%H:%M:%S") - # 寰幆娣诲姞娑ㄥ仠姒傚康 - for i in limit_up_info: - limit_up_block_names.append(i[5]) - # print(f"limit_up_block_names==={limit_up_block_names}") - # return limit_up_block_names - # # 浣跨敤Counter璁$畻姣忎釜鍏冪礌鐨勫嚭鐜版鏁� - # counter = Counter(limit_up_block_names) - # # 鎵惧嚭鍑虹幇娆℃暟鏈�澶氱殑鍏冪礌鍙婂叾娆℃暟 - # most_common_element, most_common_count = counter.most_common(1)[0] - # # 鎵撳嵃鍑虹幇娆℃暟鏈�澶氱殑鍏冪礌 - # print(f"涓荤嚎姒傚康锛歿most_common_element}锛屽嚭鐜颁簡 {most_common_count} 娆�") - if now_time > data_cache.after_closing_time: - # print(f"鏀剁洏缁撴潫锛岃褰曞綋鍓嶆定鍋滄澘鍧�") - # 灏嗚幏鍙栧埌鐨勬定鍋滄蹇垫澘鍧楄浆JSON鏍煎紡骞跺瓨鍌ㄥ湪鏈湴鏂囦欢澶逛腑 - # 灏嗗瓧鍏歌浆鎹负JSON鏍煎紡鐨勫瓧绗︿覆 - json_data = json.dumps(limit_up_block_names) - # print(f"json_data=={json_data}") - if len(json_data) != 0: - # 鍐欏叆鏂囦欢 - with open(constant.KPL_LIMIT_UP_BLOCK_NAMES_PATH, 'w', encoding='utf-8') as f: - f.write(json_data) - return limit_up_block_names - -# 涓哄紑鐩樺暒鎺ュ彛鑾峰彇鐨勬定鍋滃垪琛ㄦ蹇垫澘鍧楀崟鐙紑涓�涓繘绋� 褰㈠弬(callback) -def kpl_limit_up_process(callback): - while True: - try: - # now = time.time() - # print(f"kpl_limit_up_process寮�濮嬩簡{now}") - limit_up_block_names = get_limit_up_block_names() - callback(limit_up_block_names) - # logger.info(f"娑ㄥ仠鏇存柊===={limit_up_block_names}") - # print(f"娑ㄥ仠鏇存柊鏁伴噺===={len(limit_up_block_names)}") - # print(f"kpl_limit_up_process瀹屾垚涓�涓媨now}") - except Exception as e: - logger.error(f"寮�鐩樺暒娑ㄥ仠鏉垮潡姒傚康绾跨▼鎶ラ敊An error occurred: {e}") - finally: - time.sleep(1.5) - - -# kpl_limit_up_process() - - -# 鏋勫缓娑ㄥ仠淇℃伅璇诲啓瀵硅薄 -class DailyLimitUpInfoStorageManager: - # 鍒濆鍖栨枃浠惰矾寰� - def __init__(self, file_path=constant.KPL_LIMIT_UP_DATA_PATH): - self.file_path = file_path - - # 娣诲姞鍗曟棩娑ㄥ仠淇℃伅鏁版嵁鍒版枃浠朵腑鐨勪竴琛� 鍑芥暟 - def append_data_to_file(self, data_to_append): - # print(f"data_to_append=={data_to_append}") - # 璇诲彇鎵�鏈夎骞惰В鏋愪负 JSON 瀵硅薄鍒楄〃 - if os.path.exists(self.file_path): - with open(self.file_path, 'r', encoding='utf-8') as file: - # 鑾峰彇褰撳墠鏃ユ湡骞舵牸寮忓寲 - current_date = datetime.datetime.now().strftime('%Y-%m-%d') - lines = [json.loads(line.strip()) for line in file if line.strip()] - # print(f"lines type=={type(lines)}") - # print(f"lines=={lines}") - # 妫�鏌ュ綋鍓嶆棩鏈熸槸鍚﹀凡瀛樺湪浜庢枃浠朵腑 - if lines: # 濡傛灉璇诲彇鍒扮殑琛屾枃浠跺垪琛ㄤ笉涓虹┖锛堜负鐪燂級 - if lines[-1].get(current_date) is None: # 濡傛灉鍒楄〃涓殑鍊掓暟鏈�鍚庝竴琛岃幏鍙栦笉鍒板綋鏃ョ殑鏃ユ湡锛堟渶鍚庝竴琛岀殑閿� 涓� 褰撴棩鏃ユ湡锛� - # 灏嗘棩鏈熷拰data_to_append杞崲涓篔SON鏍煎紡鐨勫瓧绗︿覆 - json_line = json.dumps({current_date: data_to_append}, ensure_ascii=False) + '\n' - # 鎵撳紑鏂囦欢骞惰拷鍔燡SON琛� - with open(self.file_path, 'a', encoding='utf-8') as file:file.write(json_line) - else: - logger.info(f"锛堝綋鏃ユ棩鏈熷凡瀛樺湪浜庢枃浠剁殑鏈�鍚庝竴琛屼簡锛屼笉鍐嶉噸澶嶈拷鍔犲啓鍏ワ級") - else: - json_line = json.dumps({current_date: data_to_append}, ensure_ascii=False) + '\n' - # 鎵撳紑鏂囦欢骞惰拷鍔燡SON琛� - with open(self.file_path, 'a', encoding='utf-8') as file: - file.write(json_line) - - # 娓呯悊澶氫綑鏁版嵁鍑芥暟 - def check_and_remove_oldest_entry(self, max_entries): - # 璇诲彇鎵�鏈夎骞惰В鏋愪负 JSON 瀵硅薄鍒楄〃 - if os.path.exists(self.file_path): - with open(self.file_path, 'r', encoding='utf-8') as file: - lines = [json.loads(line.strip()) for line in file if line.strip()] - else: - lines = [] - - # 濡傛灉琛屾暟瓒呰繃闄愬埗锛岀Щ闄ゆ渶鏃╃殑涓�浜涜 - if len(lines) >= max_entries: - # 鎴柇鍒楄〃锛屽彧淇濈暀鏈�鏂扮殑 max_entries 涓璞� - lines = lines[-max_entries:] - # 閲嶆柊鎵撳紑鏂囦欢浠ュ啓鍏ユā寮忥紝骞跺啓鍏ユ埅鏂悗鐨勫璞″垪琛ㄤ负 JSON Lines - with open(self.file_path, 'w', encoding='utf-8') as file: - for obj in lines: - file.write(json.dumps(obj, ensure_ascii=False) + '\n') - # file.write(json.dumps(obj, ensure_ascii=False)) - - # 闅旇鏁寸悊鏁版嵁骞跺悎骞惰鍏ヤ竴涓瓧鍏告暟鎹腑璋冪敤鏃惰繑鍥炶繖涓瓧鍏告暟鎹� 鍑芥暟 - def arrange_limit_up_info(self): - limit_info = {} - # 鍒涘缓涓�涓垪琛ㄦ潵瀛樺偍鎵�鏈夎В鏋愮殑 JSON 瀵硅薄 - if os.path.exists(self.file_path): - with open(self.file_path, 'r', encoding='utf-8') as file: - for line in file: - # 鍘婚櫎姣忚鏈熬鐨勬崲琛岀锛堝鏋滄湁鐨勮瘽锛� - line = line.rstrip('\n') - # 灏嗘瘡琛岃В鏋愪负涓�涓� JSON 瀵硅薄 - info = json.loads(line) - # 鍋囪姣忚閮芥槸涓�涓瓧鍏告暟鎹紝涓斿彧鏈変竴涓敭鍊煎锛屽叾涓敭鏄棩鏈� - if isinstance(info, dict) and len(info) == 1: - date, data = list(info.items())[0] - limit_info[date] = data - return limit_info - - -# 鏋勫缓涓�涓幏鍙栬鍐欏瓨鍌ㄦ湰鍦扮殑骞舵暣鐞嗘定鍋滄暟鎹殑鍑芥暟 -def get_arrange_limit_up_info(): - # 瀹炰緥鍖栨瘡鏃ユ定鍋滀俊鎭暣鐞嗘柟娉� - manager = DailyLimitUpInfoStorageManager() - manager.append_data_to_file(get_limit_up_info()) - manager.check_and_remove_oldest_entry(max_entries=1000) - - -# 鏋勫缓涓�涓鐞嗗巻鍙叉定鍋滄定鍋滀俊鎭暟鎹殑鍑芥暟 -def get_handling_limit_up_info(): - # 瀹炰緥鍖栨瘡鏃ユ定鍋滀俊鎭暣鐞嗘柟娉� - history_limit_up_info = DailyLimitUpInfoStorageManager() - data_cache.daily_limit_up_info = history_limit_up_info.arrange_limit_up_info() - # logger.info(f"璇绘湰鍦扮殑鏃ユ洿鐨勫巻鍙叉定鍋滄暟鎹�=={data_cache.daily_limit_up_info}") - - - # print(f"daily_limit_up_info 绫诲瀷==={type(data_cache.daily_limit_up_info)}") - # 缁熻姣忔棩涓荤嚎 - daily_limit_up_info_len = len(data_cache.daily_limit_up_info) - # print(f"daily_limit_up_info_len==={daily_limit_up_info_len}") - - historical_transaction_date_list = [] - date_of_the_day = data_cache.DataCache().today_date - for i in range(daily_limit_up_info_len): - pre_date = hx_qc_value_util.get_previous_trading_date(date_of_the_day) # 鑾峰彇鍓嶄竴涓氦鏄撴棩API - # target_date_str = basic_methods.pre_num_trading_day(data_cache.today_date, daily_limit_up_info_len) - date_format = "%Y-%m-%d" - target_date = datetime.datetime.strptime(pre_date, date_format).strftime("%Y-%m-%d") - historical_transaction_date_list.append(target_date) - date_of_the_day = pre_date - - # print(f"historical_transaction_date_list={historical_transaction_date_list}") - history_sorted_plate_ranking_list = [] - for key, value in data_cache.daily_limit_up_info.items(): - # print(f"key=={key}") - for i in historical_transaction_date_list: - # print(f"i======={i}") - # 鎵惧埌姣忎笂涓�涓氦鏄撴棩瀵瑰簲鐨勬湰鍦版暟鎹殑淇℃伅 - if key == i: - # print(f"{key}===鎵惧埌浜嗭紒value={value}") - # - plate_ranking_list = [] - # 閬嶅巻浜ゆ槗鏃ユ瘡涓�涓定鍋滆偂鐨勪俊鎭� - for v in value: - # print(f"v =={v}") - # 灏嗘瘡涓�涓定鍋滆偂鐨勬定鍋滄蹇靛拰鍚岀彮绾ф暟閲� 姹囩紪涓轰竴涓瓧鍏� - plate_limit_up_num_dict = { - v[5]: v[20] - } - # 灏嗚繖涓瓧鍏告暟鎹笉閲嶅鐨勬坊鍔犲埌姒傚康鎺掑悕鍒楄〃涓� - if plate_limit_up_num_dict not in plate_ranking_list: - plate_ranking_list.append(plate_limit_up_num_dict) - # plate_ranking_set.add(v[20]) - # print(f"plate_ranking_list={plate_ranking_list}") - # 浣跨敤sorted鍑芥暟鍜宭ambda琛ㄨ揪寮忔潵鏍规嵁瀛楀吀鐨勫�艰繘琛屾帓搴� - # 杩欓噷鎴戜滑纭繚涓嶄慨鏀瑰師濮嬪瓧鍏革紝浠呴�氳繃list(x.values())[0]鏉ヨ幏鍙栧�� - sorted_plate_ranking_list = sorted(plate_ranking_list, key=lambda x: list(x.values())[0], reverse=True) - # logger.info(f"{key}=====>>>>{sorted_plate_ranking_list}") - history_sorted_plate_ranking_list.append(sorted_plate_ranking_list) - # print(f"history_sorted_plate_ranking_list={history_sorted_plate_ranking_list}") - # for ranking_list in history_sorted_plate_ranking_list: - # print(f"ranking_list={ranking_list}") - # for i in ranking_list: - # print(f"i={i}") - - # 璁$畻鍘嗗彶娑ㄥ仠姒傚康鐨勮繛缁嚭鐜版鏁板嚱鏁� - def count_key_occurrences(list_of_dicts_lists): - # 鍒涘缓涓�涓瓧鍏告潵瀛樺偍姣忎釜閿殑鎬诲嚭鐜版鏁� - key_counts = {} - # 閬嶅巻鍒楄〃涓殑姣忎釜瀛楀吀鍒楄〃 - for sublist in list_of_dicts_lists: - # 閬嶅巻褰撳墠瀛楀吀鍒楄〃涓殑姣忎釜瀛楀吀 - for dict_item in sublist: - # 閬嶅巻瀛楀吀涓殑姣忎釜閿� - for key in dict_item: - # 濡傛灉閿笉鍦╧ey_counts涓紝鍒欏垵濮嬪寲璁℃暟涓�0 - if key not in key_counts: - key_counts[key] = 0 - # 澧炲姞褰撳墠閿殑璁℃暟 - key_counts[key] += 1 - # 鎵撳嵃缁撴灉 - for key, count in key_counts.items(): - if count > 1: - logger.info(f"'{key}' 杩炵画鍑虹幇 {count} 娆�") - - # 璋冪敤鍑芥暟锛屼紶鍏ユ暣涓垪琛� - # count_key_occurrences(history_sorted_plate_ranking_list) - - # daily_limit_up_info_list = list(reversed(daily_limit_up_info_list)) - # print(f"daily_limit_up_info_list==={daily_limit_up_info_list}") - - # 鑾峰彇鏄ㄦ棩娑ㄥ仠浠g爜 锛堜互渚夸笌K绾垮姣旓級 - pre_trading_day_limit_up_info = data_cache.daily_limit_up_info.get(data_cache.DataCache().pre_trading_day) - if pre_trading_day_limit_up_info is not None: - yesterday_limit_up_code_list = [] - for i in pre_trading_day_limit_up_info: - symbol_code = basic_methods.format_stock_symbol(i[0]) - limit_up_code = symbol_code - yesterday_limit_up_code_list.append(limit_up_code) - data_cache.yesterday_limit_up_code_list = yesterday_limit_up_code_list - logger.info(f"鏄ㄦ棩娑ㄥ仠鑲$エ鏁伴噺=={len(data_cache.yesterday_limit_up_code_list)}") - logger.info(f"鏄ㄦ棩娑ㄥ仠浠g爜鍒楄〃=={yesterday_limit_up_code_list}") - - # code = pre_trading_day_limit_up_info[0][0] - # logger.info(f"鑲$エ浠g爜=={code}") - # cor_name = pre_trading_day_limit_up_info[0][1] - # logger.info(f"鍏徃鍚嶇О=={cor_name}") - # unknown_zero_2 = pre_trading_day_limit_up_info[0][2] - # logger.info(f"鏈煡闆跺��2=={unknown_zero_2}") - # none_data = pre_trading_day_limit_up_info[0][3] - # logger.info(f"绌烘暟鎹�=={none_data}") - # # 鎬诲競鍊�(涓�)锛� - # total_market_value = round((pre_trading_day_limit_up_info[0][4] / 10000), 2) - # logger.info(f"鎬诲競鍊�=={total_market_value}(涓�)锛�") - # # 鏈�鐩稿叧姒傚康 - # the_most_relevant_plate = pre_trading_day_limit_up_info[0][5] - # logger.info(f"鏈�鐩稿叧姒傚康=={the_most_relevant_plate}") - # # 鏀剁洏灏佸崟閲戦(涓�) - # closing_amount = round((pre_trading_day_limit_up_info[0][6] / 10000), 2) - # logger.info(f"鏀剁洏灏佸崟閲戦=={closing_amount}(涓�)") - # # 鏈�澶у皝鍗曢噾棰�(涓�) - # maximum_blocked_amount = round((pre_trading_day_limit_up_info[0][7] / 10000), 2) - # logger.info(f"鏈�澶у皝鍗曢噾棰�=={maximum_blocked_amount}(涓�)") - # # 涓诲姏鍑�棰� - # main_net_amount = round((pre_trading_day_limit_up_info[0][8] / 10000), 2) - # logger.info(f"涓诲姏鍑�棰�=={main_net_amount}(涓�)") - # # 涓诲姏涔� - # main_buyers = round((pre_trading_day_limit_up_info[0][9] / 10000), 2) - # logger.info(f"涓诲姏涔�=={main_buyers}(涓�)") - # # 涓诲姏鍗� - # main_sellers = round((pre_trading_day_limit_up_info[0][10] / 10000), 2) - # logger.info(f"涓诲姏鍗�=={main_sellers}(涓�)") - # # 鎴愪氦棰� - # transaction_amount = round((pre_trading_day_limit_up_info[0][11] / 10000), 2) - # logger.info(f"鎴愪氦棰�=={transaction_amount}(涓�)") - # # 鎵�灞炵簿閫夋澘鍧� - # selected_plate = pre_trading_day_limit_up_info[0][12] - # logger.info(f"鎵�灞炵簿閫夋澘鍧�=={selected_plate}") - # # 瀹為檯娴侀�� - # actual_circulation = round((pre_trading_day_limit_up_info[0][11] / 100000000), 2) - # logger.info(f"瀹為檯娴侀��=={actual_circulation}(浜�)") - # # 閲忔瘮锛燂紙涓嶆槸锛屼笉鐭ラ亾鏄粈涔堬級 - # equivalent_ratio = pre_trading_day_limit_up_info[0][14] - # logger.info(f"閲忔瘮锛�=={equivalent_ratio}") - # # 棰嗘定娆℃暟 - # leading_increases_times = pre_trading_day_limit_up_info[0][15] - # logger.info(f"棰嗘定娆℃暟=={leading_increases_times}") - # # 鏈煡闆跺�� - # unknown_zero_16 = pre_trading_day_limit_up_info[0][16] - # logger.info(f"鏈煡闆跺��16=={unknown_zero_16}") - # # 鏈煡闆跺�� - # unknown_zero_17 = pre_trading_day_limit_up_info[0][17] - # logger.info(f"鏈煡闆跺��17=={unknown_zero_17}") - # # 绗嚑鏉�(杩炵画娑ㄥ仠澶╂暟) - # continuous_limit_up_days = pre_trading_day_limit_up_info[0][18] - # logger.info(f"绗嚑鏉�=={continuous_limit_up_days}") - # # 鏈�鐩稿叧姒傚康鐨勪唬鐮� - # the_most_relevant_plate_code = pre_trading_day_limit_up_info[0][19] - # logger.info(f"鏈�鐩稿叧姒傚康鐨勪唬鐮�=={the_most_relevant_plate_code}") - # # 鍚岀彮绾х殑鏁伴噺(鍚屾蹇垫定鍋滄暟閲�) - # the_same_class_amount = pre_trading_day_limit_up_info[0][20] - # logger.info(f"鍚屾蹇垫定鍋滄暟閲�=={the_same_class_amount}") - -# get_handling_limit_up_info() - - -# 鑾峰彇鍏ㄩ儴涓偂鐨勬澘鍧楀苟瀛樺偍鐨勫嚱鏁� -def get_all_stocks_plate_dict(stocks_list): - all_stocks_plate_dict = {} - # 閫愪釜鑾峰彇涓偂绮鹃�夋澘鍧楁蹇靛拰鑷敱甯傚�肩瓑锛屽苟鏁翠綋鏀惧叆涓�涓柊鍒涘缓鐨勫瓧鍏镐腑鐒跺悗娣诲姞鍒版暟鎹腑 - for i in stocks_list: - try: - code = i.split('.')[1] - # print(f"i==={i}") - # 鑾峰彇涓偂鐨勮嚜鐢卞競鍊� - free_market_value = getZYLTAmount(code) - # 鑾峰彇涓偂鐨勬澘鍧楀垪琛� - selected_blocks = getStockIDPlate(code) - # 鎻愬彇绮鹃�夋澘鍧椾腑鐨勬澘鍧楀悕绉� - selected_plate_list = [block[1] for block in selected_blocks] - # print(f"selected_block_names==={selected_block_list}") - block_data = { - # 娣诲姞鑷敱甯傚�� - 'free_market_value': free_market_value, - # 娣诲姞绮鹃�夋澘鍧� - 'plate': selected_plate_list - } - # 灏哻ode浣滀负閿紝stocks_selected_block_data浣滀负鍊兼坊鍔犲埌stocks_block_data瀛楀吀涓� - all_stocks_plate_dict[code] = block_data - # print(f"all_stocks_plate_dict==={all_stocks_plate_dict}") - except Exception as e: - print(f"鑾峰彇鍏ㄩ儴涓偂鐨勬澘鍧楀苟瀛樺偍鐨勫嚱鏁� An error occurred: {e}") - finally: - pass - # return stocks_plate_data - # print(f"all_stocks_plate_dict==={len(all_stocks_plate_dict)}") - # 灏嗚幏鍙栧埌鐨勮寖鍥寸エ姒傚康鏉垮潡杞琂SON鏍煎紡骞跺瓨鍌ㄥ湪鏈湴鏂囦欢澶逛腑 - # 灏嗗瓧鍏歌浆鎹负JSON鏍煎紡鐨勫瓧绗︿覆 - json_data = json.dumps(all_stocks_plate_dict) - # 鍐欏叆鏂囦欢 - with open(constant.ALL_STOCKS_PLATE_PATH, 'w', encoding='utf-8') as f: - f.write(json_data) - now_time = datetime.datetime.now() # 鑾峰彇鏈満鏃堕棿 - logger.info(f"鍐欏叆鎵�鏈変釜鑲℃澘鍧楁枃浠跺畬鎴愶紒::{now_time}") - - -# 璁$畻寮�鐩樺暒鏄ㄦ棩鎷夊彇鐨勬蹇垫暟鎹腑涓虹┖鐨勮偂绁ㄦ暟閲忓嚱鏁� -def get_have_no_plate_num(): - # 鍒濆鍖栨棤姒傚康鏁伴噺 - have_no_plate_num = 0 - plate_are_null_list = [] - for k, v in data_cache.all_stocks_plate_dict.items(): - pass - # print(f"i==={i} T==={t}") - if len(v['plate']) == 0: - have_no_plate_num += 1 - # print(f"{k}鐨勬蹇典负绌�") - # logger.info(f"{k}鐨勬蹇典负绌�") - # 鑲$エ浠g爜鏍煎紡杞寲涓烘帢閲戞牸寮� - symbol = basic_methods.format_stock_symbol(k) - sec_name = data_cache.all_stocks_all_K_line_property_dict.get(symbol) - if sec_name is not None: - plate_are_null_list.append(sec_name) - logger.info(f"鏈墈have_no_plate_num}鍙偂绁ㄦ蹇典负绌�") - logger.info(f"涓偂鏈夊巻鍙睰绾夸絾姒傚康涓虹┖鐨勬湁锛歿plate_are_null_list}") - - - - - -# 鑾峰彇鍏ㄩ儴涓偂鐨勭簿閫夋澘鍧楀苟瀛樺偍鐨勫嚱鏁� -def stocks_list_selected_blocks(min_stocks): - stocks_selected_block_data = [] - # 閫愪釜鑾峰彇涓偂绮鹃�夋澘鍧楁蹇靛拰鑷敱甯傚�肩瓑锛屽苟鏁翠綋鏀惧叆涓�涓柊鍒涘缓鐨勫瓧鍏镐腑鐒跺悗娣诲姞鍒版暟鎹腑 - for i in min_stocks: - try: - code = i.split('.')[1] - # 鑾峰彇涓偂鐨勮嚜鐢卞競鍊� - free_market_value = getZYLTAmount(code) - # 鑾峰彇涓偂鐨勭簿閫夋澘鍧楀垪琛� - # selected_blocks = getCodeJingXuanBlocks('000021') - selected_blocks = getCodeJingXuanBlocks(code) - # 鎻愬彇绮鹃�夋澘鍧椾腑鐨勬澘鍧楀悕绉� - selected_block_list = [block[1] for block in selected_blocks] - # print(f"selected_block_names==={selected_block_list}") - stocks_selected_block_dict = { - # 娣诲姞鑲$エ浠g爜 - 'code': code, - # 娣诲姞鑷敱甯傚�� - 'free_market_value': free_market_value, - # 娣诲姞绮鹃�夋澘鍧� - 'selected_block': selected_block_list - } - stocks_selected_block_data.append(stocks_selected_block_dict) - # print(f"stocks_selected_block_data==={stocks_selected_block_dict}") - except Exception as e: - logger.error(f"鑾峰彇鍏ㄩ儴涓偂鐨勭簿閫夋澘鍧楀苟瀛樺偍鐨勫嚱鏁� An error occurred: {e}") - - # print(f"stocks_selected_block_data==={len(stocks_selected_block_data)}") - # 灏嗚幏鍙栧埌鐨勮寖鍥寸エ姒傚康鏉垮潡杞琂SON鏍煎紡骞跺瓨鍌ㄥ湪鏈湴鏂囦欢澶逛腑 - # 灏嗗瓧鍏歌浆鎹负JSON鏍煎紡鐨勫瓧绗︿覆 - json_data = json.dumps(stocks_selected_block_data) - # 鍐欏叆鏂囦欢 - with open('local_storage_data/stocks_selected_block_data.json', 'w', encoding='utf-8') as f: - f.write(json_data) - now_time = datetime.datetime.now() # 鑾峰彇鏈満鏃堕棿 - print(f"鍐欏叆绮鹃�夋澘鍧楁枃浠跺畬鎴愶紒::{now_time}") - - -# 鑾峰彇瀹炴椂澶х洏琛屾儏鎯呯华缁煎悎寮哄害 [鍒嗘暟] 鍑芥暟 -def get_real_time_market_strong(): - while True: - try: - if data_cache.position_automatic_management_switch is True: - # 鍒濆鍖栧垎鏃跺競鍦烘儏缁垎鏁板垪琛ㄦ暟鎹垪琛� - time_sharing_market_strong_dirt = {} - now = datetime.datetime.now() # 鑾峰彇鏈満鏃堕棿 - 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(f"澶х洏琛屾儏鎯呯华缁煎悎寮哄害 [鍒嗘暟]==={data_cache.real_time_market_strong}鍒�") - usefulMoney = data_cache.account_finance_dict[0].get('usefulMoney', 0) - logger.info(f"璐︽埛鍙敤璧勯噾==={usefulMoney}鍏�") - # 鏈烘鐗� - # if data_cache.real_time_market_strong >= 70: - # data_cache.have_plate_buy_money = 30000 - # data_cache.have_strength_buy_money = 30000 - # elif 60 <= data_cache.real_time_market_strong < 70: - # data_cache.have_plate_buy_money = 20000 - # data_cache.have_strength_buy_money = 20000 - # elif 50 <= data_cache.real_time_market_strong < 60: - # data_cache.have_plate_buy_money = 10000 - # data_cache.have_strength_buy_money = 10000 - # elif 30 <= data_cache.real_time_market_strong < 50: - # data_cache.have_plate_buy_money = 3000 - # data_cache.have_strength_buy_money = 3000 - # elif data_cache.real_time_market_strong < 30: - # data_cache.have_plate_buy_money = 1000 - # data_cache.have_strength_buy_money = 1000 - - # 鏍规嵁璐︽埛鍙敤閲戦 璁$畻浠婃棩璁″垝涓嬪崟閲戦 - # (璐︽埛鍙敤閲戦/浠婃棩鏈�澶ф柊澧炴寔浠撶エ鏁�) * 锛堝ぇ鐩樼患鍚堝己搴︿唤鏁� * 0.01锛� - # data_cache.today_planned_order_amount = (200000 / 3) * (data_cache.real_time_market_strong * 0.01) # 娴嬭瘯鏄笉鏄彲鐢ㄨ祫閲戞病鏈夋洿鏂扮殑鍘熷洜 - data_cache.today_planned_order_amount = (usefulMoney / 3) * (data_cache.real_time_market_strong * 0.01) - 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__": + MarketFelling = getMarketFelling() + print(f"MarketFelling==={MarketFelling}") + changeStatistics = changeStatistics() + print(f"changeStatistics==={changeStatistics}") -- Gitblit v1.8.0