Tardis.dev Python Client

1.4.2 · deprecated · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the deprecated `tardis-client` to replay historical market data for BitMEX. It fetches trades for 'XBTUSD' and 'ETHUSD', and Level 2 order book data for 'XBTUSD' for a specific date range. An API key is typically required for full access to historical data.

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())

view raw JSON →