From a884ed13ad5ada4dc7a7e2db5f0971a9f6c07e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Mon, 16 Feb 2026 10:46:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AE=B0=E5=BD=95=E4=B8=8E?= =?UTF-8?q?=E5=B8=81=E5=AE=89=E7=9A=84=E4=B8=80=E8=87=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/api/routes/trades.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/api/routes/trades.py b/backend/api/routes/trades.py index 229df11..7d0e9ea 100644 --- a/backend/api/routes/trades.py +++ b/backend/api/routes/trades.py @@ -79,6 +79,7 @@ async def get_trades( trade_type: Optional[str] = Query(None, description="交易类型筛选: 'buy', 'sell'"), exit_reason: Optional[str] = Query(None, description="平仓原因筛选: 'stop_loss', 'take_profit', 'trailing_stop', 'manual', 'sync'"), status: Optional[str] = Query(None, description="状态筛选: 'open', 'closed', 'cancelled'"), + include_sync: bool = Query(False, description="是否包含 entry_reason 为 sync_recovered 的历史同步单"), limit: int = Query(100, ge=1, le=1000, description="返回记录数限制"), ): """ @@ -126,7 +127,9 @@ async def get_trades( logger.warning(f"无效的结束日期格式: {end_date}") trades = Trade.get_all(start_timestamp, end_timestamp, symbol, status, trade_type, exit_reason, account_id=account_id) - logger.info(f"查询到 {len(trades)} 条交易记录") + if not include_sync: + trades = [t for t in trades if (t.get("entry_reason") or "") != "sync_recovered"] + logger.info(f"查询到 {len(trades)} 条交易记录(include_sync={include_sync})") # 格式化交易记录,添加平仓类型的中文显示 formatted_trades = [] @@ -184,6 +187,7 @@ async def get_trade_stats( end_date: Optional[str] = Query(None, description="结束日期 (YYYY-MM-DD 或 YYYY-MM-DD HH:MM:SS)"), period: Optional[str] = Query(None, description="快速时间段筛选: '1d', '7d', '30d', 'today', 'week', 'month'"), symbol: Optional[str] = Query(None, description="交易对筛选"), + include_sync: bool = Query(False, description="是否包含 entry_reason 为 sync_recovered 的历史同步单"), ): """获取交易统计""" try: @@ -221,6 +225,8 @@ async def get_trade_stats( logger.warning(f"无效的结束日期格式: {end_date}") trades = Trade.get_all(start_timestamp, end_timestamp, symbol, None, account_id=account_id) + if not include_sync: + trades = [t for t in trades if (t.get("entry_reason") or "") != "sync_recovered"] closed_trades = [t for t in trades if t['status'] == 'closed'] # 辅助函数:计算净盈亏(优先使用 realized_pnl - commission)