Skip to content

binance module

Module with BinanceData.


BinanceData class

BinanceData(
    wrapper,
    data,
    single_key=True,
    classes=None,
    level_name=None,
    fetch_kwargs=None,
    returned_kwargs=None,
    last_index=None,
    delisted=None,
    tz_localize=None,
    tz_convert=None,
    missing_index=None,
    missing_columns=None,
    **kwargs
)

Data class for fetching from Binance.

See https://github.com/sammchardy/python-binance for API.

See BinanceData.fetch_symbol() for arguments.

Note

If you are using an exchange from the US, Japan or other TLD then make sure pass tld="us" in client_config when creating the client.

Usage

  • Set up the API key globally (optional):
>>> from vectorbtpro import *

>>> vbt.BinanceData.set_custom_settings(
...     client_config=dict(
...         api_key="YOUR_KEY",
...         api_secret="YOUR_SECRET"
...     )
... )
  • Pull data:
>>> data = vbt.BinanceData.pull(
...     "BTCUSDT",
...     start="2020-01-01",
...     end="2021-01-01",
...     timeframe="1 day"
... )

Superclasses

Inherited members


feature_config class variable

Column config of BinanceData.

HybridConfig({
    'Quote volume': dict(
        resample_func=<function BinanceData.<lambda> at 0x15f9e6840>
    ),
    'Taker base volume': dict(
        resample_func=<function BinanceData.<lambda> at 0x15f9e68e0>
    ),
    'Taker quote volume': dict(
        resample_func=<function BinanceData.<lambda> at 0x15f9e6980>
    )
})

Returns BinanceData._feature_config, which gets (hybrid-) copied upon creation of each instance. Thus, changing this config won't affect the class.

To change fields, you can either change the config in-place, override this property, or overwrite the instance variable BinanceData._feature_config.


fetch_symbol class method

BinanceData.fetch_symbol(
    symbol,
    client=None,
    client_config=None,
    start=None,
    end=None,
    timeframe=None,
    tz=None,
    klines_type=None,
    limit=None,
    delay=None,
    show_progress=None,
    pbar_kwargs=None,
    silence_warnings=None,
    **get_klines_kwargs
)

Override Data.fetch_symbol() to fetch a symbol from Binance.

Args

symbol : str
Symbol.
client : binance.client.Client

Client.

See BinanceData.resolve_client().

client_config : dict

Client config.

See BinanceData.resolve_client().

start : any

Start datetime.

See to_tzaware_datetime().

end : any

End datetime.

See to_tzaware_datetime().

timeframe : str

Timeframe.

Allows human-readable strings such as "15 minutes".

tz : any

Timezone.

See to_timezone().

klines_type : int or str

Kline type.

See binance.enums.HistoricalKlinesType. Supports strings.

limit : int
The maximum number of returned items.
delay : float
Time to sleep after each request (in seconds).
show_progress : bool
Whether to show the progress bar.
pbar_kwargs : dict
Keyword arguments passed to ProgressBar.
silence_warnings : bool
Whether to silence all warnings.
**get_klines_kwargs
Keyword arguments passed to binance.client.Client.get_klines.

For defaults, see custom.binance in data.


list_symbols class method

BinanceData.list_symbols(
    pattern=None,
    use_regex=False,
    sort=True,
    client=None,
    client_config=None
)

List all symbols.

Uses CustomData.key_match() to check each symbol against pattern.


resolve_client class method

BinanceData.resolve_client(
    client=None,
    **client_config
)

Resolve the client.

If provided, must be of the type binance.client.Client. Otherwise, will be created using client_config.