feat(state): dvol_history multi-asset (ETH+BTC) + backfill ETH legacy rows
Migration 0006 promuove dvol_history da PK=(timestamp) mono-ETH a PK=(timestamp, asset), rinomina eth_spot -> spot, e backfilla con asset='ETH' le righe storiche. market_snapshot_cycle ora scrive sia per ETH che per BTC; monitor_cycle resta ETH-only via WHERE asset='ETH' nella lookup di return_4h. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -277,15 +277,46 @@ def test_record_dvol_snapshot_replaces_on_duplicate_timestamp(
|
||||
ts = datetime(2026, 4, 27, 14, 0, tzinfo=UTC)
|
||||
with transaction(conn):
|
||||
repo.record_dvol_snapshot(
|
||||
conn, DvolSnapshot(timestamp=ts, dvol=Decimal("50"), eth_spot=Decimal("3000"))
|
||||
conn,
|
||||
DvolSnapshot(
|
||||
timestamp=ts, asset="ETH", dvol=Decimal("50"), spot=Decimal("3000")
|
||||
),
|
||||
)
|
||||
repo.record_dvol_snapshot(
|
||||
conn, DvolSnapshot(timestamp=ts, dvol=Decimal("55"), eth_spot=Decimal("3050"))
|
||||
conn,
|
||||
DvolSnapshot(
|
||||
timestamp=ts, asset="ETH", dvol=Decimal("55"), spot=Decimal("3050")
|
||||
),
|
||||
)
|
||||
rows = conn.execute("SELECT COUNT(*) FROM dvol_history").fetchone()
|
||||
assert rows[0] == 1
|
||||
|
||||
|
||||
def test_record_dvol_snapshot_keeps_assets_distinct_on_same_timestamp(
|
||||
conn: sqlite3.Connection, repo: Repository
|
||||
) -> None:
|
||||
ts = datetime(2026, 4, 27, 14, 0, tzinfo=UTC)
|
||||
with transaction(conn):
|
||||
repo.record_dvol_snapshot(
|
||||
conn,
|
||||
DvolSnapshot(
|
||||
timestamp=ts, asset="ETH", dvol=Decimal("50"), spot=Decimal("3000")
|
||||
),
|
||||
)
|
||||
repo.record_dvol_snapshot(
|
||||
conn,
|
||||
DvolSnapshot(
|
||||
timestamp=ts, asset="BTC", dvol=Decimal("45"), spot=Decimal("65000")
|
||||
),
|
||||
)
|
||||
rows = conn.execute(
|
||||
"SELECT asset, dvol, spot FROM dvol_history ORDER BY asset"
|
||||
).fetchall()
|
||||
assert [r["asset"] for r in rows] == ["BTC", "ETH"]
|
||||
assert Decimal(str(rows[0]["spot"])) == Decimal("65000")
|
||||
assert Decimal(str(rows[1]["spot"])) == Decimal("3000")
|
||||
|
||||
|
||||
def test_manual_action_enqueue_consume_cycle(
|
||||
conn: sqlite3.Connection, repo: Repository
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user