34 lines
2.0 KiB
Python
34 lines
2.0 KiB
Python
from pathlib import Path
|
|
|
|
from poly_updown.analytics import load_recent_market_stats
|
|
|
|
|
|
def test_load_recent_market_stats_groups_samples(tmp_path: Path) -> None:
|
|
path = tmp_path / "samples.jsonl"
|
|
path.write_text(
|
|
"\n".join(
|
|
[
|
|
'{"recorded_at":"2026-05-21T15:20:01Z","benchmark_source":"rtds_boundary","start_boundary":{"price":100,"offset_ms":500},"market":{"event_slug":"m1","title":"M1","start_time":"s","end_time":"e","seconds_remaining":120,"price_to_beat":100},"tick":{"source":"polymarket_rtds_chainlink","price":99},"books":{"up":{"asks":[{"price":0.52,"size":100}]},"down":{"asks":[{"price":0.48,"size":100}]}},"edge":{"fair_up":0.55,"buy_up_edge":0.01,"buy_down_edge":0.02,"up_ask":0.52,"down_ask":0.48}}',
|
|
'{"recorded_at":"2026-05-21T15:20:02Z","benchmark_source":"rtds_boundary","start_boundary":{"price":100,"offset_ms":500},"market":{"event_slug":"m1","title":"M1","start_time":"s","end_time":"e","seconds_remaining":50,"price_to_beat":100},"tick":{"source":"polymarket_rtds_chainlink","price":101},"books":{"up":{"asks":[{"price":0.52,"size":100}]},"down":{"asks":[{"price":0.48,"size":100}]}},"edge":{"fair_up":0.58,"buy_up_edge":0.04,"buy_down_edge":-0.01,"up_ask":0.52,"down_ask":0.48}}',
|
|
]
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
result = load_recent_market_stats(path, edge_threshold=0.03)
|
|
|
|
market = result["markets"][0]
|
|
assert result["total_samples"] == 2
|
|
assert result["trusted_samples"] == 2
|
|
assert market["slug"] == "m1"
|
|
assert market["max_buy_up_edge"] == 0.04
|
|
assert market["max_last60_up_edge"] == 0.04
|
|
assert market["up_signals"] == 1
|
|
assert market["final_direction"] == "up"
|
|
assert market["paper_trades"][0]["side"] == "up"
|
|
assert market["paper_trades"][0]["won"] is True
|
|
assert market["paper_trades"][0]["filled_notional"] == 25.0
|
|
assert market["paper_trades"][0]["levels_used"] == 1
|
|
assert result["paper"]["trades"] == 1
|
|
assert result["paper"]["wins"] == 1
|