quantease-binance


Namequantease-binance JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryNone
upload_time2024-09-27 03:23:35
maintainerNone
docs_urlNone
authorriver
requires_python<4.0,>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## 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:

```python
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

```python
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

```python
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

```python
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

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

#### Fetch Klines Data

```python
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

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "quantease-binance",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "river",
    "author_email": "shinachuan@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e8/6f/c561851f674b0d908364a6dba5f677fe307da3db9568b480d4cc76e0e844/quantease_binance-0.1.2.tar.gz",
    "platform": null,
    "description": "## Project Description\n\nThis 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.\n\n### Usage\n\nTo 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:\n\n#### Fetch all the symbols\n\nTo fetch all symbols from the Binance exchange, you can use the `fetch_all_symbols` function. Here's an example of how to use it:\n\n```python\nimport quantease_binance as qb\n\nsymbols = qb.fetch_all_symbols()\nprint(symbols)\n```\n\nThis 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.\n\n#### Fetch Aggregated Trades Data\n\n```python\nimport binace_history as qb\n\nagg_trades = qb.fetch_agg_trades(\n    symbol='BTCUSDT',\n    start='2024-01-01',\n    end='2024-05-01',\n    asset_type='spot',\n    tz='UTC'\n)\nprint(agg_trades)\n```\n\n#### Fetch Book Ticker Data\n\n```python\nbook_ticker = qb.fetch_book_ticker(\n    symbol='AAVEUSD_PERP',\n    start='2024-01-01',\n    end='2024-02-01',\n    asset_type='futures/cm',\n    tz='UTC'\n)\nprint(book_ticker)\n```\n\n#### Fetch Funding Rate Data\n\n```python\nfunding_rate = qb.fetch_funding_rate(\n    symbol='ETHUSDT',\n    start='2019-01-01',\n    end='2024-07-01',\n    asset_type='futures/um',\n    tz='UTC'\n)\nprint(funding_rate)\n```\n\n#### Fetch Trades Data\n\n```python\ntrade = qb.fetch_trades(\n    symbol='ETHUSDT',\n    start='2024-05-01',\n    end='2024-07-10',\n    asset_type='spot',\n    tz='UTC'\n)\nprint(trade)\n```\n\n#### Fetch Klines Data\n\n```python\nklines = qb.fetch_klines(\n    symbol='BTCUSDT',\n    start='2018-01-01',\n    end='2024-07-12',\n    timeframe='1m',\n    asset_type='spot',\n    tz='UTC'\n)\nprint(klines)\n```\n\n#### Fetch Metrics Data\n\n```python\nmetrics = qb.fetch_metrics(\n    symbol='BTCUSDT',\n    start='2024-01-01',\n    end='2024-04-01',\n    asset_type='futures/um',\n    tz='UTC'\n)\nprint(metrics)\n```\n\nMake sure to replace the placeholders with the actual values for `symbol`, `start`, `end`, and other parameters as needed.\n\nMake sure you have the required dependencies installed (`pandas`, `pendulum`, `asyncio`, `uvloop`, `tqdm`) before running the code.\n\n### Function Documentation\n\n#### `fetch_klines`\n\nConvenience function for fetching klines data.\n\nParameters:\n- `symbol` (str): The Binance market pair name, e.g., \"BTCUSDT\".\n- `start` (str or datetime): The start datetime of the requested data.\n- `end` (str or datetime): The end datetime of the requested data.\n- `timeframe` (str, optional): The kline interval. Default is \"1m\".\n- `asset_type` (str, optional): The asset type of the requested data. Default is \"spot\".\n- `tz` (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.\n\nReturns:\n- `DataFrame`: A pandas dataframe with columns `open`, `high`, `low`, `close`, `volume`, `trades`, `close_datetime`.\n\n#### `fetch_trades`\n\nConvenience function for fetching trades data.\n\nParameters:\n- `symbol` (str): The Binance market pair name, e.g., \"BTCUSDT\".\n- `start` (str or datetime): The start datetime of the requested data.\n- `end` (str or datetime): The end datetime of the requested data.\n- `asset_type` (str, optional): The asset type of the requested data. Default is \"spot\".\n- `tz` (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.\n\nReturns:\n- `DataFrame`: A pandas dataframe with columns `id`, `price`, `qty`, `quoteQty`, `time`, `isBuyerMaker`, `isBestMatch`.\n\n#### `fetch_agg_trades`\n\nConvenience function for fetching aggregated trades data.\n\nParameters:\n- `symbol` (str): The Binance market pair name, e.g., \"BTCUSDT\".\n- `start` (str or datetime): The start datetime of the requested data.\n- `end` (str or datetime): The end datetime of the requested data.\n- `asset_type` (str, optional): The asset type of the requested data. Default is \"spot\".\n- `tz` (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.\n\nReturns:\n- `DataFrame`: A pandas dataframe with columns `id`, `price`, `qty`, `firstTradeId`, `lastTradeId`, `time`, `isBuyerMaker`, `isBestMatch`.\n\n#### `fetch_book_ticker`\n\nConvenience function for fetching book ticker data.\n\nParameters:\n- `symbol` (str): The Binance market pair name, e.g., \"BTCUSDT\".\n- `start` (str or datetime): The start datetime of the requested data.\n- `end` (str or datetime): The end datetime of the requested data.\n- `asset_type` (str, optional): The asset type of the requested data. Default is \"spot\".\n- `tz` (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.\n\nReturns:\n- `DataFrame`: A pandas dataframe with columns `symbol`, `bidPrice`, `bidQty`, `askPrice`, `askQty`, `time`.\n\n#### `fetch_funding_rate`\n\nConvenience function for fetching funding rate data.\n\nParameters:\n- `symbol` (str): The Binance market pair name, e.g., \"BTCUSDT\".\n- `start` (str or datetime): The start datetime of the requested data.\n- `end` (str or datetime): The end datetime of the requested data.\n- `asset_type` (str): The asset type of the requested data. Must be one of \"spot\", \"futures/um\", \"futures/cm\".\n- `tz` (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.\n\nReturns:\n- `DataFrame`: A pandas dataframe with columns `symbol`, `fundingRate`, `fundingTime`.\n\n#### `fetch_metrics`\n\nConvenience function for fetching metrics data.\n\nParameters:\n- `symbol` (str): The Binance market pair name, e.g., \"BTCUSDT\".\n- `start` (str or datetime): The start datetime of the requested data.\n- `end` (str or datetime): The end datetime of the requested data.\n- `asset_type` (str): The asset type of the requested data. Must be one of \"spot\", \"futures/um\", \"futures/cm\".\n- `tz` (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is None.\n\nReturns:\n- `DataFrame`: A pandas dataframe with columns `symbol`, `openInterest`, `numberOfTrades`, `volume`, `quoteVolume`, `takerBuyBaseAssetVolume`, `takerBuyQuoteAssetVolume`, `openTime`, `closeTime`.\n\n#### `fetch_data`\n\nMain function for fetching data.\n\nParameters:\n- `symbol` (str): The Binance market pair name, e.g., \"BTCUSDT\".\n- `asset_type` (str): The asset type of the requested data. Must be one of \"spot\", \"futures/um\", \"futures/cm\".\n- `data_type` (str): The type of requested data. Must be one of \"klines\", \"aggTrades\", \"bookTicker\", \"fundingRate\", \"metrics\".\n- `start` (datetime): The start datetime of the requested data.\n- `end` (datetime): The end datetime of the requested data.\n- `tz` (str, optional): Timezone of the datetime parameters and the returned dataframe. Default is \"UTC\".\n- `timeframe` (str, optional): The kline interval. Default is None.\n\nReturns:\n- `DataFrame`: A pandas dataframe with the requested data.\n\n#### `fetch_all_symbols`\n\nFunction to fetch all symbols from the Binance exchange.\n\nParameters:\n- `exchange` (object): The exchange object initialized with ccxt library. Default is `config.EXCHANGE`.\n- `asset_type` (str, optional): The asset type for which symbols are fetched. Must be one of \"spot\", \"futures/um\", \"futures/cm\". Default is \"spot\".\n\nReturns:\n- `List[str]`: A list of symbol IDs based on the specified `asset_type`.\n\n### Note\n\nThe 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.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "0.1.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed139fb211c5a8f3b49a10d0759c98be2f8d8b1339d7a2c36fde984806cba2f2",
                "md5": "4ef3ae9dad8f8f8c3b0e81e1bbac1c25",
                "sha256": "ef46539bd72fba933202869c807f366c7b17e11055ea9521687814a138c392e7"
            },
            "downloads": -1,
            "filename": "quantease_binance-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4ef3ae9dad8f8f8c3b0e81e1bbac1c25",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 10162,
            "upload_time": "2024-09-27T03:23:33",
            "upload_time_iso_8601": "2024-09-27T03:23:33.276485Z",
            "url": "https://files.pythonhosted.org/packages/ed/13/9fb211c5a8f3b49a10d0759c98be2f8d8b1339d7a2c36fde984806cba2f2/quantease_binance-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e86fc561851f674b0d908364a6dba5f677fe307da3db9568b480d4cc76e0e844",
                "md5": "a239bbb25072492fe6219b86efda0e11",
                "sha256": "5cbed9302b685d7fde28a3addd6868241a03b23ffecd79277ed2813379127879"
            },
            "downloads": -1,
            "filename": "quantease_binance-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "a239bbb25072492fe6219b86efda0e11",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 9834,
            "upload_time": "2024-09-27T03:23:35",
            "upload_time_iso_8601": "2024-09-27T03:23:35.025043Z",
            "url": "https://files.pythonhosted.org/packages/e8/6f/c561851f674b0d908364a6dba5f677fe307da3db9568b480d4cc76e0e844/quantease_binance-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-27 03:23:35",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "quantease-binance"
}
        
Elapsed time: 0.79369s