Replaying Historical Data
HTTP and WebSocket replay endpoints with options and response formats
Exchange-native market data APIs
HTTP GET /replay?options={options}
HTTP GET /replay?options={options}import asyncio
import aiohttp
import json
import urllib.parse
async def replay_via_tardis_machine(replay_options):
timeout = aiohttp.ClientTimeout(total=0)
async with aiohttp.ClientSession(timeout=timeout) as session:
# url encode as json object options
encoded_options = urllib.parse.quote_plus(json.dumps(replay_options))
# assumes tardis-machine HTTP API running on localhost:8000
url = f"http://localhost:8000/replay?options={encoded_options}"
async with session.get(url) as response:
# otherwise we may get line to long errors
response.content._high_water = 100_000_000
# returned data is in NDJSON format http://ndjson.org/
# each line is separate message JSON encoded
async for line in response.content:
yield line
async def main():
lines = replay_via_tardis_machine(
{
"exchange": "binance",
"from": "2024-03-01",
"to": "2024-03-02",
"filters": [
{"channel": "trade", "symbols": ["btcusdt"]},
{"channel": "depth", "symbols": ["btcusdt"]},
],
}
)
async for line in lines:
message = json.loads(line)
# localTimestamp string marks timestamp when message was received
# message is a message dict as provided by exchange real-time stream
print(message["localTimestamp"], message["message"])
asyncio.run(main())Replay options
name
type
default
description
Response format
WebSocket /ws-replay?exchange={exchange}&from={fromDate}&to={toDate}
WebSocket /ws-replay?exchange={exchange}&from={fromDate}&to={toDate}Query string params
name
type
default
description
Normalized market data APIs
HTTP GET /replay-normalized?options={options}
HTTP GET /replay-normalized?options={options}Replay normalized options
name
type
default
description
Response format & sample messages
WebSocket /ws-replay-normalized?options={options}
WebSocket /ws-replay-normalized?options={options}Replay normalized options
name
type
default
description
Response format & sample messages
Last updated
Was this helpful?