Tardis.dev Python Client

4.0.0 · active · verified Thu Apr 16

The `tardis-dev` Python client (version 4.0.0) provides convenient access to tick-level historical cryptocurrency market data in exchange-native format. It focuses on two primary workflows: replaying historical market data and downloading historical market data as CSV files. The library is actively maintained with regular updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates both replaying historical market data and downloading CSV datasets. An API key is typically required for full access, though free samples may be available without one. Replay data is streamed asynchronously, while CSV datasets are downloaded to a specified directory.

import asyncio
import os
from tardis_dev import Channel, replay

async def main():
    api_key = os.environ.get('TARDIS_API_KEY', '') # Optional for some free tiers
    if not api_key:
        print("Warning: TARDIS_API_KEY not set. Data may be limited to free samples.")
    
    print("Replaying historical trade and depth data...")
    async for local_timestamp, message in replay(
        exchange="binance",
        from_date="2024-03-01",
        to_date="2024-03-02",
        filters=[Channel("trade", ["btcusdt"]), Channel("depth", ["btcusdt"])],
        api_key=api_key,
    ):
        print(f"{local_timestamp}: {message['type']} for {message.get('symbol', 'N/A')}")
        # Process first 5 messages and break for brevity
        if main.counter < 5:
            main.counter += 1
        else:
            break

    print("\nDownloading historical CSV datasets...")
    from tardis_dev import download_datasets
    try:
        download_datasets(
            exchange="binance",
            data_types=["trades"],
            symbols=["BTCUSDT"], # Note: Symbols here are typically uppercase for datasets API
            from_date="2024-03-01",
            to_date="2024-03-02",
            api_key=api_key,
            download_dir="./tardis_datasets_quickstart",
            skip_if_exists=True
        )
        print("Download initiated. Check ./tardis_datasets_quickstart directory.")
    except Exception as e:
        print(f"Could not initiate download (API key issue or no data?): {e}")

main.counter = 0
asyncio.run(main())

view raw JSON →