Skip to main content

A very fast downloader for Binance historical data

Project description

A very simple fast fetcher for Binance historical market data.

By using a combination of historical CSV files and API calls this tiny library can fetch data significantly faster than alternatives fetching just from the API while avoiding rate limiting.

here is a very simple benchmark for you :)

Downloaded tickers Time range HistoricalBinance Freqtrade
BTC/USDT:USDT, ETH/USDT:USDT 20230201-20240315 5.139s 5min 11.78s
BTC/USDT:USDT, ETH/USDT:USDT, OP/USDT:USDT, FET/USDT:USDT, SOL/USDT:USDT, RUNE/USDT:USDT 20230201-20240315 9.68s 14min 28.22s

Usage

The library includes two classes - BinanceDataDownloader and BinanceDataDownloader

BinanceDataDownloader is a very simple class that just fetches the available tickers to download and upon requesting the download_one_ticker(ticker, start_date, end_date, timeframe) function will return a polars dataframe requested. If necessary it can be easily converted to pandas.

 downloader = BinanceDataDownloader()
 data = await downloader.download_one_ticker("BTCUSDT", datetime(2020, 1, 1), datetime(2024, 3, 10), "1d")

BinanceDataProvider is served as an example of how to effectively use the library - caching and asynchronously fetching multiple tickers.

Here is an example of how to use BinanceDataProvider:

from binance_data import BinanceDataProvider 
 
async def binance_data_provider_example(self):
    provider = BinanceDataProvider(["ETH/USDT:USDT", "BTC/USDT:USDT", "FET/USDT:USDT", "RUNE/USDT:USDT", "SOL/USDT:USDT", "OP/USDT:USDT"], ["1m"])
    asyncio.run(provider.update_tickers_async(["ETH/USDT:USDT", "BTC/USDT:USDT", "FET/USDT:USDT", "RUNE/USDT:USDT", "SOL/USDT:USDT", "OP/USDT:USDT"], ["1m"], datetime(2023, 2, 1)))
    print(provider.cached_dataframes["1m"]["ETHUSDT"])

This will print out a polars dataframe with columns 'date', 'open', 'high', 'low', 'close', 'volume', 'count', 'taker_buy_volume', however if you wish you can modify the code to leave the 'ignore', 'taker_buy_quote_volume' and 'quote_volume' columns.

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

historical_binance-0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

historical_binance-0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file historical_binance-0.1.tar.gz.

File metadata

  • Download URL: historical_binance-0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.6

File hashes

Hashes for historical_binance-0.1.tar.gz
Algorithm Hash digest
SHA256 e245133f1c1efa6600bee25a1852e198e5dd21ab816d771f4411ecfdd42dcc8e
MD5 d60640630eecf5f8908eb69943830eb4
BLAKE2b-256 8ed8a53459f23286d7e7921b64bbaf0dacbab2b42de898e8af43fcb7b1f7b622

See more details on using hashes here.

File details

Details for the file historical_binance-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for historical_binance-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 73568b68cb82b204887de91406b76a5c6f15da20a507d45b370d6aacf23e8b81
MD5 b9f37d7e30c66782c76fd295892e5f9b
BLAKE2b-256 47852c2258fef85618d0bec9e5df0325e6c33da40ac156e0723e14a8e4417470

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page