Przeglądaj źródła

fix(record): 修正平仓时使用实际持仓数量而非固定交易数量

确保平仓时使用账户实际持仓数量进行交易,避免因固定交易数量导致的平仓不彻底问题
skyfffire 1 tydzień temu
rodzic
commit
95e5f13987
1 zmienionych plików z 5 dodań i 2 usunięć
  1. 5 2
      src/record/strategy.py

+ 5 - 2
src/record/strategy.py

@@ -288,11 +288,14 @@ class TradingStrategy:
             close_price = min(binance_price, lighter_price)
             is_ask = True  # 卖出
         
-        logger.info(f"开始平仓:方向={'做空' if self.position_side == 'short' else '做多'},价格={close_price}")
+        # 获取实际持仓数量
+        position_quantity = abs(int(self.current_position.position)) if self.current_position else self.trade_quantity
+        
+        logger.info(f"开始平仓:方向={'做空' if self.position_side == 'short' else '做多'},价格={close_price},数量={position_quantity}")
         
         tx_hash, error = await self.create_order_and_send_tx(
             orderbook=orderbook,
-            quantity=self.trade_quantity,
+            quantity=position_quantity,
             price=close_price,
             is_ask=is_ask,
             reduce_only=True