Keep bot operational when forecast model is unavailable

This commit is contained in:
Курнат Андрей
2026-07-13 11:57:25 +03:00
parent da53483164
commit 668e606ee2
22 changed files with 706 additions and 73 deletions
+28
View File
@@ -2,9 +2,11 @@ from __future__ import annotations
import json
from datetime import timedelta
from pathlib import Path
from crypto_spot_bot.models import Signal, utc_now
from crypto_spot_bot.storage import MAX_SIGNAL_DIAGNOSTICS_BYTES, PRUNE_BATCH_SIZE, Storage
from tools.compact_runtime_db import compact_database
def test_hold_sampling_is_independent_for_each_reason_and_diagnostics_are_bounded(tmp_path) -> None:
@@ -58,3 +60,29 @@ def test_prune_deletes_only_one_bounded_batch_per_table(tmp_path) -> None:
assert deleted["signals"] == PRUNE_BATCH_SIZE
assert len(storage.recent_signals(PRUNE_BATCH_SIZE + 10)) == 5
def test_runtime_compaction_preserves_durable_state_and_bounds_telemetry(tmp_path) -> None:
database = tmp_path / "tradebot.sqlite3"
storage = Storage(database)
for index in range(10):
storage.insert_signal(
Signal("BTCUSDT", "BUY", 0.8, f"signal-{index}"),
hold_sample_seconds=0,
)
storage.set_runtime("active", {"value": 1})
result = compact_database(
database,
recent_rows={"signals": 3, "equity": 0, "events": 0, "llm_advice": 0},
)
compacted = Storage(database)
assert [row["reason"] for row in compacted.recent_signals(10)] == [
"signal-9",
"signal-8",
"signal-7",
]
assert compacted.get_runtime("active") == {"value": 1}
assert Path(result["backup"]).is_file()
assert result["rows"]["signals"] == 3