From 4212f32e8df7a955605096328e3d3a6e95cd0081 Mon Sep 17 00:00:00 2001 From: admin <admin@example.com> Date: 星期五, 01 八月 2025 14:28:10 +0800 Subject: [PATCH] 修复昨日涨停股票代码BUG --- strategy/basic_methods.py | 76 +++++++++++++++++++++++--------------- 1 files changed, 46 insertions(+), 30 deletions(-) diff --git a/strategy/basic_methods.py b/strategy/basic_methods.py index 5011736..6f1e685 100644 --- a/strategy/basic_methods.py +++ b/strategy/basic_methods.py @@ -2,13 +2,14 @@ from __future__ import print_function, absolute_import, unicode_literals import decimal + +from log_module.log import logger_common # from datetime import datetime from strategy import data_cache -from strategy.logging_config import get_logger from utils import hx_qc_value_util # 鑾峰彇logger瀹炰緥 -logger = get_logger() +logger = logger_common # 灏嗙函鏁板瓧浠g爜杞寲涓�=銆嬫帢閲戞牸寮忚偂绁ㄤ唬鐮� @@ -52,28 +53,28 @@ # print(f"open_growth=={open_growth}") -# 璁$畻鐬椂娑ㄥ箙鍏紡 -# 鍒濆鍖栧巻鍙蹭环鏍� -price_history = {} +# # 璁$畻鐬椂娑ㄥ箙鍏紡 +# # 鍒濆鍖栧巻鍙蹭环鏍� +# price_history = {} +# +# +# def calculate_growth(symbol, price): +# try: +# if symbol not in price_history: +# return 0 # 涓嶈冻涓や釜鍘嗗彶浠锋牸锛屾棤娉曡绠楁定骞� +# last_price = price_history[symbol] +# # print(f"price_history[symbol]~~~~~~~~~{price_history[symbol]}") +# if last_price != 0: +# growth = (price - last_price) / last_price * 100 # 璁$畻娑ㄥ箙鐧惧垎姣� +# return growth +# finally: +# price_history[symbol] = price +# # print(f"price======={price}") +# # print(f"price_history=={price_history}") +# # print(f"price_history[symbol]=={price_history[symbol]}") -def calculate_growth(symbol, price): - try: - if symbol not in price_history: - return 0 # 涓嶈冻涓や釜鍘嗗彶浠锋牸锛屾棤娉曡绠楁定骞� - last_price = price_history[symbol] - # print(f"price_history[symbol]~~~~~~~~~{price_history[symbol]}") - if last_price != 0: - growth = (price - last_price) / last_price * 100 # 璁$畻娑ㄥ箙鐧惧垎姣� - return growth - finally: - price_history[symbol] = price - # print(f"price======={price}") - # print(f"price_history=={price_history}") - # print(f"price_history[symbol]=={price_history[symbol]}") - - -# 璁$畻tick娑ㄥ箙鍏紡銆愪负鍗栧嚭绛栫暐鍗曠嫭鍒涘缓鍑芥暟銆� +# # 璁$畻鐬椂闂撮殧娑ㄥ箙鍏紡銆愪负鍗栧嚭绛栫暐鍗曠嫭鍒涘缓鍑芥暟銆� # 鍒濆鍖栧巻鍙蹭环鏍� history_price = {} @@ -87,6 +88,7 @@ if last_price != 0: growth = (price - last_price) / last_price * 100 # 璁$畻娑ㄥ箙鐧惧垎姣� return growth + finally: history_price[symbol] = price # print(f"price======={price}") @@ -95,20 +97,22 @@ # 璁$畻褰撴棩娑ㄥ仠浠峰嚱鏁� 褰㈠弬pre_close 瀹炲弬搴斾紶鍏� pre_close 銆恟eturn鐨勭粨鏋滈渶瑕佸皬鏁扮偣鍚庝袱浣�,鍦ㄧ涓変綅杩涜鍥涜垗浜斿叆銆� -def limit_up_price(pre_close): +def limit_up_price(pre_close, fixed=2): limit_up_price_data = decimal.Decimal(str(pre_close)) * decimal.Decimal("1.1") - limit_up_price_value = limit_up_price_data.quantize(decimal.Decimal("0.00"), decimal.ROUND_HALF_UP) + limit_up_price_value = limit_up_price_data.quantize(decimal.Decimal("0." + '0' * fixed), decimal.ROUND_HALF_UP) return float(limit_up_price_value) + # 娴嬭瘯璁$畻鐢� # limit_up = limit_up_price(15) # print(f"limit_up=={limit_up}") # 璁$畻褰撴棩璺屽仠浠峰嚱鏁� 褰㈠弬pre_close 瀹炲弬搴斾紶鍏� pre_close 銆恟eturn鐨勭粨鏋滈渶瑕佸皬鏁扮偣鍚庝袱浣峳ound鍙栨暣銆� -def limit_down_price(pre_close): +def limit_down_price(pre_close, fixed=2): limit_down_price_data = decimal.Decimal(str(pre_close)) * decimal.Decimal("0.9") - limit_down_price_value = limit_down_price_data.quantize(decimal.Decimal("0.00"), decimal.ROUND_HALF_UP) + limit_down_price_value = limit_down_price_data.quantize(decimal.Decimal("0." + '0' * fixed), decimal.ROUND_HALF_UP) return float(limit_down_price_value) + # 娴嬭瘯璁$畻鐢� # limit_down = limit_down_price(20) # print(f"limit_up=={limit_down}") @@ -147,6 +151,7 @@ frying_plate_day_min_index = next((i for i, d in enumerate(k_line_data[0:7]) if 'attribute' in d and d['attribute'] in data_cache.frying_plate_type), None) # 濡傛灉娌℃湁鎵惧埌锛岃繑鍥濶one # 鎵惧埌鏈�杩�7鏃ュ唴鐨勬湁璺屽仠鐨勫簭鍙� limit_down_day_min_index = next((i for i, d in enumerate(k_line_data[0:7]) if 'attribute' in d and d['attribute'] in data_cache.limit_down_type), None) # 濡傛灉娌℃湁鎵惧埌锛岃繑鍥濶one + # 鏈�杩戠殑娑ㄥ仠搴忓彿瀛樺湪 涓� 闈炴槰鏃� if limit_up_day_min_index is not None and limit_up_day_min_index > 0: # 寮�鐩樹环 < 娑ㄥ仠褰撴棩鏈�楂樹环 <= 浠婃棩娑ㄥ仠浠� @@ -182,7 +187,7 @@ def secure_volume(now_date_time): # 瀹氫箟鏃堕棿娈电殑寮�濮嬪拰缁撴潫鏃堕棿锛堜娇鐢ㄥ瓧绗︿覆鏍煎紡锛� time_slots = [ - (("09:30:00", "09:30:30"), 0.05), + (("09:30:00", "09:30:30"), 0.04), (("09:30:30", "09:31:00"), 0.08), (("09:31:00", "09:31:30"), 0.1), (("09:31:30", "09:32:00"), 0.15), @@ -205,9 +210,14 @@ return 0 -# 绀轰緥浣跨敤 -# now = datetime.now() -# print(f"secure_volume(now)=={secure_volume(now)}") +# 鍏呭垎浜ゆ槗閲忓叕寮� 鐢ㄤ簬璁$畻鏃ュ唴娑ㄥ箙娈电悊璁虹殑瀹夊叏浜ゆ槗閲忓�� +def sufficient_volume(current_volume, yesterday_volume, today_growth): + if today_growth > 0 and round(current_volume / yesterday_volume, 2) >= 0.01: + if current_volume > yesterday_volume * (today_growth/10) * 0.3: + return True + else: + return False + # 璁$畻 濮斾拱鍜屽鍗栫殑姣斾緥鍑芥暟(鑾峰彇涔扮洏寮哄害鏁版嵁)銆愭帢閲戞暟鎹粨鏋勩�� def buying_and_selling_ratio(current_quotes): @@ -251,3 +261,9 @@ else: buying_ratio = 0.01 return buying_ratio + + +# 缁熻鏈夋剰涔拌偂绁ㄥ嚭鐜版鏁板嚱鏁� +def count_willing_buy_times(sec_name): + willing_buy_times = data_cache.willing_buy_list.count(sec_name) + return willing_buy_times \ No newline at end of file -- Gitblit v1.8.0