Skip to main content

No project description provided

Project description

Project Description

This project provides a Python API for fetching historical data from the Binance exchange. It includes functions for fetching klines, trades, aggregated trades, book ticker data, funding rates, and metrics.

Usage

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

Fetch all the symbols

To fetch all symbols from the Binance exchange, you can use the fetch_all_symbols function. Here's an example of how to use it:

import quantease_binance as qb

symbols = qb.fetch_all_symbols()
print(symbols)

This will return a list of symbols based on the specified asset_type. By default, the asset_type is set to "spot". If you want to fetch symbols for perp futures contracts, you can specify the asset_type as "futures/um" for linear contracts or "futures/cm" for inverse contracts.

Fetch Aggregated Trades Data

import binace_history 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 Trades Data

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

Fetch Klines 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 with the actual values for symbol, start, end, and other parameters as needed.

Make sure you have the required dependencies installed (pandas, pendulum, asyncio, uvloop, tqdm) before running the code.

Function Documentation

fetch_klines

Convenience function for fetching klines data.

Parameters:

  • symbol (str): The Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): The start datetime of the requested data.
  • end (str or datetime): The end datetime of the requested data.
  • timeframe (str, optional): The kline interval. Default is "1m".
  • asset_type (str, optional): The asset type of the requested data. Default is "spot".
  • tz (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.

Returns:

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

fetch_trades

Convenience function for fetching trades data.

Parameters:

  • symbol (str): The Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): The start datetime of the requested data.
  • end (str or datetime): The end datetime of the requested data.
  • asset_type (str, optional): The asset type of the requested data. Default is "spot".
  • tz (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.

Returns:

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

fetch_agg_trades

Convenience function for fetching aggregated trades data.

Parameters:

  • symbol (str): The Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): The start datetime of the requested data.
  • end (str or datetime): The end datetime of the requested data.
  • asset_type (str, optional): The asset type of the requested data. Default is "spot".
  • tz (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.

Returns:

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

fetch_book_ticker

Convenience function for fetching book ticker data.

Parameters:

  • symbol (str): The Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): The start datetime of the requested data.
  • end (str or datetime): The end datetime of the requested data.
  • asset_type (str, optional): The asset type of the requested data. Default is "spot".
  • tz (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.

Returns:

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

fetch_funding_rate

Convenience function for fetching funding rate data.

Parameters:

  • symbol (str): The Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): The start datetime of the requested data.
  • end (str or datetime): The end datetime of the requested data.
  • asset_type (str): The asset type of the requested data. Must be one of "spot", "futures/um", "futures/cm".
  • tz (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.

Returns:

  • DataFrame: A pandas dataframe with columns symbol, fundingRate, fundingTime.

fetch_metrics

Convenience function for fetching metrics data.

Parameters:

  • symbol (str): The Binance market pair name, e.g., "BTCUSDT".
  • start (str or datetime): The start datetime of the requested data.
  • end (str or datetime): The end datetime of the requested data.
  • asset_type (str): The asset type of the requested data. Must be one of "spot", "futures/um", "futures/cm".
  • tz (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.

Returns:

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

fetch_data

Main function for fetching data.

Parameters:

  • symbol (str): The Binance market pair name, e.g., "BTCUSDT".
  • asset_type (str): The asset type of the requested data. Must be one of "spot", "futures/um", "futures/cm".
  • data_type (str): The type of requested data. Must be one of "klines", "aggTrades", "bookTicker", "fundingRate", "metrics".
  • start (datetime): The start datetime of the requested data.
  • end (datetime): The end datetime of the requested data.
  • tz (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is "UTC".
  • timeframe (str, optional): The kline interval. Default is None.

Returns:

  • DataFrame: A pandas dataframe with the requested data.

fetch_all_symbols

Function to fetch all symbols from the Binance exchange.

Parameters:

  • exchange (object): The exchange object initialized with ccxt library. Default is config.EXCHANGE.
  • asset_type (str, optional): The asset type for which symbols are fetched. Must be one of "spot", "futures/um", "futures/cm". Default is "spot".

Returns:

  • List[str]: A list of symbol IDs based on the specified asset_type.

Note

The functions in this API require the quantease_binance.utils module and the gen_dates, get_data, unify_datetime, and get_data_async functions from it. Make sure 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.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

quantease_binance-0.1.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quantease_binance-0.1.1.tar.gz
  • Upload date:
  • Size: 9.8 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.1.tar.gz
Algorithm Hash digest
SHA256 e908c4b3b9636f660b012641c0c68aaaa147fb71cfdc27cadbfbc165de94bfc6
MD5 b3147db51fb65f80cdee09a765d589b4
BLAKE2b-256 fe9eb3a3bbaa0181451ff19ad8f0d55e6276415de484bb9f41d4d7a41874d4dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quantease_binance-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a34b832e622725ef2d407be824569f457f6f2e896c34489fd0f4a7807e74f2f
MD5 bc88aa0dd4514aeba82774948558b314
BLAKE2b-256 de4f1131e69ced1c3e667bdcb2a4a1c21c427fce5b16ab96aa6edfabf047cadf

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