Skip to main content

Python client for tardis.dev - historical tick-level cryptocurrency market data replay API.

Project description

tardis-client

PyPi Python Code style: black

Python client for tardis.dev - historical tick-level cryptocurrency market data replay API. Provides fast, high level and developer friendly wrapper for more low level HTTP API with local file based caching build in.

Installation

Requires Python 3.7.0+ installed.

pip install tardis-client

Usage

import asyncio
from tardis_client import TardisClient, Channel

async def replay():
    tardis_client = TardisClient()

    # replay method returns Async Generator
    # https://rickyhan.com/jekyll/update/2018/01/27/python36.html
    messages = tardis_client.replay(
        exchange="bitmex",
        from_date="2019-06-01",
        to_date="2019-06-02",
        filters=[Channel(name="trade", symbols=["XBTUSD","ETHUSD"]), Channel("orderBookL2", ["XBTUSD"])],
    )

    # this will print all trades and orderBookL2 messages for XBTUSD
    # and all trades for ETHUSD for bitmex exchange
    # between 2019-06-01T00:00:00.000Z and 2019-06-02T00:00:00.000Z (whole first day of June 2019)
    async for local_timestamp, message in messages:
        # local timestamp is a Python datetime that marks timestamp when given message has been received
        # message is a message object as provided by exchange real-time stream
        print(message)

asyncio.run(replay())

Try on repl.it

API

tardis-client package provides TardisClient and Channel classes.

from tardis_client import TardisClient, Channel

TardisClient

Optional client constructor parameters.

name type default value description
api_key (optional) string "" optional string containing API key for tardis.dev API. If not provided only first day of each month of data is accessible (free access)
cache_dir (optional) string <os.tmpdir>/.tardis-cache optional string with path to local dir that will be used as cache location. If not provided default temp dir for given OS will be used.

Example:

# creates new client instance with access only to sample data (first day of each month)
tardis_client = TardisClient()

# creates new client with access to all data for given API key
tardis_client = TardisClient(api_key="YOUR_API_KEY")

# creates new client with custom cache dir
tardis_client = TardisClient(cache_dir="./cache")
  • tardis_client.clear_cache()

    Removes local file cache dir and it's contents.

    Example:

    tardis_client = TardisClient()
    
    tardis_client.clear_cache()
    
  • tardis_client.replay(exchange, from_date, to_date, filters=[])

    Replays historical market data messages for given replay arguments.

    Returns Async Generator with named tuples (namedtuple("Response", ["local_timestamp", "message"])).

    • local_timestamp is a Python datetime object specyfying when message has been received from the exchange real-time data feed.

    • message is Python dict with parsed JSON that has exactly the same format as message provided by particular exchange's real-time data feed.

      replay method parameters:

      name type default value description
      exchange string - requested exchange name - see allowed exchanges list
      from_date string - requested UTC start date of data feed - valid ISO date string, eg: 2019-04-05 or 2019-05-05T00:00:00
      to_date string - requested UTC end date of data feed - valid ISO date string, eg: 2019-04-05 or 2019-05-05T00:00:00
      filters (optional) List[Channel] [] optional filters of requested data feed. Use /exchanges/:exchange API call to get allowed channel names and symbols for requested exchange
      Channel class

      Channel class constructor parameters.

      name type description
      name string Use /exchanges/:exchange API call to get allowed channel names and symbols for requested exchange
      symbols List[string] Use /exchanges/:exchange API call to get allowed channel names and symbols for requested exchange
      Channel(name="trade", symbols=["XBTUSD","ETHUSD"])
      Channel("orderBookL2", ["XBTUSD"])
      

FAQ

How to debug it if something went wrong?

tardis-client uses Python logging on DEBUG level for that purpose. In doubt please create issue in this repository with steps how to reproduce the issue.

Where can I find more details about tardis.dev API?

Check out API docs.

License

MPL-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tardis_dev-2.0.0a14.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

tardis_dev-2.0.0a14-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file tardis_dev-2.0.0a14.tar.gz.

File metadata

  • Download URL: tardis_dev-2.0.0a14.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for tardis_dev-2.0.0a14.tar.gz
Algorithm Hash digest
SHA256 3496a6b595dbd73c42d0e3d3a80ea2a262940195eb059a5efc57b6af1474c48d
MD5 f972c071bdde96a7e725112c792610d1
BLAKE2b-256 86383732f28d8ba9cde3b091fb223f134724c54f12e709638ecb8086be529ba1

See more details on using hashes here.

File details

Details for the file tardis_dev-2.0.0a14-py3-none-any.whl.

File metadata

  • Download URL: tardis_dev-2.0.0a14-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.12.4 Darwin/23.4.0

File hashes

Hashes for tardis_dev-2.0.0a14-py3-none-any.whl
Algorithm Hash digest
SHA256 7685e0b0b44a0e34b69687cc3bda0445eb9c2abf6028529c7b3da87bc719a694
MD5 1fbd661683f348091fc4874ab56b6f22
BLAKE2b-256 cf296497f60ac896702455967cf9d7f903c91916a9112e5c55e8ac5bf0a79f55

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page