stas-prokopiev / binance_historical_data

python PYPI package to dump all needed crypto historical data from binance just by 2 lines of code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

binance_historical_data

GitHub last commit

GitHub license<space><space>

PyPI

PyPI - Python Version

Table of Contents

Short Overview.

binance_historical_data is a python package (py>=3.8) which makes download of historical crypto data (prices and volumes) from binance server as simple as it can only be. You don't even need to have an account at binance.com to download all history of crypto data

Data is taken from here: https://data.binance.vision/?prefix=data/
Dumped locally and then unzipped,
so you would have an identical local ready to use data copy
Using this package you will be able to have full historical data of prices and volumes with only 3 lines of python code
And if you need to update already downloaded data then once again 3 lines of python code will do the job
Limitations: The previous day data appears on binance server a few minutes after 0 a.m. UTC
So there is a delay in which you can get the data.

Installation via pip:

How to use it

Initialize main object: data_dumper

Arguments:

  1. path_dir_where_to_dump:
    (string) Path to folder where to dump the data
  2. asset_class:
    (string) Source of data: [spot, um, cm] um: usd(t) margined futures, cm: coin margined futures
  3. data_type="klines":
    (string) data type to dump:
    [aggTrades, klines, trades] for spot
    [aggTrades, klines, trades, indexPriceKlines, markPriceKlines, premiumIndexKlines, metrics] for futures (metrics only supported for um)
    Refer to binance doc for additional info: https://github.com/binance/binance-public-data
  4. str_data_frequency:
    (string) One of [1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h]
    Frequency of price-volume data candles to get

1) The only method to dump the data

Arguments:

  1. tickers=None:
    (list) Trading pairs for which to dump data
    if equals to None - all USDT pairs will be used
  2. date_start=None:
    (datetime.date) The date from which to start dump
    if equals to None - every trading pair will be dumped from the early begining (the earliest is 2017-01-01)
  3. date_end=True=None:
    (datetime.date) The last date for which to dump data
    if equals to None - Today's date will be used
  4. is_to_update_existing=False:
    (bool) Flag if you want to update the data if it's already exist
  5. tickers_to_exclude=None:
    (list) Tickers to exclude from dump

2) Delete outdated daily results

Deleta all daily data for which full month monthly data was already dumped

.csv klines (candles) files columns

"Open time" - Timestamp
"Open"
"High"
"Low"
"Close"
"Volume"
"Close time" - Timestamp
"Quote asset volume"
"Number of trades"
"Taker buy base asset volume"
"Taker buy quote asset volume"
"Ignore"

Examples

How to dump all data for all USDT trading pairs

Please be advised that the first data dump for all trading pairs might take some time (~40 minutes)

How to update data (get all new data)

It's as easy as running the exactly same method dump_data once again
The data_dumper will find all the dates for which data already exists
and will try to dump only the new data

How to update (reload) data for the asked time period

Other useful methods

Get all trading pairs (tickers) from binance

Get the first data when data for the ticker can be found

Get all tickers with locally saved data

Get all dates for which there is locally saved data

Get directory where the local data of exact ticker lies

Create file name for the local file

Contacts

License

This project is licensed under the MIT License.

About

python PYPI package to dump all needed crypto historical data from binance just by 2 lines of code

License:MIT License


Languages

Language:Python 100.0%