diff --git a/backend/api/routes/trades.py b/backend/api/routes/trades.py index d655483..9d9b60c 100644 --- a/backend/api/routes/trades.py +++ b/backend/api/routes/trades.py @@ -30,18 +30,28 @@ def get_date_range(period: Optional[str] = None): Returns: (start_date, end_date) 元组,格式为 'YYYY-MM-DD HH:MM:SS' """ + # 使用当前时间作为结束时间,确保包含最新的单子 end_date = datetime.now() if period == '1d': - start_date = end_date - timedelta(days=1) + # 最近1天:从今天00:00:00到现在(确保包含今天的所有单子) + # 这样即使查询时已经是晚上,也能查到今天早上开的单子 + start_date = end_date.replace(hour=0, minute=0, second=0, microsecond=0) elif period == '7d': - start_date = end_date - timedelta(days=7) + # 最近7天:从7天前00:00:00到现在 + start_date = (end_date - timedelta(days=7)).replace(hour=0, minute=0, second=0, microsecond=0) elif period == '30d': - start_date = end_date - timedelta(days=30) + # 最近30天:从30天前00:00:00到现在 + start_date = (end_date - timedelta(days=30)).replace(hour=0, minute=0, second=0, microsecond=0) else: return None, None - return start_date.strftime('%Y-%m-%d 00:00:00'), end_date.strftime('%Y-%m-%d %H:%M:%S') + # 开始时间:使用计算出的开始日期的00:00:00 + start_date_str = start_date.strftime('%Y-%m-%d %H:%M:%S') + # 结束时间:使用当前时间,确保包含最新单子 + end_date_str = end_date.strftime('%Y-%m-%d %H:%M:%S') + + return start_date_str, end_date_str @router.get("")