Critical: - #2: Add _entry_lock in RiskManager to serialize concurrent entry (balance race) - #3: Add startTime to get_recent_income + record _entry_time_ms (SYNC PnL fix) Important: - #1: Add threading.Lock + _run_api() helper for thread-safe Client access - #4: Convert reset_daily to async with lock - #8: Add 24h TTL to exchange_info_cache Minor: - #7: Remove duplicate Indicators creation in _open_position (use ATR directly) - #11: Add input validation for LEVERAGE, MARGIN ratios, ML_THRESHOLD - #12: Replace hardcoded corr[0]/corr[1] with dict-based dynamic access - #14: Add fillna(0.0) to LightGBM path for NaN consistency with ONNX Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
import os
|
|
import pytest
|
|
from src.config import Config
|
|
|
|
|
|
def test_config_loads_symbol():
|
|
os.environ["SYMBOL"] = "XRPUSDT"
|
|
os.environ["LEVERAGE"] = "10"
|
|
cfg = Config()
|
|
assert cfg.symbol == "XRPUSDT"
|
|
assert cfg.leverage == 10
|
|
|
|
|
|
def test_config_dynamic_margin_params():
|
|
os.environ["MARGIN_MAX_RATIO"] = "0.50"
|
|
os.environ["MARGIN_MIN_RATIO"] = "0.20"
|
|
os.environ["MARGIN_DECAY_RATE"] = "0.0006"
|
|
cfg = Config()
|
|
assert cfg.margin_max_ratio == 0.50
|
|
assert cfg.margin_min_ratio == 0.20
|
|
assert cfg.margin_decay_rate == 0.0006
|
|
|
|
|
|
def test_config_loads_symbols_list():
|
|
"""SYMBOLS 환경변수로 쉼표 구분 리스트를 로드한다."""
|
|
os.environ["SYMBOLS"] = "XRPUSDT,TRXUSDT,DOGEUSDT"
|
|
os.environ.pop("SYMBOL", None)
|
|
cfg = Config()
|
|
assert cfg.symbols == ["XRPUSDT", "TRXUSDT", "DOGEUSDT"]
|
|
|
|
|
|
def test_config_fallback_to_symbol():
|
|
"""SYMBOLS 미설정 시 SYMBOL에서 1개짜리 리스트로 변환한다."""
|
|
os.environ.pop("SYMBOLS", None)
|
|
os.environ["SYMBOL"] = "XRPUSDT"
|
|
cfg = Config()
|
|
assert cfg.symbols == ["XRPUSDT"]
|
|
|
|
|
|
def test_config_correlation_symbols():
|
|
"""상관관계 심볼 로드."""
|
|
os.environ["CORRELATION_SYMBOLS"] = "BTCUSDT,ETHUSDT"
|
|
cfg = Config()
|
|
assert cfg.correlation_symbols == ["BTCUSDT", "ETHUSDT"]
|
|
|
|
|
|
def test_config_max_same_direction_default():
|
|
"""동일 방향 최대 수 기본값 2."""
|
|
cfg = Config()
|
|
assert cfg.max_same_direction == 2
|
|
|
|
|
|
def test_config_rejects_zero_leverage():
|
|
"""LEVERAGE=0은 ValueError."""
|
|
os.environ["LEVERAGE"] = "0"
|
|
with pytest.raises(ValueError, match="LEVERAGE"):
|
|
Config()
|
|
os.environ["LEVERAGE"] = "10" # 복원
|
|
|
|
|
|
def test_config_rejects_invalid_margin_ratio():
|
|
"""MARGIN_MAX_RATIO가 0이면 ValueError."""
|
|
os.environ["MARGIN_MAX_RATIO"] = "0"
|
|
with pytest.raises(ValueError, match="MARGIN_MAX_RATIO"):
|
|
Config()
|
|
os.environ["MARGIN_MAX_RATIO"] = "0.50" # 복원
|
|
|
|
|
|
def test_config_rejects_min_gt_max_margin():
|
|
"""MARGIN_MIN > MAX이면 ValueError."""
|
|
os.environ["MARGIN_MIN_RATIO"] = "0.80"
|
|
os.environ["MARGIN_MAX_RATIO"] = "0.50"
|
|
with pytest.raises(ValueError, match="MARGIN_MIN_RATIO"):
|
|
Config()
|
|
os.environ["MARGIN_MIN_RATIO"] = "0.20" # 복원
|