Skip to main content

This project provides a Python API for fetching historical data from the Binance exchange. It includes functionalities for retrieving Klines, trades, aggregate trades, book ticker data, funding rates, and metrics.

Project description

Project Documentation

Project Description

This project provides a Python API for fetching historical data from the Binance exchange. It includes functionalities for retrieving Klines, trades, aggregate trades, book ticker data, funding rates, and metrics.

Quick Start Guide

View Full Documentation

To use the functions in quantease_binance, you need to import the necessary modules and call the desired functions with appropriate parameters. Here are some examples:

Installation

quantease-binance can be installed using pip:

pip install quantease-binance

Fetch All Trading Pairs

To fetch all trading pairs from the Binance exchange, you can use the fetch_all_symbols function. Here’s how to use it:

import quantease_binance as qb

symbols = qb.fetch_all_symbols()
print(symbols)

This will return a list of trading pairs based on the specified asset_type. By default, asset_type is set to "spot". If you want to get trading pairs for perpetual contracts, specify asset_type as "futures/um" or "futures/cm".

Fetch Aggregate Trade Data

import quantease_binance as qb

agg_trades = qb.fetch_agg_trades(
    symbol='BTCUSDT',
    start='2024-01-01',
    end='2024-05-01',
    asset_type='spot',
    tz='UTC'
)
print(agg_trades)

Fetch Book Ticker Data

book_ticker = qb.fetch_book_ticker(
    symbol='AAVEUSD_PERP',
    start='2024-01-01',
    end='2024-02-01',
    asset_type='futures/cm',
    tz='UTC'
)
print(book_ticker)

Fetch Funding Rate Data

funding_rate = qb.fetch_funding_rate(
    symbol='ETHUSDT',
    start='2019-01-01',
    end='2024-07-01',
    asset_type='futures/um',
    tz='UTC'
)
print(funding_rate)

Fetch Trade Data

trade = qb.fetch_trades(
    symbol='ETHUSDT',
    start='2024-05-01',
    end='2024-07-10',
    asset_type='spot',
    tz='UTC'
)
print(trade)

Fetch Kline Data

klines = qb.fetch_klines(
    symbol='BTCUSDT',
    start='2018-01-01',
    end='2024-07-12',
    timeframe='1m',
    asset_type='spot',
    tz='UTC'
)
print(klines)

Fetch Metrics Data

metrics = qb.fetch_metrics(
    symbol='BTCUSDT',
    start='2024-01-01',
    end='2024-04-01',
    asset_type='futures/um',
    tz='UTC'
)
print(metrics)

Make sure to replace the placeholders for symbol, start, end, and other parameters as needed.

API Documentation

fetch_klines

Convenience function to fetch Kline data.

Parameters:

  • symbol (str): Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): Start time for the data request.
  • end (str or datetime): End time for the data request.
  • timeframe (str, optional): Kline interval. Default is "1m".
  • asset_type (str, optional): Asset type for the data request. Default is "spot".
  • tz (str, optional): Timezone for the returned DataFrame's datetime parameters. Default is None.

Returns:

  • DataFrame: A pandas DataFrame containing open, high, low, close, volume, trades, close_datetime columns.

fetch_trades

Convenience function to fetch trade data.

Parameters:

  • symbol (str): Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): Start time for the data request.
  • end (str or datetime): End time for the data request.
  • asset_type (str, optional): Asset type for the data request. Default is "spot".
  • tz (str, optional): Timezone for the returned DataFrame's datetime parameters. Default is None.

Returns:

  • DataFrame: A pandas DataFrame containing id, price, qty, quoteQty, time, isBuyerMaker, isBestMatch columns.

fetch_agg_trades

Convenience function to fetch aggregate trade data.

Parameters:

  • symbol (str): Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): Start time for the data request.
  • end (str or datetime): End time for the data request.
  • asset_type (str, optional): Asset type for the data request. Default is "spot".
  • tz (str, optional): Timezone for the returned DataFrame's datetime parameters. Default is None.

