fix: prevent OI API failure from corrupting _prev_oi state and ML features

- _fetch_market_microstructure: oi_val > 0 체크 후에만 _calc_oi_change 호출하여
  API 실패(None/Exception) 시 0.0으로 폴백하고 _prev_oi 상태 오염 방지
- README: ML 피처 수 오기재 수정 (25개 → 23개)
- tests: _calc_oi_change 첫 캔들 및 API 실패 시 상태 보존 유닛 테스트 추가

Made-with: Cursor
This commit is contained in:
21in7
2026-03-02 14:01:50 +09:00
parent b57b00051a
commit aa52047f14
3 changed files with 29 additions and 5 deletions

View File

@@ -58,11 +58,13 @@ class TradingBot:
self.exchange.get_funding_rate(),
return_exceptions=True,
)
oi_float = float(oi_val) if isinstance(oi_val, (int, float)) else 0.0
# None(API 실패) 또는 Exception이면 _calc_oi_change를 호출하지 않고 0.0 반환
if isinstance(oi_val, (int, float)) and oi_val > 0:
oi_change = self._calc_oi_change(float(oi_val))
else:
oi_change = 0.0
fr_float = float(fr_val) if isinstance(fr_val, (int, float)) else 0.0
oi_change = self._calc_oi_change(oi_float)
logger.debug(f"OI={oi_float:.0f}, OI변화율={oi_change:.6f}, 펀딩비={fr_float:.6f}")
logger.debug(f"OI={oi_val}, OI변화율={oi_change:.6f}, 펀딩비={fr_float:.6f}")
return oi_change, fr_float
def _calc_oi_change(self, current_oi: float) -> float: