Skip to main content

Fetch binance historical klines or trades easily.

Project description

pypi version License - MIT Coverage Tests Status Documentation Status PyPI - Python Version

Fetch binance public data easily.

Supports Python 3.8+.

Installation

$ pip install binance-history

Usage

API docs

Klines

>>> import binance_history as bh
>>> klines = bh.fetch_klines(
...     symbol="BTCUSDT",
...     timeframe="1m",
...     start="2022-12-14",
...     end="2022-12-24",
... )
                               open      high       low     close     volume  quote_volume  trades                   close_datetime
open_datetime
2022-12-14 00:00:00+08:00  17753.54  17768.41  17752.78  17766.99  240.82918  4.277685e+06    5241 2022-12-14 00:00:59.999000+08:00
2022-12-14 00:01:00+08:00  17766.99  17786.40  17764.37  17781.81  311.47670  5.536668e+06    6278 2022-12-14 00:01:59.999000+08:00
2022-12-14 00:02:00+08:00  17781.81  17790.54  17771.44  17785.37  372.12992  6.616562e+06    6911 2022-12-14 00:02:59.999000+08:00
2022-12-14 00:03:00+08:00  17786.23  17800.18  17774.63  17777.35  401.52223  7.142210e+06    6926 2022-12-14 00:03:59.999000+08:00
2022-12-14 00:04:00+08:00  17777.35  17785.98  17769.15  17781.93  218.03837  3.876373e+06    5519 2022-12-14 00:04:59.999000+08:00
...                             ...       ...       ...       ...        ...           ...     ...                              ...
2022-12-23 23:56:00+08:00  16850.22  16850.22  16839.55  16842.59  146.38906  2.465894e+06    4229 2022-12-23 23:56:59.999000+08:00
2022-12-23 23:57:00+08:00  16842.59  16846.22  16839.00  16840.99   86.95440  1.464495e+06    3152 2022-12-23 23:57:59.999000+08:00
2022-12-23 23:58:00+08:00  16840.99  16843.61  16827.28  16830.27  208.41471  3.508642e+06    4918 2022-12-23 23:58:59.999000+08:00
2022-12-23 23:59:00+08:00  16830.27  16836.66  16824.41  16832.16  154.10833  2.593717e+06    4502 2022-12-23 23:59:59.999000+08:00
2022-12-24 00:00:00+08:00  16832.15  16833.62  16828.42  16830.52  119.28572  2.007721e+06    3725 2022-12-24 00:00:59.999000+08:00

[14401 rows x 8 columns]

AggTrades

>>> bh.fetch_agg_trades(
...     symbol="ETCBTC",
...     start="2022-11 01:05",
...     end="2022-11-25 3:20",
...     tz="Europe/Paris"
... )
                                    price  quantity  is_buyer_maker
datetime
2022-11-01 01:05:09.435000+01:00  0.001187      1.60            True
2022-11-01 01:05:17.639000+01:00  0.001186     29.56            True
2022-11-01 01:05:18.616000+01:00  0.001186      8.43            True
2022-11-01 01:05:18.621000+01:00  0.001186     37.31            True
2022-11-01 01:05:18.748000+01:00  0.001186      0.17            True
...                                    ...       ...             ...
2022-11-25 03:19:18.317000+01:00  0.001199      5.00           False
2022-11-25 03:19:19.482000+01:00  0.001199     10.69           False
2022-11-25 03:19:23.270000+01:00  0.001199      7.55            True
2022-11-25 03:19:26.082000+01:00  0.001199      2.56            True
2022-11-25 03:19:40.375000+01:00  0.001199      2.20           False

Command Line

binance-history comes with a command line interface, you need to install some extra dependencies to use it:

$ pip install 'binance-history[cli]'
$ bh --help
Usage: bh [OPTIONS]

Options:
  --symbol TEXT                   The binance market pair name, e.g. BTCUSDT
                                  [required]
  --start TEXT                    The start datetime, e.g. '2022-1-2 1:10'
                                  [required]
  --end TEXT                      The end datetime, e.g. '2022-1-25 2:20
                                  [required]
  --data-type [klines|aggTrades]  choose klines or aggTrades to download,
                                  default to 'klines'
  --asset-type [spot|futures/um|futures/cm]
                                  choose spot or futures data, default to
                                  'spot'
  --timeframe [1s|1m|3m|5m|15m|30m|1h|2h|4h|6h|8h|12h|1d|3d|1w|1M]
                                  The timeframe of klines, default to '15m',
                                  can be omitted if --data-type is not
                                  'klines'
  --tz TEXT                       The tz database name of time zone, use your
                                  local time zone if omitted'
  --output-path TEXT              The path you want to save the downloaded
                                  data, support format: [csv, json, xlsx],
                                  e.g. a.xlsx  [required]
  --help                          Show this message and exit.

$ bh --start 2022-1-5 --end 2022-1-7 --symbol ETCBTC --output-path a.xlsx

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

binance_history-0.1.7.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

binance_history-0.1.7-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file binance_history-0.1.7.tar.gz.

File metadata

  • Download URL: binance_history-0.1.7.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1036-azure

File hashes

Hashes for binance_history-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b193ff15ae755cf71efa42362550f046e42044d5444d3889e55867bd93ae032d
MD5 219f1ffe6d5c554ea6f4523b9ef16b80
BLAKE2b-256 c9a0ef3330214aeb7c9743961648b48be9959e76aa46e67bac53d436a2c0dfd9

See more details on using hashes here.

File details

Details for the file binance_history-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: binance_history-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1036-azure

File hashes

Hashes for binance_history-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e3f3664e76f7873cbbc101ab0db0182c93a9459e1766c588d5713c7ac745de05
MD5 455a18cbfc2d0a3169aea1d6531ecede
BLAKE2b-256 7b4c22779e18c77fdf8d66e975936d46c6102bd17cfbd40be2574e49db7d010a

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