Tardis.dev Python Client
The `tardis-client` library provides a Python interface for accessing historical tick-level cryptocurrency market data from tardis.dev. It facilitates replaying historical data via an asynchronous generator and offers local file-based caching. The current version is 1.4.2. **Note: This package is deprecated and has been replaced by the `tardis-dev` package, where all new development is focused.**
Common errors
-
ConnectionResetError: [Errno 54] Connection reset by peer OR EOFError: Read up to 0 bytes from peer
cause These errors often occur when the Python `asyncio` event loop is blocked by synchronous (blocking) I/O operations, such as writing to files, preventing the network connection from being properly maintained.fixReplace blocking file operations with their asynchronous equivalents (e.g., using `aiofiles`) or ensure I/O is offloaded to a separate thread/process to keep the `asyncio` event loop responsive. Clear the `.tardis-cache` directory. -
HTTP status 401 Unauthorized
cause The API key provided is either missing, invalid, or does not have sufficient permissions for the requested data. For full historical data, an API key is always required.fixEnsure you have a valid Tardis.dev API key. Pass it correctly to the `TardisClient` constructor using the `api_key` argument, or set it as the `TARDIS_API_KEY` environment variable. Verify the API key's permissions on the Tardis.dev website.
Warnings
- breaking The `tardis-client` package is deprecated and frozen. No new features will be added, and future Python development continues under the `tardis-dev` package. Existing users should migrate.
- gotcha Access to full historical data requires a Tardis.dev API key. Without one, only the first day of each month is accessible.
- gotcha Performing blocking I/O operations (e.g., synchronous file writes) within the `asyncio` event loop used by `tardis-client` can cause `ConnectionResetError` or `EOFError` due to the event loop being blocked, leading to network connection timeouts.
- gotcha The local file cache (`<os.tmpdir>/.tardis-cache` by default) can grow significantly, consuming disk space, especially during large historical data backfills.
Install
-
pip install tardis-client -
pip install tardis-dev
Imports
- TardisClient
from tardis_dev import TardisClient
from tardis_client import TardisClient
- Channel
from tardis_dev.client import Channel
from tardis_client import Channel
Quickstart
import asyncio
import os
from tardis_client import TardisClient, Channel
async def replay_data():
api_key = os.environ.get('TARDIS_API_KEY', '')
# Note: For full historical access, an API key is required.
# Without an API key, only the first day of each month is accessible.
# The cache_dir is optional; default is os.tmpdir/.tardis-cache.
tardis_client = TardisClient(api_key=api_key, cache_dir="./tardis_cache")
print("Replaying BitMEX trades and order book for 2019-06-01...")
messages = tardis_client.replay(
exchange="bitmex",
from_date="2019-06-01",
to_date="2019-06-02", # Non-inclusive end date
filters=[
Channel(name="trade", symbols=["XBTUSD", "ETHUSD"]),
Channel("orderBookL2", ["XBTUSD"])
],
)
message_count = 0
async for local_timestamp, message in messages:
# local_timestamp is a Python datetime object
# message is the raw message object from the exchange real-time stream
if message_count < 5: # Print first 5 messages as an example
print(f"[{local_timestamp}] {message['symbol']}: {message['data_type']}")
message_count += 1
print(f"\nFinished replaying. Total messages received: {message_count}")
# Optionally clear the cache
# tardis_client.clear_cache()
if __name__ == "__main__":
# Set your API key as an environment variable or pass it directly
# os.environ['TARDIS_API_KEY'] = 'YOUR_TARDIS_API_KEY'
asyncio.run(replay_data())