examples/live/bybit/README_options_data_collector.md
This script discovers all available options for a given underlying asset (e.g., BTC) on Bybit, subscribes to their quote and orderbook data, and stores the data in parquet files.
export BYBIT_API_KEY="your_api_key"
export BYBIT_API_SECRET="your_api_secret"
python examples/live/bybit/bybit_options_data_collector.py
The script can be configured by modifying the BybitOptionsDataCollectorConfig in the script:
strategy_config = BybitOptionsDataCollectorConfig(
underlying_asset="BTC", # The underlying asset to collect options for
spot_instrument_id=InstrumentId.from_str("BTCUSDT-SPOT.BYBIT"),
depth=25, # Orderbook depth (25 or 100 levels)
batch_size=1000, # Records to batch before writing to parquet
data_dir="data", # Directory to store parquet files
log_interval=60.0, # Log and save data every N seconds
)
The script creates the following directory structure:
data/
└── BTC/
└── USDT/
├── spot/
│ ├── BTCUSDT-SPOT_BYBIT_quote.parquet
│ └── BTCUSDT-SPOT_BYBIT_orderbook.parquet
└── options/
├── BTC-15SEP26-45000-C-USDT-OPTION_BYBIT_quote.parquet
├── BTC-15SEP26-45000-C-USDT-OPTION_BYBIT_orderbook.parquet
├── BTC-15SEP26-45000-P-USDT-OPTION_BYBIT_quote.parquet
├── BTC-15SEP26-45000-P-USDT-OPTION_BYBIT_orderbook.parquet
└── ... (one file pair per option)
Each quote tick record contains:
timestamp: When the data was receivedinstrument_id: The instrument identifierbid_price: Best bid priceask_price: Best ask pricebid_size: Best bid sizeask_size: Best ask sizets_event: Event timestampts_init: Initialization timestampEach orderbook delta record contains:
timestamp: When the data was receivedinstrument_id: The instrument identifiersequence: Sequence numberdelta_count: Number of deltas in this updatebest_bid: Best bid price after applying deltasbest_ask: Best ask price after applying deltasbid_size: Best bid size after applying deltasask_size: Best ask size after applying deltas# Collect data for all BTC options
python examples/live/bybit/bybit_options_data_collector.py
You can modify the script to:
The script provides real-time monitoring through logs:
2025-07-31T14:47:55.003958000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: Discovering all available BTC options...
2025-07-31T14:47:55.004032000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: Found 150 BTC options instruments
2025-07-31T14:47:55.004097000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: BTC options grouped by expiry (8 expiry dates):
2025-07-31T14:47:55.004159000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: 15SEP26: 25 options
2025-07-31T14:47:55.004247000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: 15OCT26: 25 options
2025-07-31T14:47:55.004300000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: 15NOV26: 25 options
...
2025-07-31T14:47:55.004357000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: Total BTC options to monitor: 150
2025-07-31T14:47:55.004413000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: === 60.0 SECOND UPDATE ===
2025-07-31T14:47:55.004470000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: BTC-15SEP26-45000-C-USDT-OPTION.BYBIT: 150 quotes, 41 deltas
2025-07-31T14:47:55.004503000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: BTC-15SEP26-45000-P-USDT-OPTION.BYBIT: 148 quotes, 137 deltas
...
2025-07-31T14:47:55.004515000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: BTCUSDT-SPOT.BYBIT: 1076 quotes, 523 deltas
2025-07-31T14:47:55.006441000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: TOTAL: 15000 quotes, 8000 deltas
2025-07-31T14:47:55.006517000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: OPTIONS: 13924 quotes, 7477 deltas
2025-07-31T14:47:55.006522000Z [INFO] OPTIONS-COLLECTOR-001.BybitOptionsDataCollector: SPOT: 1076 quotes, 523 deltas