fix: resolve critical/important bugs from code review (#1,#2,#4,#5,#6,#8)

- #1: OI division by zero — already fixed (prev_oi == 0.0 guard exists)
- #2: cumulative trade count used max() instead of sum(), breaking ML trigger
- #4: fetch_history API calls now retry 3x with exponential backoff
- #5: parquet upsert now deduplicates timestamps before sort
- #6: record_pnl() is now async with Lock for multi-symbol safety
- #8: exit_price=0.0 skips close handling with warning log

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
21in7
2026-03-07 03:06:48 +09:00
parent 0a8748913e
commit 60510c026b
5 changed files with 31 additions and 11 deletions

View File

@@ -52,9 +52,10 @@ class RiskManager:
self.daily_pnl += pnl
logger.info(f"포지션 종료: {symbol}, PnL={pnl:+.4f}, 누적={self.daily_pnl:+.4f}")
def record_pnl(self, pnl: float):
self.daily_pnl += pnl
logger.info(f"오늘 누적 PnL: {self.daily_pnl:.4f} USDT")
async def record_pnl(self, pnl: float):
async with self._lock:
self.daily_pnl += pnl
logger.info(f"오늘 누적 PnL: {self.daily_pnl:.4f} USDT")
def reset_daily(self):
"""매일 자정 초기화"""

View File

@@ -94,6 +94,13 @@ class UserDataStream:
net_pnl = realized_pnl - commission
exit_price = float(order.get("ap", "0"))
if exit_price == 0.0:
logger.warning(
f"[{self._symbol}] 청산 이벤트에서 exit_price=0.0 — "
f"ap 필드 누락 가능. 청산 처리 스킵 (rp={realized_pnl:+.4f})"
)
return
if order_type == "TAKE_PROFIT_MARKET":
close_reason = "TP"
elif order_type == "STOP_MARKET":