31 lines
817 B
Python
31 lines
817 B
Python
import json
|
|
|
|
import pytest
|
|
|
|
from app.bars.models import Bar, Timeframe
|
|
from app.market.recorder import Recorder
|
|
from app.market.replay import ReplaySource
|
|
|
|
|
|
def sample_bars():
|
|
return [
|
|
Bar(Timeframe.M1, 100 + i * 60, 1, 2, 0.5, 1.5, 10, True, "ES=F", "yahoo")
|
|
for i in range(2)
|
|
]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_recorded_tape_replays_identically(tmp_path):
|
|
expected = sample_bars()
|
|
|
|
async def source():
|
|
for bar in expected:
|
|
yield bar
|
|
|
|
tape = tmp_path / "tape.jsonl"
|
|
recorded = [bar async for bar in Recorder(tape).record(source())]
|
|
replayed = [bar async for bar in ReplaySource(tape).stream("ES=F")]
|
|
|
|
assert recorded == expected
|
|
assert replayed == expected
|
|
assert len([json.loads(line) for line in tape.read_text().splitlines()]) == 2
|