Welcome to binance-history’s documentation!#
binance-history is a Python library for fetching cryptocurrency klines or trades data. It downloads data from the Binance Public Data.
API#
- binance_history.fetch_klines(symbol, start, end, timeframe='1m', asset_type='spot', tz=None)#
- Parameters:
symbol (str) – The binance market pair name. e.g.
'BTCUSDT'.start (str | datetime) – The start datetime of requested data. If it’s an instance of
datetime.datetime, it’s timezone is ignored. If it’s astr, it should be parsed by dateutil, e.g."2022-1-1 8:10".The end datetime of requested data. If it’s an instance of
datetime.datetime, it’s timezone is ignored. If it’s astr, it should be parsed by dateutil, e.g."2022-1-2 8:10".timeframe (str) – The kline interval. e.g. “1m”. see
binance_history.constants.TIMEFRAMESto see the full list of available intervals.asset_type (str) – The asset type of requested data. It must be one of
'spot','futures/um','futures/cm'.tz (str | None) – Timezone of
start,end, and the open/close datetime of the returned dataframe. It should be a time zone name of tz database, e.g. “Asia/Shanghai”. Your can find a full list of available time zone names in List of tz database time zones.
- Returns:
A pandas dataframe with columns open, high, low, close, volume, trades, close_datetime. the dataframe’s index is the open datetime of klines, the timezone of the datetime is set by
tz_database_name, if it is None, your local timezone will be used.- Return type:
- binance_history.fetch_agg_trades(symbol, start, end, asset_type='spot', tz=None)#
- Parameters:
symbol (str) – The binance market pair name. e.g.
'BTCUSDT'.The start datetime of requested data. If it’s an instance of
datetime.datetime, it’s timezone is ignored. If it’s astr, it should be parsed by dateutil, e.g."2022-1-1 8:10".The end datetime of requested data. If it’s an instance of
datetime.datetime, it’s timezone is ignored. If it’s astr, it should be parsed by dateutil, e.g."2022-1-2 8:10".asset_type (str) – The asset type of requested data. It must be one of
'spot','futures/um','futures/cm'.tz (str | None) –
Timezone of
start,end, and the open/close datetime of the returned dataframe. It should be a time zone name of tz database, e.g. “Asia/Shanghai”. Your can find a full list of available time zone names in List of tz database time zones.
- Returns:
A pandas dataframe with columns price, quantity, is_buyer_maker, the dataframe’s index is the datetime of the aggregated trades, the timezone of the datetime is set by
tz_database_name, if it is None, your local timezone will be used.- Return type: