Skip to main content

Python SDK for accessing cryptocurrency high-frequency trading data

Project description

CryptoHFTData Python SDK

PyPI version Python versions License: MIT

cryptohftdata is a Python SDK for downloading high-frequency cryptocurrency market data as pandas DataFrames.

It is designed for research scripts, notebooks, and production ingestion jobs that need a simple interface over the CryptoHFTData parquet dataset.

Installation

pip install cryptohftdata

Quick Start

Dataset downloads require an API key. Export CRYPTOHFTDATA_API_KEY or pass api_key= explicitly.

import os

import cryptohftdata as chd

chd.configure_client(api_key=os.environ["CRYPTOHFTDATA_API_KEY"])

exchange = chd.exchanges.BINANCE_FUTURES
symbols = chd.list_symbols(exchange, data_type="trades")

if "BTCUSDT" not in symbols:
    raise RuntimeError("BTCUSDT is not currently listed for Binance futures trades")

trades = chd.get_trades(
    symbol="BTCUSDT",
    exchange=exchange,
    start_date="2025-08-01",
    end_date="2025-08-01",
    max_workers=4,
)

print(trades.head())
print(f"rows={len(trades)} columns={list(trades.columns)}")

Authentication Model

  • list_symbols(), list_exchanges(), and get_exchange_info() query API metadata and can be used without an API key.
  • Dataset download helpers such as get_trades() and get_mark_price() download parquet files and require an API key.
  • The convenience helpers also accept client configuration kwargs such as api_key, base_url, timeout, max_retries, rate_limit, and use_jwt.

Native S3 Access

If you want raw flat-file access instead of DataFrame helpers, exchange your existing CryptoHFTData API key for short-lived R2 S3 credentials:

import os
import requests

response = requests.post(
    "https://api.cryptohftdata.com/s3-credentials",
    headers={"X-API-Key": os.environ["CRYPTOHFTDATA_API_KEY"]},
    timeout=30,
)
response.raise_for_status()

payload = response.json()
creds = payload["credentials"]

print(payload["bucket"])
print(payload["endpoint"])
print(payload["expires_at"])

You can then pass the returned credentials into boto3:

import boto3

s3 = boto3.client(
    "s3",
    endpoint_url=payload["endpoint"],
    region_name=payload["region"],
    aws_access_key_id=creds["access_key_id"],
    aws_secret_access_key=creds["secret_access_key"],
    aws_session_token=creds["session_token"],
)

objects = s3.list_objects_v2(Bucket=payload["bucket"])
for item in objects.get("Contents", []):
    print(item["Key"])

Public API

Convenience helpers

Use the top-level helpers when you want the shortest path from notebook code to DataFrame output:

import cryptohftdata as chd

chd.configure_client(api_key="your-api-key")

trades = chd.get_trades("BTCUSDT", chd.exchanges.BINANCE_FUTURES, "2025-08-01", "2025-08-01")
mark_price = chd.get_mark_price("BTCUSDT", chd.exchanges.BINANCE_FUTURES, "2025-08-01", "2025-08-01")

Explicit client usage

Use CryptoHFTDataClient when you want explicit configuration, context-manager usage, or cache inspection:

from cryptohftdata import CryptoHFTDataClient, exchanges

with CryptoHFTDataClient(api_key="your-api-key", timeout=60, rate_limit=10) as client:
    info = client.get_exchange_info(exchanges.BYBIT_FUTURES)
    trades = client.get_trades(
        "ETHUSDT",
        exchanges.BYBIT_FUTURES,
        "2025-08-01",
        "2025-08-01",
        max_workers=2,
    )
    print(info["supported_data_types"])
    print(client.get_cache_info())

Data Sets

All dataset download helpers return pandas DataFrames. Column names can vary by exchange, but these are the typical shapes:

Helper Typical columns
get_klines() open_time, open, high, low, close, volume
get_orderbook() timestamp, side, level, price, size
get_trades() timestamp, trade_id, price, quantity, side
get_ticker() timestamp, open, high, low, close, volume
get_mark_price() timestamp, mark_price, index_price, funding_rate, next_funding_time
get_open_interest() timestamp, symbol, exchange, open_interest
get_liquidations() timestamp, side, price, quantity, order_id

You can inspect the in-package schema reference if you want a structured summary at runtime:

from cryptohftdata import get_dataset_schema

schema = get_dataset_schema("trades")
print(schema.typical_columns)

Supported Exchanges

Use the SDK itself to discover supported exchanges and dataset coverage instead of hard-coding assumptions:

import cryptohftdata as chd

for exchange in chd.list_exchanges():
    info = chd.get_exchange_info(exchange)
    print(exchange, info["type"], info["supported_data_types"])

The package also exposes constants through chd.exchanges, for example:

  • chd.exchanges.BINANCE_SPOT
  • chd.exchanges.BINANCE_FUTURES
  • chd.exchanges.BYBIT_SPOT
  • chd.exchanges.BYBIT_FUTURES
  • chd.exchanges.KRAKEN_FUTURES

Error Handling

The most common exceptions are:

  • ValidationError for invalid symbols, exchange identifiers, or date ranges
  • ConfigurationError when a dataset download is attempted without an API key
  • AuthenticationError when credentials are rejected
  • APIError for API-side failures or malformed responses

Example:

import cryptohftdata as chd

try:
    chd.get_trades("BTCUSDT", chd.exchanges.BINANCE_FUTURES, "2025-08-02", "2025-08-01")
except chd.ValidationError as exc:
    print(f"invalid request: {exc}")

Examples and Docs

  • Example scripts live in sdk/python/examples/
  • Documentation source files live in sdk/python/docs/
  • Package docstrings are available through help(cryptohftdata) and help(cryptohftdata.CryptoHFTDataClient)

Development

From a source checkout:

cd sdk/python
pip install -e ".[dev,docs,test]"
pytest
sphinx-build -b html docs docs/_build/html

Support

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

cryptohftdata-0.3.0.tar.gz (46.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cryptohftdata-0.3.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file cryptohftdata-0.3.0.tar.gz.

File metadata

  • Download URL: cryptohftdata-0.3.0.tar.gz
  • Upload date:
  • Size: 46.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for cryptohftdata-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9677c30fc3d16a9df2626061fd105a6405c857dce9af9b81a33e2cb407761874
MD5 332dbb5095edbd67b1cc61441255a9b7
BLAKE2b-256 19b2a30422384fcac0266af0feb320ee9ebd829a44925e3050cf1722a08d2445

See more details on using hashes here.

File details

Details for the file cryptohftdata-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: cryptohftdata-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for cryptohftdata-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29c393ecc185b02e600bd13650a84a29872f422471ecd5fa1abaeed1b84a6907
MD5 7689844978e48d576514c311bb0742ad
BLAKE2b-256 43c695d082e8bdf5afff99423b72c524e303808b97d4fa3c02631d29cc0e409e

See more details on using hashes here.

Supported by

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