Returns:

  • DataFrame: A pandas DataFrame containing id, price, qty, firstTradeId, lastTradeId, time, isBuyerMaker, isBestMatch columns.

fetch_book_ticker

Convenience function to fetch book ticker data.

Parameters:

  • symbol (str): Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): Start time for the data request.
  • end (str or datetime): End time for the data request.
  • asset_type (str, optional): Asset type for the data request. Default is "spot".
  • tz (str, optional): Timezone for the returned DataFrame's datetime parameters. Default is None.

Returns:

  • DataFrame: A pandas DataFrame containing symbol, bidPrice, bidQty, askPrice, askQty, time columns.

fetch_funding_rate

Convenience function to fetch funding rate data.

Parameters:

  • symbol (str): Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): Start time for the data request.
  • end (str or datetime): End time for the data request.
  • asset_type (str): Asset type for the data request. Must be one of "spot", "futures/um", or "futures/cm".
  • tz (str, optional): Timezone for the returned DataFrame's datetime parameters. Default is None.

Returns:

  • DataFrame: A pandas DataFrame containing symbol, fundingRate, fundingTime columns.

fetch_metrics

Convenience function to fetch metrics data.

Parameters:

  • symbol (str): Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): Start time for the data request.
  • end (str or datetime): End time for the data request.
  • asset_type (str): Asset type for the data request. Must be one of "spot", "futures/um", or "futures/cm".
  • tz (str, optional): Timezone for the returned DataFrame's datetime parameters. Default is None.

Returns:

  • DataFrame: A pandas DataFrame containing symbol, openInterest, numberOfTrades, volume, quoteVolume, takerBuyBaseAssetVolume, takerBuyQuoteAssetVolume, openTime, closeTime columns.

fetch_data

Main function to fetch data.

Parameters:

  • symbol (str): Binance market pair name, e.g., "BTCUSDT".
  • asset_type (str): Asset type for the data request. Must be one of "spot", "futures/um", or "futures/cm".
  • data_type (str): Type of data to request. Must be one of "klines", "aggTrades", "bookTicker", "fundingRate", "metrics".
  • start (datetime): Start time for the data request.
  • end (datetime): End time for the data request.
  • tz (str, optional): Timezone for the returned DataFrame's datetime parameters. Default is "UTC".
  • timeframe (str, optional): Kline interval. Default is None.

Returns:

  • DataFrame: A pandas DataFrame containing the requested data.

fetch_all_symbols

Function to fetch all trading pairs from the Binance exchange.

Parameters:

  • exchange (object): Exchange object initialized using the ccxt library. Default is config.EXCHANGE.
  • asset_type (str, optional): Asset type for the trading pairs to fetch. Must be one of "spot", "futures/um", or "futures/cm". Default is "spot".

Returns:

  • List[str]: List of trading pair IDs based on the specified asset_type.

Notes

Functions in this API require the quantease_binance.utils module and its gen_dates, get_data, unify_datetime, and get_data_async functions. Ensure to import them as well.

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

quantease_binance-0.1.7.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

quantease_binance-0.1.7-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quantease_binance-0.1.7.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.15 Linux/6.8.0-41-generic

File hashes

Hashes for quantease_binance-0.1.7.tar.gz
Algorithm Hash digest
SHA256 e6f30868c45869cf1eaa0501c7a33beafd96ca7b73f6e6eec492bb650eb42bc8
MD5 d2ff98f798ce485ce4e0d4ac0a55bc07
BLAKE2b-256 0e082a4517134ce4c221aec926d6206a0abacc148a9066e867f7ff96b45861b1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quantease_binance-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.15 Linux/6.8.0-41-generic

File hashes

Hashes for quantease_binance-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 64b0b037a144c3129b787a5e609fa5d2a2cc5996bd49f872a70ba0bb5791daf5
MD5 e7b4ef76c5c6304ff5b8a95e09572212
BLAKE2b-256 cb7a00fb16178e0d82e95a6dbf5e07110b1f501277ec550de1486210024b0765

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