Skip to main content

Add your description here

Project description

OKX Historical Data Download Tool

A Python tool for downloading historical data from OKX exchange. Supports downloading trading data for spot, swap, and futures markets.

Features

  • Multiple data types supported:
    • Trade-by-trade data (trades)
    • Aggregated trade data (aggtrades)
    • Funding rate data (swaprate)
    • Candlestick data (klines, generated from aggregated trades)
  • Multiple market types supported:
    • Spot
    • Perpetual Swap
    • Futures
  • Customizable time range for downloads
  • Asynchronous concurrent downloading for improved efficiency
  • Automatic retry mechanism for improved stability
  • Data automatically saved in Parquet format for storage efficiency

Dependencies

pip install pandas aiohttp tenacity tqdm

Usage Example

import datetime
from okx_dump.dump import DataDumper

# Initialize downloader
dumper = DataDumper(
    asset_type="swap",  # Options: "spot", "swap", "future"
    symbols=["BTC-USDT-SWAP", "ETH-USDT-SWAP"],  # Optional, downloads all pairs by default
    start_date=datetime.date(2024, 1, 1),  # Optional, defaults to 2021-10-01
    end_date=datetime.date(2024, 1, 31),  # Optional, defaults to yesterday
    save_dir="./data",  # Optional, defaults to "./data/{asset_type}"
    proxy="http://your-proxy-url"  # Optional, set proxy
)

# Download data
dumper.dump_symbols(
    data_type="trades",  # Options: "trades", "aggtrades", "swaprate", "klines"
    start_date=datetime.date(2024, 1, 1),  # Optional, overrides initialization setting
    end_date=datetime.date(2024, 1, 31)  # Optional, overrides initialization setting
)

Data Storage Structure

Downloaded data will be saved in the following structure:

data/
├── spot/
│   ├── trades/
│   │   └── 2024-01-01/
│   │       └── BTC-USDT-trades-2024-01-01.parquet
│   └── klines/
│       └── 2024-01-01/
│           └── BTC-USDT-klines-2024-01-01.parquet
├── swap/
└── future/

Data Formats

Trade Data (trades/aggtrades)

  • trade_id: Trade ID
  • side: Trade direction
  • size: Trade size
  • price: Trade price
  • created_time: Creation time (millisecond timestamp)
  • timestamp: UTC timestamp

Funding Rate Data (swaprate)

  • contract_type: Contract type
  • funding_rate: Funding rate
  • real_funding_rate: Actual funding rate
  • funding_time: Settlement time (millisecond timestamp)
  • timestamp: UTC timestamp

Candlestick Data (klines)

  • timestamp: UTC timestamp
  • open: Opening price
  • high: Highest price
  • low: Lowest price
  • close: Closing price
  • volume: Trading volume

Notes

  1. Data download depends on network connection, stable network environment recommended
  2. Large data downloads may take considerable time, please be patient
  3. Downloaded data is automatically saved in Parquet format, readable with pandas
  4. The program will automatically retry in case of network issues

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

okx_dump-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

okx_dump-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file okx_dump-0.1.1.tar.gz.

File metadata

  • Download URL: okx_dump-0.1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-52-generic

File hashes

Hashes for okx_dump-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9a5d73d1bb1175c7da60fc875813007b70fcd7f682ff8469f18d807b7753db28
MD5 2c20bde1fb54880be50e82c914f9a391
BLAKE2b-256 9d7a77a1170c20635ed7ddd56445f03b54062e7348ab07423a3b894d7856518d

See more details on using hashes here.

File details

Details for the file okx_dump-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: okx_dump-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-52-generic

File hashes

Hashes for okx_dump-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5647335c5b909ebc29b2e76ae6f8dc9cc906e1ea1cec2ffe78ed43c497f2c1c
MD5 79b3ddedf9c31e04fc544796668cf6b2
BLAKE2b-256 434e43a63ba54ed559c5c687e44648fe4d2c3a047a9b8d187d639da1c6ec97d6

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