unicorn_binance_local_depth_cache package

Submodules

unicorn_binance_local_depth_cache.unicorn_binance_local_depth_cache_manager module

class unicorn_binance_local_depth_cache.manager.BinanceLocalDepthCacheManager(exchange: str = 'binance.com', default_refresh_interval: int | None = None, default_update_interval: int | None = None, default_websocket_close_timeout: int = 2, default_websocket_ping_interval: int = 5, default_websocket_ping_timeout: int = 10, disable_colorama: bool = False, lucit_api_secret: str | None = None, lucit_license_ini: str | None = None, lucit_license_profile: str | None = None, lucit_license_token: str | None = None, ubra_manager: BinanceRestApiManager | None = None, ubwa_manager: BinanceWebSocketApiManager | None = None, warn_on_update: bool = True)[source]

Bases: Thread

A local Binance DepthCache Manager for Python that supports multiple depth caches in one instance in an easy, fast, flexible, robust and fully-featured way.

Binance API documentation: https://developers.binance.com/docs/binance-api/spot-detail/web-socket-streams#diff-depth-stream https://binance-docs.github.io/apidocs/futures/en/#diff-book-depth-streams

Parameters:
  • exchange (str) – Select binance.com, binance.com-testnet, binance.com-margin, binance.com-margin-testnet, binance.com-isolated_margin, binance.com-isolated_margin-testnet, binance.com-futures, binance.com-futures-testnet, binance.com-coin_futures, binance.us, trbinance.com, jex.com, binance.org or binance.org-testnet (default: binance.com)

  • default_refresh_interval (int) – The default refresh interval in seconds, default is None.

  • default_update_interval (int) – Update speed of the depth webstream in milliseconds. More info: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-local-depth-cache/wiki/update_intervals This can be overwritten with update_interval of create_depth_cache().

  • default_websocket_close_timeout (int) – The close_timeout parameter defines a maximum wait time in seconds for completing the closing handshake and terminating the TCP connection. This parameter is passed through to the websockets.client.connect()

  • default_websocket_ping_interval (int) –

    Once the connection is open, a Ping frame is sent every ping_interval seconds. This serves as a keepalive. It helps keeping the connection open, especially in the presence of proxies with short timeouts on inactive connections. Set ping_interval to None to disable this behavior. This parameter is passed through to the websockets.client.connect()

  • default_websocket_ping_timeout (int) –

    If the corresponding Pong frame isn’t received within ping_timeout seconds, the connection is considered unusable and is closed with code 1011. This ensures that the remote endpoint remains responsive. Set ping_timeout to None to disable this behavior. This parameter is passed through to the websockets.client.connect()

  • disable_colorama (bool) – set to True to disable the use of colorama

  • warn_on_update (bool) – set to False to disable the update warning

  • lucit_api_secret (str) – The api_secret of your UNICORN Binance Suite license from https://shop.lucit.services/software/unicorn-binance-suite

  • lucit_license_ini (str) – Specify the path including filename to the config file (ex: ~/license_a.ini). If not provided lucitlicmgr tries to load a lucit_license.ini from /home/oliver/.lucit/.

  • lucit_license_profile (str) – The license profile to use. Default is ‘LUCIT’.

  • lucit_license_token (str) – The license_token of your UNICORN Binance Suite license from https://shop.lucit.services/software/unicorn-binance-suite

  • ubra_manager (BinanceRestApiManager) – Provide a shared unicorn_binance_rest_api.manager instance

  • ubwa_manager (BinanceWebSocketApiManager) – Provide a shared unicorn_binance_websocket_api.manager instance. Use enable_stream_signal_buffer=True otherwise the depth_cache will not work as it should!

create_depth_cache(markets: str | list | None = None, update_interval: int | None = None, refresh_interval: int | None = None, websocket_close_timeout: int | None = None, websocket_ping_interval: int | None = None, websocket_ping_timeout: int | None = None) bool[source]

Create one or more depth_cache!

Parameters:
  • markets (str or list) – Specify the market symbols for caches to be created

  • update_interval (int) – Update speed of the depth webstream in milliseconds. More info: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-local-depth-cache/wiki/update_intervals

  • refresh_interval (int) – The refresh interval in seconds, default is the default_refresh_interval of BinanceLocalDepthCache.

  • websocket_close_timeout (int) –

    The close_timeout parameter defines a maximum wait time in seconds for completing the closing handshake and terminating the TCP connection. This parameter is passed through to the websockets.client.connect()

  • websocket_ping_interval (int) –

    Once the connection is open, a Ping frame is sent every ping_interval seconds. This serves as a keepalive. It helps keeping the connection open, especially in the presence of proxies with short timeouts on inactive connections. Set ping_interval to None to disable this behavior. This parameter is passed through to the websockets.client.connect()

  • websocket_ping_timeout (int) –

    If the corresponding Pong frame isn’t received within ping_timeout seconds, the connection is considered unusable and is closed with code 1011. This ensures that the remote endpoint remains responsive. Set ping_timeout to None to disable this behavior. This parameter is passed through to the websockets.client.connect()

Returns:

bool

get_asks(market: str | None = None) list[source]

Get the current list of asks with price and quantity.

Parameters:

market (str) – Specify the market symbol for the used depth_cache

Returns:

list

get_bids(market: str | None = None) list[source]

Get the current list of bids with price and quantity.

Parameters:

market (str) – Specify the market symbol for the used depth_cache

Returns:

list

static get_latest_release_info() dict | None[source]

Get info about the latest available release

Returns:

dict or None

get_latest_version() str[source]

Get the version of the latest available release (cache time 1 hour)

Returns:

str

get_list_of_depth_caches() list[source]

Get a list of existing depth caches

Returns:

list

get_user_agent()[source]

Get the user_agent string “lib name + lib version + python version”

Returns:

get_version() str[source]

Get the package/module version

Returns:

str

is_depth_cache_synchronized(market: str | None = None) bool[source]

Is a specific depth_cache synchronized?

Parameters:

market (str) – Specify the market symbol for the used depth_cache

Returns:

bool

is_stop_request(market: str | None = None) bool[source]

Is there a stop request?

Parameters:

market (str) – Specify the market symbol for the used depth_cache

Returns:

bool

is_update_available() bool[source]

Is a new release of this package available?

Returns:

bool

print_summary(add_string=None)[source]

Print an overview of all streams

Parameters:

add_string (str) – text to add to the output

set_refresh_request(markets: str | list | None = None) bool[source]

Set refresh requests for one or more depth_caches!

Parameters:

markets (str or list) – Specify the market symbols for the depth_caches to be refreshed

Returns:

bool

stop_depth_cache(markets: str | list | None = None) bool[source]

Stop and delete one or more depth_caches!

Parameters:

markets (str or list) – Specify the market symbols for the depth_caches to be stopped and deleted

Returns:

bool

stop_manager(close_api_session: bool = True) bool[source]

Stop unicorn-binance-local-depth-cache with all sub routines

Returns:

bool

stop_manager_with_all_depth_caches() bool[source]

Alias of stop_manager().

Returns:

bool

unicorn_binance_local_depth_cache.unicorn_binance_local_depth_cache_exceptions module

exception unicorn_binance_local_depth_cache.exceptions.DepthCacheOutOfSync[source]

Bases: Exception

Exception if a DepthCache is out of sync

Module contents