Skip to main content

Deribit options data pipeline with ClickHouse storage

Project description

gapless-deribit-clickhouse

Deribit options data pipeline with ClickHouse storage.

Features

  • Historical trades: Backfillable from 2018 via history.deribit.com
  • Ticker snapshots: Point-in-time OI + Greeks (forward-only collection)
  • Schema-first: YAML schemas generate types, DDL, and documentation
  • Python API: Clean interface for querying options data

Installation

pip install gapless-deribit-clickhouse

Quick Start

import gapless_deribit_clickhouse as gdch

# Fetch historical trades
df = gdch.fetch_trades(
    underlying="BTC",
    start="2024-01-01",
    end="2024-01-31",
    option_type="C"  # Calls only
)

# Fetch ticker snapshots (OI + Greeks)
df = gdch.fetch_ticker_snapshots(
    underlying="BTC",
    start="2024-12-01"
)

# Get active instruments
instruments = gdch.get_active_instruments(underlying="BTC")

Data Sources

Trades Table

Field Type Description
trade_id String Unique trade identifier
instrument_name String e.g., BTC-27DEC24-100000-C
timestamp DateTime64 Trade time (ms precision)
price Float64 Trade price in USD
amount Float64 Contract amount
direction String buy or sell
iv Float64 Implied volatility
underlying String BTC or ETH (derived)
expiry Date Option expiration (derived)
strike Float64 Strike price (derived)
option_type String C or P (derived)

Ticker Snapshots Table

Field Type Description
instrument_name String e.g., BTC-27DEC24-100000-C
timestamp DateTime64 Snapshot time (ms precision)
open_interest Float64 Current OI in contracts
delta Float64 Option delta (-1 to 1)
gamma Float64 Option gamma
vega Float64 Option vega
theta Float64 Option theta
mark_iv Float64 Mark implied volatility

IMPORTANT: Open Interest cannot be reconstructed from trades. The ticker_snapshots table requires forward-only collection.

Instrument Name Format

{UNDERLYING}-{DDMMMYY}-{STRIKE}-{TYPE}

Examples:

  • BTC-27DEC24-100000-C - BTC call, $100k strike, expires Dec 27 2024
  • ETH-28MAR25-5000-P - ETH put, $5k strike, expires Mar 28 2025

Configuration

Credentials

Set ClickHouse credentials via one of:

  1. Environment variables:

    export CLICKHOUSE_HOST_READONLY=<host>
    export CLICKHOUSE_USER_READONLY=<user>
    export CLICKHOUSE_PASSWORD_READONLY=<password>
    
  2. .env file in project root

  3. Doppler (recommended for production):

    doppler setup --project gapless-deribit-clickhouse --config prd
    

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check src/

Architecture

๐Ÿ“Š Deribit Options Data Pipeline

   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚ history.deribit.com โ”‚  โ”€โ”
   โ”‚  /get_last_trades   โ”‚   โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
             โ”‚               โ”‚
             โˆจ               โ”‚
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
   โ”‚   TradesCollector   โ”‚   โ”‚  Historical
   โ”‚    (Historical)     โ”‚   โ”‚  Backfill
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
             โ”‚               โ”‚
             โˆจ               โ”‚
   โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—   โ”‚
   โ•‘ deribit_options     โ•‘ <โ”€โ”˜
   โ•‘      .trades        โ•‘
   โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
             โ”‚
             โˆจ
   โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
   โ”‚     Python API      โ”‚
   โ”‚   fetch_trades()    โ”‚
   โ”‚  fetch_snapshots()  โ”‚
   โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
             โˆง
             โ”‚
   โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
   โ•‘ deribit_options     โ•‘ <โ”€โ”
   โ•‘ .ticker_snapshots   โ•‘   โ”‚
   โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•   โ”‚
             โˆง               โ”‚
             โ”‚               โ”‚
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
   โ”‚   TickerCollector   โ”‚   โ”‚  Forward-Only
   โ”‚   (Forward-Only)    โ”‚   โ”‚  Collection
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
             โˆง               โ”‚
             โ”‚               โ”‚
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
   โ”‚   www.deribit.com   โ”‚  โ”€โ”˜
   โ”‚       /ticker       โ”‚
   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

License

MIT

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

gapless_deribit_clickhouse-0.1.0.tar.gz (115.1 kB view details)

Uploaded Source

Built Distribution

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

gapless_deribit_clickhouse-0.1.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file gapless_deribit_clickhouse-0.1.0.tar.gz.

File metadata

  • Download URL: gapless_deribit_clickhouse-0.1.0.tar.gz
  • Upload date:
  • Size: 115.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gapless_deribit_clickhouse-0.1.0.tar.gz
Algorithm Hash digest
SHA256 14703a89381a82d29e635541afad8f04a0aa29ab6829eac34fdc055fa01b7bd3
MD5 63afd6ad9d142343a615d18e7d033685
BLAKE2b-256 ae51ebea1d9e4e3bd4527127dd5b6b52c5724d6ce061d3b1c532c343b3d7cd71

See more details on using hashes here.

File details

Details for the file gapless_deribit_clickhouse-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gapless_deribit_clickhouse-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for gapless_deribit_clickhouse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cde23dfab905edeb93f75ad1db4625a53ec9e33fb312fad90036ce37df26b87e
MD5 7ec33eb73a5c3616e97429c22bd4b7fc
BLAKE2b-256 9a65808d0da8b083c8412da70925ebf1bdade594b7082a993a2a96931f796683

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