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

Uploaded Source

Built Distribution

quantease_binance-0.1.11-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quantease_binance-0.1.11.tar.gz
  • Upload date:
  • Size: 10.7 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.11.tar.gz
Algorithm Hash digest
SHA256 72b89837d8b60f5bfdc7afae3e28d61623208cd97bbb56a65afb2cab0388725d
MD5 0fc698af2862194f0b91012575a7a855
BLAKE2b-256 7bb831c7bdc7e7f20fe0f8b1962a175f2c2e87fa2b97df073f8b077cf6647cfe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quantease_binance-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 10.7 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 ca2fa2b0259178186d7566bdbd9a590be1e1b2126a3eab3b36d6f3422ccf59b7
MD5 da0a40c7220f116f26b057d5c43a36f4
BLAKE2b-256 11636d11287b99fc31262bf1ab475ca78486f0ec9e893058c0e13ec838417bfa

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