admin
2025-04-08 70b51a2636858fb8cfbf39d3764d88d07286d8ad
strategy/basic_methods.py
@@ -53,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 = {}
@@ -148,6 +148,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)  # 如果没有找到,返回None
    # 找到最近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)  # 如果没有找到,返回None
    # 最近的涨停序号存在 且 非昨日
    if limit_up_day_min_index is not None and limit_up_day_min_index > 0:
        # 开盘价 < 涨停当日最高价 <= 今日涨停价