feat: add bounded KIS account read recovery
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""Account snapshot configuration stays opt-in and bounded."""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from trex_core.runtime.config import AccountSnapshotConfig, DaemonConfig
|
||||
|
||||
_KEYS = (
|
||||
"TREX_ACCOUNT_SNAPSHOT_ENABLED",
|
||||
"TREX_ACCOUNT_SNAPSHOT_BUY_MAX_AGE_SEC",
|
||||
"TREX_ACCOUNT_SNAPSHOT_SELL_MAX_AGE_SEC",
|
||||
"TREX_ACCOUNT_SNAPSHOT_REFRESH_INTERVAL_SEC",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _clean(monkeypatch):
|
||||
for key in _KEYS:
|
||||
monkeypatch.delenv(key, raising=False)
|
||||
monkeypatch.setenv("TREX_POSTGRESQL_DSN", "dbname=x")
|
||||
|
||||
|
||||
def test_defaults_are_disabled_and_bounded():
|
||||
config = DaemonConfig.from_env().account_snapshot
|
||||
assert config == AccountSnapshotConfig()
|
||||
assert config.enabled is False
|
||||
|
||||
|
||||
def test_env_enables_and_tunes_account_snapshot():
|
||||
import os
|
||||
|
||||
os.environ["TREX_ACCOUNT_SNAPSHOT_ENABLED"] = "true"
|
||||
os.environ["TREX_ACCOUNT_SNAPSHOT_BUY_MAX_AGE_SEC"] = "300"
|
||||
os.environ["TREX_ACCOUNT_SNAPSHOT_SELL_MAX_AGE_SEC"] = "1800"
|
||||
os.environ["TREX_ACCOUNT_SNAPSHOT_REFRESH_INTERVAL_SEC"] = "240"
|
||||
|
||||
config = DaemonConfig.from_env().account_snapshot
|
||||
assert config.enabled is True
|
||||
assert config.buy_max_age_sec == 300
|
||||
assert config.sell_max_age_sec == 1800
|
||||
assert config.refresh_interval_sec == 240
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"kwargs",
|
||||
[
|
||||
{"buy_max_age_sec": -1},
|
||||
{"buy_max_age_sec": 601, "sell_max_age_sec": 600},
|
||||
{"sell_max_age_sec": 21_601},
|
||||
{"refresh_interval_sec": 0},
|
||||
],
|
||||
)
|
||||
def test_invalid_age_or_interval_policy_is_rejected(kwargs):
|
||||
with pytest.raises(ValueError):
|
||||
AccountSnapshotConfig(**kwargs)
|
||||
@@ -322,7 +322,7 @@ class TestReportWacPath:
|
||||
return_value=mock_adapter,
|
||||
),
|
||||
):
|
||||
rc = cli.main(["report", "--json"])
|
||||
cli.main(["report", "--json"])
|
||||
j = json.loads(capsys.readouterr().out)
|
||||
# WAC 필드는 null (당일 net 99999로 채워지지 않음)
|
||||
assert j["realized_pnl_wac"] is None
|
||||
|
||||
Reference in New Issue
Block a user