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
Installation
pip install okx-dump
Build from source
git clone https://github.com/okx-dump/okx-dump.git
cd okx-dump
poetry install
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
- Data download depends on network connection, stable network environment recommended
- Large data downloads may take considerable time, please be patient
- Downloaded data is automatically saved in Parquet format, readable with pandas
- The program will automatically retry in case of network issues
Metadata
Release files for okx-dump 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| okx_dump-0.1.2.tar.gz | 5.2 kB | Without provenance | Details for okx_dump-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| okx_dump-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for okx_dump-0.1.2-py3-none-any.whl |
Total release size: 11.4 kB
Release files / okx_dump-0.1.2.tar.gz
| Download URL | okx_dump-0.1.2.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
430c6fbcda5d78cb19f4fd23348107796b73d00d1316c99b6cf29ff7997cd476
|
|
BLAKE2b-256 checksum How to use checksums |
fd1c8e9e56680e16f0ae1a14fe440a6e9053fe079c8880cbf6f642f9ee30e547
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-52-generic
|
Release files / okx_dump-0.1.2-py3-none-any.whl
| Download URL | okx_dump-0.1.2-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
006561291e38376038cd763388bcd04b579422cf6cfb4c37c7f32cca320a5a50
|
|
BLAKE2b-256 checksum How to use checksums |
dc14f5bb5ce46405162d48eef23b76785f37263ad385e4507dc4f16b49decf88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-52-generic
|
Security for okx-dump 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.