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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: quantease_binance-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5cbed9302b685d7fde28a3addd6868241a03b23ffecd79277ed2813379127879
MD5 a239bbb25072492fe6219b86efda0e11
BLAKE2b-256 e86fc561851f674b0d908364a6dba5f677fe307da3db9568b480d4cc76e0e844

See more details on using hashes here.

File details

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

File metadata

  • Download URL: quantease_binance-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ef46539bd72fba933202869c807f366c7b17e11055ea9521687814a138c392e7
MD5 4ef3ae9dad8f8f8c3b0e81e1bbac1c25
BLAKE2b-256 ed139fb211c5a8f3b49a10d0759c98be2f8d8b1339d7a2c36fde984806cba2f2

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