From 223608bec0851c033262d39b1bd33f548fcc0866 Mon Sep 17 00:00:00 2001 From: 21in7 Date: Mon, 2 Mar 2026 16:16:25 +0900 Subject: [PATCH] refactor: remove duplicate pnl/notify from _close_position (handled by callback) Made-with: Cursor --- src/bot.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/bot.py b/src/bot.py index 73d73b7..75043ee 100644 --- a/src/bot.py +++ b/src/bot.py @@ -184,25 +184,12 @@ class TradingBot: ) async def _close_position(self, position: dict): + """포지션 청산 주문만 실행한다. PnL 기록/알림은 _on_position_closed 콜백이 담당.""" amt = abs(float(position["positionAmt"])) side = "SELL" if float(position["positionAmt"]) > 0 else "BUY" - pos_side = "LONG" if side == "SELL" else "SHORT" await self.exchange.cancel_all_orders() await self.exchange.place_order(side=side, quantity=amt, reduce_only=True) - - entry = float(position["entryPrice"]) - mark = float(position["markPrice"]) - pnl = (mark - entry) * amt if side == "SELL" else (entry - mark) * amt - - self.notifier.notify_close( - symbol=self.config.symbol, - side=pos_side, - exit_price=mark, - pnl=pnl, - ) - self.risk.record_pnl(pnl) - self.current_trade_side = None - logger.success(f"포지션 청산: PnL={pnl:.4f} USDT") + logger.info(f"청산 주문 전송 완료 (side={side}, qty={amt})") async def _close_and_reenter( self,