From 2f2516749615da866e96d8d24e499b7ecbb63a3e Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期一, 23 六月 2025 12:28:52 +0800 Subject: [PATCH] 默认交易模式变更/真实下单位置计算位置修改 --- utils/init_data_util.py | 174 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 133 insertions(+), 41 deletions(-) diff --git a/utils/init_data_util.py b/utils/init_data_util.py index 53977c9..70a3f5b 100644 --- a/utils/init_data_util.py +++ b/utils/init_data_util.py @@ -2,6 +2,7 @@ import decimal from code_attribute import gpcode_manager +from log_module.log import logger_debug from third_data.history_k_data_util import HistoryKDatasUtils from utils import tool @@ -12,27 +13,124 @@ def re_set_price_pres(codes, force=False): - result = HistoryKDatasUtils.get_gp_latest_info(codes) - for item in result: - symbol = item['symbol'] - symbol = symbol.split(".")[1] - pre_close = tool.to_price(decimal.Decimal(str(item['pre_close']))) - gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close, force) + # 閫氳繃鍘嗗彶鏁版嵁缂撳瓨鑾峰彇 + for code in codes: + result = HistoryKDatasUtils.get_history_tick_n(code, 1) + for item in result: + symbol = item['symbol'] + symbol = symbol.split(".")[1] + pre_close = tool.to_price(decimal.Decimal(str(item['close']))) + gpcode_manager.CodePrePriceManager.set_price_pre(symbol, pre_close, force) # 鑾峰彇杩�90澶╃殑鏈�澶ч噺涓庢渶杩戠殑閲� # 鑾峰彇鏈�杩戜竴娆℃定鍋�/娑ㄥ仠涓嬩竴涓氦鏄撴棩鐨勬渶澶у�� -def get_volumns_by_code(code, count=60) -> object: +def get_volumns_by_code(code, count=60): datas = HistoryKDatasUtils.get_history_tick_n(code, count, "open,high,low,close,volume,pre_close,bob,amount") + if not datas: + return None # 璁$畻 datas.sort(key=lambda x: x["bob"], reverse=True) return datas -# 瑙f瀽鏈�澶ч噺 -def parse_max_volume(datas, is_new_or_near_top=False): +def parse_max_volume(code, datas, is_new_or_near_top=False): + result = __parse_max_volume(code, datas, is_new_or_near_top) + refer_index = result[3] + # 璁$畻鏈�浣庝环 + refer_price = datas[refer_index]["high"] + min_price = float(refer_price) + for i in range(0, refer_index + 1): + if min_price > datas[i]["low"]: + min_price = datas[i]["low"] + if (refer_price - min_price) / refer_price < 0.4: + return result + # 瓒呰穼 + new_datas = [] + for i in range(0, refer_index): + # 鑾峰彇娑ㄥ箙 + item = datas[i] + rate = (item["low"] - item["pre_close"]) / item["pre_close"] + new_datas.append((i, rate)) + new_datas.sort(key=lambda x: x[1]) + refer_index = new_datas[0][0] + # 鑾峰彇褰撳墠澶╁拰鍚庝竴澶╄緝澶ч噺 + if refer_index > 0: + if datas[refer_index - 1]["volume"] > datas[refer_index]["volume"]: + refer_index -= 1 + + return datas[refer_index]["volume"], datas[refer_index]["volume"], datas[refer_index]['bob'].strftime( + "%Y-%m-%d"), refer_index + + +def parse_max_volume_new(code, datas): + """ + 璁$畻杩滈珮閲� + @param code: + @param datas: + @return: [楂橀噺,楂橀噺,楂橀噺鏃ユ湡,楂橀噺绱㈠紩] + """ + + def __is_limited_up(item): + limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"])) + if abs(limit_up_price - item["high"]) < 0.001: + return True + return False + + # 鍙栨渶杩�60涓氦鏄撴棩 + datas = datas[:60] + + # 鍒ゆ柇鏄惁娑ㄥ仠杩� + target_index = None + for i in range(len(datas)): + data = datas[i] + if __is_limited_up(data): + next_data = None + if i > 0: + next_data = datas[i - 1] + # max锛堟定鍋滆繖涓�澶�, 鍚庝竴澶╋級鐨勯噺 + if next_data and next_data['volume'] > data['volume']: + target_index = i - 1 + else: + target_index = i + break + if target_index is None: + # 60澶╂湭娑ㄥ仠,鑾峰彇60澶╁唴鐨勬渶楂橀噺 + for i in range(len(datas)): + data = datas[i] + if target_index is None: + target_index = i + if data['volume'] > datas[target_index]['volume']: + target_index = i + return datas[target_index]['volume'], datas[target_index]['volume'], datas[target_index]['bob'].strftime( + "%Y-%m-%d"), target_index + + +def parse_max_volume_in_days(datas, max_day): + """ + 瑙f瀽鏈�杩戝嚑澶╂渶澶х殑閲� + @param datas: + @param max_day: + @return: + """ + # 瑙f瀽鏈�杩戝嚑澶╃殑鏈�澶ч噺 + datas = datas[:max_day] + max_volume_info = None + for d in datas: + if max_volume_info is None: + max_volume_info = (d["volume"], d) + if d["volume"] > max_volume_info[0]: + max_volume_info = (d["volume"], d) + if max_volume_info: + return max_volume_info[0] + return None + + +# 杩斿洖锛�(60澶╂渶澶ч噺,鏄ㄦ棩閲�,閲忓弬鑰冩棩鏈�,鍙傝�冮噺鎹粖浜ゆ槗鏃ユ暟) +def __parse_max_volume(code, datas, is_new_or_near_top=False): max_volume = 0 max_volume_date = None + max_volume_index = None # 鍒ゆ柇30澶╁唴鏄惁鏈夋定鍋� if is_new_or_near_top: # 30澶╁唴鏄惁鏈夋定鍋� @@ -41,26 +139,29 @@ if i >= len(datas): break item = datas[i] - limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) + limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"])) if abs(limit_up_price - item["high"]) < 0.001: latest_limit_up_index = i break if latest_limit_up_index is not None: # 绐佺牬鍓嶉珮鎴栬�呮帴杩戝墠楂橈紝30涓氦鏄撴棩鍐呮湁娑ㄥ仠 - if latest_limit_up_index > 0 and datas[latest_limit_up_index - 1]["volume"] > datas[latest_limit_up_index]["volume"]: + if latest_limit_up_index > 0 and datas[latest_limit_up_index - 1]["volume"] > datas[latest_limit_up_index][ + "volume"]: return datas[latest_limit_up_index - 1]["volume"], datas[latest_limit_up_index - 1]["volume"], \ - datas[latest_limit_up_index - 1]['bob'].strftime("%Y-%m-%d") + datas[latest_limit_up_index - 1]['bob'].strftime("%Y-%m-%d"), latest_limit_up_index - 1 else: return datas[latest_limit_up_index]["volume"], datas[latest_limit_up_index]["volume"], \ - datas[latest_limit_up_index]['bob'].strftime("%Y-%m-%d") + datas[latest_limit_up_index]['bob'].strftime("%Y-%m-%d"), latest_limit_up_index if is_new_or_near_top: # 濡傛灉鏄獊鐮村墠楂樺氨鍙栨渶澶ч噺 - for item in datas: + for i in range(len(datas)): + item = datas[i] if max_volume < item["volume"]: max_volume = item["volume"] max_volume_date = item["bob"] - return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d") + max_volume_index = i + return max_volume, max_volume, max_volume_date.strftime("%Y-%m-%d"), max_volume_index else: date = None target_volume = None @@ -72,8 +173,9 @@ max_volume = volume max_volume_date = item['bob'] # 鏄惁鏈夋定鍋� - limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) - if abs(limit_up_price - item["high"]) < 0.01: + limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(code, item["pre_close"])) + # 涓嶇湅瓒呰繃60澶╃殑娑ㄥ仠 + if abs(limit_up_price - item["high"]) < 0.001 and i <= 59: # 娑ㄥ仠 next_volume = 0 if i > 0: @@ -82,29 +184,19 @@ if volume < next_volume: volume = next_volume date = datas[i - 1]["bob"] - target_volume = (volume, date) + target_volume = (volume, date, i) break + + # 90涓氦鏄撴棩鏃犳定鍋滐紝鍙栨渶杩�30澶╁唴鐨勬渶楂橀噺浣滀负鍙傝�冮噺 if not target_volume: - target_volume = (max_volume, max_volume_date) - - # --鍒ゆ柇杩�60澶╂棤娑ㄥ仠鐨勬渶澶ч噺 - max_60_volume_info = [0, None] - # 60澶╁唴鏄惁鏈夋定鍋� - has_60_limit_up = False - for i in range(60): - if i >= len(datas): - break - item = datas[i] - volume = item["volume"] - if max_60_volume_info[0] < volume: - max_60_volume_info = [volume, item["bob"]] - limit_up_price = float(gpcode_manager.get_limit_up_price_by_preprice(item["pre_close"])) - if abs(limit_up_price - item["high"]) < 0.01: - has_60_limit_up = True - break - - if not has_60_limit_up and target_volume[0] > max_60_volume_info[0] * 3: - # 60澶╁唴鏃犳定鍋�,涓�60澶╁唴鏈�澶ч噺灏忎簬鏈�澶ч噺鐨�1/3,鍒ゆ柇涓哄湴閲�,杩斿洖杩�60涓氦鏄撴棩鐨勬渶澶ч噺 - return max_60_volume_info[0], max_60_volume_info[0], max_60_volume_info[1].strftime("%Y-%m-%d") - else: - return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d") + # --鍒ゆ柇杩�30澶╂棤娑ㄥ仠鐨勬渶澶ч噺 + max_30_volume_info = [0, None] + for i in range(30): + if i >= len(datas): + break + item = datas[i] + volume = item["volume"] + if max_30_volume_info[0] < volume: + max_30_volume_info = [volume, item["bob"], i] + target_volume = max_30_volume_info + return target_volume[0], target_volume[0], target_volume[1].strftime("%Y-%m-%d"), target_volume[2] -- Gitblit v1.8.0