BinanceKlines - A tool to download OHLCV candlestick data (K-Lines) from Binance. Written in Python.
Project description
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
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 Distribution
File details
Details for the file binance_klines-0.1.1.tar.gz
.
File metadata
- Download URL: binance_klines-0.1.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.2 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1080afbb2620b7e9a4d0a9bc020dbc2d769183dd1cbb827066a0430fc037ef0f |
|
MD5 | ca975c63c5dec33bd1cbc31f96fa0341 |
|
BLAKE2b-256 | 8acf39e2169db30e918a22308b3ce1c2c325739fb5502863d01fe6966498f00e |
File details
Details for the file binance_klines-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: binance_klines-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.2 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32b353637c2a9fd2a0516ea38d042e39dbb6ab1a0d32c7b6cf494bc2a3889088 |
|
MD5 | 8f4371b944bcc693ac84b2a27fbdf44b |
|
BLAKE2b-256 | 8a9b9565c7e5b46087446cec25b3943f82ca06218e9172fdb01ae7dc096bd9e7 |