时间校准
This commit is contained in:
parent
e9ccc8f059
commit
8bac46aaaf
@ -977,17 +977,30 @@ class FreqaiPrimer(IStrategy):
|
||||
display_latest = display_latest.replace(tzinfo=timezone.utc)
|
||||
display_latest = display_latest.astimezone(UTC_PLUS_8)
|
||||
latest_time_str = display_latest.strftime('%H:%M:%S')
|
||||
# 计算数据新鲜度(修正时区差异)
|
||||
# 计算数据新鲜度(与交易所最新数据比较)
|
||||
latest_naive = display_latest.replace(tzinfo=None)
|
||||
current_time_utc8 = datetime.now().replace(tzinfo=UTC_PLUS_8).replace(tzinfo=None)
|
||||
data_freshness = (current_time_utc8 - latest_naive).total_seconds() / 60
|
||||
|
||||
# 修正时区差异后的判断
|
||||
if data_freshness <= 10:
|
||||
fresh_icon = "✅"
|
||||
elif data_freshness <= 30:
|
||||
fresh_icon = "⚠️"
|
||||
# 获取交易所的最新数据时间
|
||||
exchange_latest_candle, exchange_latest_date = self.get_latest_candle(
|
||||
metadata['pair'], self.timeframe, dataframe
|
||||
)
|
||||
|
||||
if exchange_latest_date:
|
||||
# 转换为UTC+8时间进行比较
|
||||
if exchange_latest_date.tzinfo is None:
|
||||
exchange_latest_date = exchange_latest_date.replace(tzinfo=timezone.utc)
|
||||
exchange_latest_utc8 = exchange_latest_date.astimezone(UTC_PLUS_8).replace(tzinfo=None)
|
||||
data_freshness = (exchange_latest_utc8 - latest_naive).total_seconds() / 60
|
||||
else:
|
||||
# 如果无法获取交易所最新时间,使用保守估计(3分钟延迟)
|
||||
data_freshness = 3.0
|
||||
|
||||
# 数据新鲜度判断
|
||||
if data_freshness <= 3: # 3分钟内为新鲜数据
|
||||
fresh_icon = "✅"
|
||||
elif data_freshness <= 10: # 3-10分钟为可接受延迟
|
||||
fresh_icon = "⚠️"
|
||||
else: # 超过10分钟为过期数据
|
||||
fresh_icon = "❌"
|
||||
self.strategy_log(
|
||||
f"[{metadata['pair']}] 数据新鲜度: {fresh_icon} {data_freshness:.1f}min | "
|
||||
@ -1002,15 +1015,28 @@ class FreqaiPrimer(IStrategy):
|
||||
display_latest = display_latest.astimezone(UTC_PLUS_8)
|
||||
latest_time_str = display_latest.strftime('%H:%M:%S')
|
||||
latest_naive = display_latest.replace(tzinfo=None)
|
||||
current_time_utc8 = datetime.now().replace(tzinfo=UTC_PLUS_8).replace(tzinfo=None)
|
||||
data_freshness = (current_time_utc8 - latest_naive).total_seconds() / 60
|
||||
|
||||
# 修正时区差异后的判断
|
||||
if data_freshness <= 10:
|
||||
fresh_icon = "✅"
|
||||
elif data_freshness <= 30:
|
||||
fresh_icon = "⚠️"
|
||||
# 获取交易所的最新数据时间
|
||||
exchange_latest_candle, exchange_latest_date = self.get_latest_candle(
|
||||
metadata['pair'], self.timeframe, dataframe
|
||||
)
|
||||
|
||||
if exchange_latest_date:
|
||||
# 转换为UTC+8时间进行比较
|
||||
if exchange_latest_date.tzinfo is None:
|
||||
exchange_latest_date = exchange_latest_date.replace(tzinfo=timezone.utc)
|
||||
exchange_latest_utc8 = exchange_latest_date.astimezone(UTC_PLUS_8).replace(tzinfo=None)
|
||||
data_freshness = (exchange_latest_utc8 - latest_naive).total_seconds() / 60
|
||||
else:
|
||||
# 如果无法获取交易所最新时间,使用保守估计(3分钟延迟)
|
||||
data_freshness = 3.0
|
||||
|
||||
# 数据新鲜度判断
|
||||
if data_freshness <= 3: # 3分钟内为新鲜数据
|
||||
fresh_icon = "✅"
|
||||
elif data_freshness <= 10: # 3-10分钟为可接受延迟
|
||||
fresh_icon = "⚠️"
|
||||
else: # 超过10分钟为过期数据
|
||||
fresh_icon = "❌"
|
||||
self.strategy_log(
|
||||
f"[{metadata['pair']}] 数据新鲜度: {fresh_icon} {data_freshness:.1f}min | "
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user