Binance public data sync CLI and Python API powered by Rust
Project description
binance-cli
A Rust CLI for downloading Binance public klines,
mark-price-klines, index-price-klines, premium-index-klines,
book-ticker, book-depth, liquidation-snapshot, metrics,
trades, and agg-trades datasets, validating Binance .CHECKSUM
files, converting the extracted CSV payload into csv or parquet,
and writing the result through OpenDAL to local storage, S3, or Aliyun
OSS.
Features
- Rust-first project structure with isolated modules for CLI, download, formatting, storage, and pipeline orchestration
- Binance
klines,mark-price-klines,index-price-klines,premium-index-klines,book-ticker,book-depth,liquidation-snapshot,metrics,trades, andagg-tradesdownloads fromhttps://data.binance.vision, with daily/monthly source files chosen automatically per dataset capability - SHA-256 validation using the companion
.CHECKSUMobject - Output format support for
csvandparquetwithparquetas the default - OpenDAL-backed sinks for local filesystem, S3, and Aliyun OSS
Usage
cargo run -- sync klines \
--market spot \
--symbol BTCUSDT \
--interval 1m \
--start 2024-01-01 \
--end 2024-03-31 \
--dest /tmp/binance-data
List supported datasets:
cargo run -- list datasets
List available symbols for a market and dataset:
cargo run -- list symbols --market spot --dataset trades
Download spot trades to CSV:
cargo run -- sync trades \
--market spot \
--symbol BTCUSDT \
--start 2026-04-01 \
--end 2026-04-01 \
--format csv \
--dest /tmp/binance-data
Download futures mark price klines to Parquet:
cargo run -- sync mark-price-klines \
--market um \
--symbol BTCUSDT \
--interval 1m \
--start 2026-04-01 \
--end 2026-04-01 \
--dest /tmp/binance-data
Download futures index price klines to Parquet:
cargo run -- sync index-price-klines \
--market um \
--symbol BTCUSDT \
--interval 1m \
--start 2026-04-01 \
--end 2026-04-01 \
--dest /tmp/binance-data
Download futures premium index klines to Parquet:
cargo run -- sync premium-index-klines \
--market um \
--symbol BTCUSDT \
--interval 1m \
--start 2026-04-01 \
--end 2026-04-01 \
--dest /tmp/binance-data
Download futures book ticker snapshots to Parquet:
cargo run -- sync book-ticker \
--market um \
--symbol BTCUSDT \
--start 2024-03-30 \
--end 2024-03-30 \
--dest /tmp/binance-data
Download futures metrics to Parquet:
cargo run -- sync metrics \
--market um \
--symbol BTCUSDT \
--start 2026-04-01 \
--end 2026-04-01 \
--dest /tmp/binance-data
Download COIN-M liquidation snapshots to Parquet:
cargo run -- sync liquidation-snapshot \
--market cm \
--symbol BTCUSD_PERP \
--start 2024-03-30 \
--end 2024-03-30 \
--dest /tmp/binance-data
Download futures book depth snapshots to Parquet:
cargo run -- sync book-depth \
--market um \
--symbol BTCUSDT \
--start 2026-04-01 \
--end 2026-04-01 \
--dest /tmp/binance-data
Download spot aggregated trades to Parquet:
cargo run -- sync agg-trades \
--market spot \
--symbol BTCUSDT \
--start 2026-04-01 \
--end 2026-04-01 \
--dest /tmp/binance-data
Write to S3:
cargo run -- sync klines \
--market spot \
--symbol BTCUSDT \
--interval 1h \
--start 2024-01-01 \
--end 2024-01-31 \
--format parquet \
--dest s3://my-market-data/binance/raw \
--storage-opt region=us-east-1 \
--storage-opt endpoint=https://s3.amazonaws.com
Write to Aliyun OSS:
cargo run -- sync klines \
--market spot \
--symbol BTCUSDT \
--interval 1h \
--start 2024-01-01 \
--end 2024-01-31 \
--format parquet \
--dest oss://my-market-data/binance/raw \
--storage-opt endpoint=https://oss-cn-hangzhou.aliyuncs.com \
--storage-opt addressing_style=path
Download one day to local disk:
cargo run -- sync klines \
--market spot \
--symbol BTCUSDT \
--interval 1m \
--start 2026-04-01 \
--end 2026-04-01 \
--dest /tmp/binance-data
Output Layout
Each sync writes one file per partition under a dataset-specific prefix. Paths are shown wrapped for readability:
binance/klines/market={market}/symbol={symbol}/interval={interval}/
year={YYYY}/month={MM}/part.{csv|parquet}
binance/mark-price-klines/market={market}/symbol={symbol}/
interval={interval}/year={YYYY}/month={MM}/
part.{csv|parquet}
binance/index-price-klines/market={market}/symbol={symbol}/
interval={interval}/year={YYYY}/month={MM}/
part.{csv|parquet}
binance/premium-index-klines/market={market}/symbol={symbol}/
interval={interval}/year={YYYY}/month={MM}/
part.{csv|parquet}
binance/metrics/market={market}/symbol={symbol}/year={YYYY}/
month={MM}/part.{csv|parquet}
binance/book-depth/market={market}/symbol={symbol}/year={YYYY}/
month={MM}/part.{csv|parquet}
binance/liquidation-snapshot/market={market}/symbol={symbol}/
year={YYYY}/month={MM}/part.{csv|parquet}
binance/trades/market={market}/symbol={symbol}/year={YYYY}/
month={MM}/day={DD}/part.{csv|parquet}
binance/agg-trades/market={market}/symbol={symbol}/year={YYYY}/
month={MM}/day={DD}/part.{csv|parquet}
binance/book-ticker/market={market}/symbol={symbol}/year={YYYY}/
month={MM}/day={DD}/part.{csv|parquet}
Notes
--startand--endalways useYYYY-MM-DD.- The CLI chooses Binance monthly files for full months when a dataset publishes monthly archives; otherwise it stays on daily archives.
- Output partitioning is dataset-specific:
- Monthly:
klines,mark-price-klines,index-price-klines,premium-index-klines,metrics,book-depth,liquidation-snapshot. - Daily:
trades,agg-trades,book-ticker.
- Monthly:
mark-price-klinescurrently supports futures markets only:umandcm.index-price-klinescurrently supports futures markets only:umandcm.premium-index-klinescurrently supports futures markets only:umandcm.book-tickercurrently supports futures markets only:umandcm.book-depthcurrently supports futures markets only:umandcm.liquidation-snapshotcurrently supports COIN-M futures only:cm.metricscurrently supports futures markets only:umandcm.- As of April 11, 2026, observed futures
book-tickerpublic objects forBTCUSDTwere available through2024-03-30; requests beyond published coverage will return404. - As of April 11, 2026, observed COIN-M
liquidation-snapshotpublic objects forBTCUSD_PERPwere available through2024-10-14; requests beyond published coverage will return404. --destaccepts an absolute local path, ans3://bucket/prefixURI, or anoss://bucket/prefixURI.--storage-opt key=valueis the preferred way to pass backend-specific settings such asregion,endpoint, oraddressing_style.s3://destinations still need a region, supplied by--storage-opt region=...,AWS_REGION, orAWS_DEFAULT_REGION.oss://destinations need an endpoint, typically via--storage-opt endpoint=https://oss-cn-hangzhou.aliyuncs.com.- Credentials are usually better supplied via environment variables,
such as
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEYfor S3 andALIBABA_CLOUD_ACCESS_KEY_ID/ALIBABA_CLOUD_ACCESS_KEY_SECRETfor OSS. - Use
--helpfor static option values andlist symbols --market ...--dataset ...for dynamic symbol discovery. - Decimal-like Binance fields are preserved as strings to avoid precision loss during transformation.
Python Package (nekojiru-binance)
Install from PyPI:
pip install nekojiru-binance
Run CLI via Python package entrypoint:
nekojiru-binance sync klines \
--market spot \
--symbol BTCUSDT \
--interval 1m \
--start 2024-01-01 \
--end 2024-01-02 \
--dest /tmp/binance-data
Python API examples:
import nekojiru_binance as nb
print(nb.list_datasets())
print(nb.list_symbols(market="spot", dataset="trades"))
summary = nb.sync(
dataset="klines",
market="spot",
symbol="BTCUSDT",
interval="1m",
start="2024-01-01",
end="2024-01-02",
dest="/tmp/binance-data",
format="parquet",
)
print(summary) # {'files_written': ..., 'rows_written': ...}
Python Build & Publish
Local build and develop install:
python -m pip install -U maturin
maturin develop --features python
Build wheel and sdist:
maturin build --release --features python --out dist
maturin sdist --out dist
Sanity check in a clean virtual environment:
python -m venv .venv
source .venv/bin/activate
pip install dist/*.whl
nekojiru-binance --help
python -c "import nekojiru_binance as nb; print(nb.list_datasets()[:3])"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nekojiru_binance-0.1.0.tar.gz.
File metadata
- Download URL: nekojiru_binance-0.1.0.tar.gz
- Upload date:
- Size: 60.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f037126b6359b9ec2dd4cb232fb8c96613dd2b39e601a15803854b0a651f58ff
|
|
| MD5 |
677bacab33c49b2d6b196c13515ce9cb
|
|
| BLAKE2b-256 |
a398527135af04cec8422ef8e597bf0b4f85f6331501d6d7e8209487b59ffa6b
|
File details
Details for the file nekojiru_binance-0.1.0-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: nekojiru_binance-0.1.0-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 6.0 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15432b28b80ccf3b0b46659d287e6afc9348a1120e11ae281e2f8d3f1ebc3e7b
|
|
| MD5 |
da060a036760da628da13c7e887def28
|
|
| BLAKE2b-256 |
108d270e2598c1e0381645dd500c69944710a44a186b7418b5d8f221aa54e4c6
|
File details
Details for the file nekojiru_binance-0.1.0-cp39-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: nekojiru_binance-0.1.0-cp39-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 7.0 MB
- Tags: CPython 3.9+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d85b0a7751bd790ad210e62f34dcd1db84098b5e505010a951f839ed697cae67
|
|
| MD5 |
f1ec2b1ed0bf2d4867afdd4ba434e8e1
|
|
| BLAKE2b-256 |
d503b90ba77cc6f31de75c46b21b5a270e65f6bc6bd6fc00078db41df9536786
|
File details
Details for the file nekojiru_binance-0.1.0-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: nekojiru_binance-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 6.3 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47744014f7318edb5be3e11e47b27ebe24bae1e2082f05b361474c0383490154
|
|
| MD5 |
254120e27c210144c422e83d146d3cf4
|
|
| BLAKE2b-256 |
ebb5311395aa2fb68e727bab9bceb0808d079f4cb3facf47c4ac36f86ec63edc
|