BinanceKlines downloader
BinanceKlines downloader is a simple command line tool and Python library used to download OHLCV k-lines from Binance. It works asynchronously to download candlestick market data from multiple symbols concurrently.
Installation
$ git clone git@github.com:fievelk/binance-klines.git # Clone the project
$ cd binance-klines/
$ pip install .
Usage
BinanceKlines can be used both as command line tool and Python module. The tool fetches data from Binance's GET /api/v3/klines endpoint.
From command line
You can check all the available options using binance-klines --help.
$ binance-klines --help
usage: binance-klines [-h] [-v] --start-date START_DATE [--end-date END_DATE] [-o OUTPUT_DIR]
[--timeframe {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M}]
symbols [symbols ...]
positional arguments:
symbols The list of currencies whose OHLCV will be fetched.
options:
-h, --help show this help message and exit
-v, --verbose Increase output verbosity. -v: INFO, -vv: DEBUG.
Default: WARNING.
--start-date START_DATE
(Required) Start downloading data from this date. E.g.: 2019-01-24 00:00:00
--end-date END_DATE Download data up to this date. E.g.: 2020-05-30 00:00:00.
Default: now.
-o OUTPUT_DIR, --output-dir OUTPUT_DIR
The data directory to store the output CSV files.
Default: the current directory.
--timeframe {1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M}
The frequency of the OHLCV data to be downloaded.
Default: 1h.
Here is an example of how to download 1-minutes candlestick data for BTC/USDT and ETH/USDT from 18th July 2022 to 20th July 2022:
$ binance-klines --start-date "2022-07-18 00:00:00" \
--end-date "2022-07-20 23:59:00" --timeframe '1m' --output-dir .data/ \
--symbols BTC/USDT ETH/USDT
As a Python module
import asyncio
import datetime
import pytz
from binance_klines.downloader import BinanceKLinesDownloader
async def main():
downloader = BinanceKLinesDownloader()
start_date = datetime.datetime(2020, 9, 1).replace(tzinfo=pytz.utc)
end_date = datetime.datetime(2020, 9, 2).replace(tzinfo=pytz.utc)
# Download data for a single symbol. Data is downloaded in batches.
results = await downloader.fetch_klines(
symbols=["BTC/USDT", "ETH/USDT"],
start_date=start_date,
end_date=end_date,
timeframe="30m",
)
# Results contain the klines for each symbol, in the order that was passed to the
# `symbols` argument.
btc_batches = results[0]
eth_batches = results[1]
if __name__ == "__main__":
asyncio.run(main())
Tests
Tests are written using pytest. To test compatibility among several Python versions, install the dev dependencies using Poetry and run tests using tox:
$ poetry install --with dev # Install dependencies
$ poetry shell # Activate Poetry environment
$ tox
Contributing
You are welcome to contribute by opening a PR with your improvements. Please make sure to run the Black linter before you do. You can use tox for this:
$ tox -e lint
TODO
- Change logging of utils.timeit to DEBUG
- Remove ccxt and use aiohttp directly
Metadata
Release files for binance-klines 0.1.1
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 |
|---|---|---|---|---|
| binance_klines-0.1.1.tar.gz | 8.0 kB | Without provenance | Details for binance_klines-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| binance_klines-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for binance_klines-0.1.1-py3-none-any.whl |
Total release size: 17.0 kB
Release files / binance_klines-0.1.1.tar.gz
| Download URL | binance_klines-0.1.1.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1080afbb2620b7e9a4d0a9bc020dbc2d769183dd1cbb827066a0430fc037ef0f
|
|
BLAKE2b-256 checksum How to use checksums |
8acf39e2169db30e918a22308b3ce1c2c325739fb5502863d01fe6966498f00e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.10.2 Darwin/22.4.0
|
Release files / binance_klines-0.1.1-py3-none-any.whl
| Download URL | binance_klines-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
32b353637c2a9fd2a0516ea38d042e39dbb6ab1a0d32c7b6cf494bc2a3889088
|
|
BLAKE2b-256 checksum How to use checksums |
8a9b9565c7e5b46087446cec25b3943f82ca06218e9172fdb01ae7dc096bd9e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.1 CPython/3.10.2 Darwin/22.4.0
|
Security for binance-klines 0.1.1
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.