admin
2025-03-24 02166225b34a7ec2c41dc8eda77c431465b8d9dd
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
# 将纯数字代码转化为=》掘金格式股票代码
@@ -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 = {}