From ed0c6754e0c9785491eb8ee3e92a9ad1ef7c091a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Thu, 26 Feb 2026 17:40:08 +0800 Subject: [PATCH] 1 --- trading_system/position_manager.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/trading_system/position_manager.py b/trading_system/position_manager.py index 2249a68..fca9919 100644 --- a/trading_system/position_manager.py +++ b/trading_system/position_manager.py @@ -929,27 +929,27 @@ class PositionManager: fallback_client_order_id = (order.get("clientOrderId") if order else None) or client_order_id logger.info(f"[DB] {symbol} 无 pending 记录,新建 open 记录 client_order_id={fallback_client_order_id!r} entry_order_id={entry_order_id}") # 如果 REST 已获取到 entry_order_id,直接写入;否则留空,等待 WS 推送或后续同步补全 - trade_id = Trade.create( - symbol=symbol, - side=side, + trade_id = Trade.create( + symbol=symbol, + side=side, quantity=quantity, entry_price=entry_price, - leverage=leverage, - entry_reason=entry_reason, + leverage=leverage, + entry_reason=entry_reason, entry_order_id=entry_order_id, # REST 已获取则直接写入 client_order_id=fallback_client_order_id, - stop_loss_price=stop_loss_price, - take_profit_price=take_profit_price, - take_profit_1=take_profit_1, - take_profit_2=take_profit_2, - atr=atr, - notional_usdt=notional_usdt, - margin_usdt=margin_usdt, + stop_loss_price=stop_loss_price, + take_profit_price=take_profit_price, + take_profit_1=take_profit_1, + take_profit_2=take_profit_2, + atr=atr, + notional_usdt=notional_usdt, + margin_usdt=margin_usdt, entry_context=entry_context, account_id=self.account_id, - ) + ) if entry_order_id: - logger.info(f"✓ {symbol} 交易记录已保存到数据库 (ID: {trade_id}, 订单号: {entry_order_id}, 成交价: {entry_price:.4f}, 成交数量: {quantity:.4f})") + logger.info(f"✓ {symbol} 交易记录已保存到数据库 (ID: {trade_id}, 订单号: {entry_order_id}, 成交价: {entry_price:.4f}, 成交数量: {quantity:.4f})") else: logger.warning(f"⚠ {symbol} 交易记录已保存但 entry_order_id 为空 (ID: {trade_id}),等待 WS 推送或后续同步补全") # 如果有 client_order_id,尝试通过 REST 查询订单号补全