| | |
| | | # 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 = {} |
| | | |