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.9.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: quantease_binance-0.1.9.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.9.tar.gz
Algorithm Hash digest
SHA256 439e1700e6971181d6ca1604d96c5b0f5f73b00ad2c157764c037b7e2131240c
MD5 daf8902e9581b3588b0b00b5a10af19d
BLAKE2b-256 814ff6a958ab65948394428ba6e03b72b55ef338ab2712d08aa53fd423968263

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quantease_binance-0.1.9-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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 8279cf5afd363114dbda14762fe757a273e6a2b30bffde8d937c015b25c25500
MD5 8afe4b7a25eb0fad2c70ac27a7c70680
BLAKE2b-256 9fdad1cd21f9f9d9599d4153626631f90bcd4f32d765d0cfaf4e43ae2e3576c6

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