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: Optional[int] = None, default_update_interval: Optional[int] = None, default_websocket_close_timeout: int = 2, default_websocket_ping_interval: int = 5, default_websocket_ping_timeout: int = 10, disable_colorama: bool = False, ubra_manager: Optional[Union[unicorn_binance_rest_api.manager.BinanceRestApiManager, bool]] = False, ubwa_manager: Optional[Union[unicorn_binance_websocket_api.manager.BinanceWebSocketApiManager, bool]] = False, warn_on_update: bool = True)

Bases: threading.Thread

A local Binance DepthCache Manager for Python that supports multiple depth caches in one instance in a 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

  • 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: Optional[Union[str, list]] = None, update_interval: Optional[int] = None, refresh_interval: Optional[int] = None, websocket_close_timeout: Optional[int] = None, websocket_ping_interval: Optional[int] = None, websocket_ping_timeout: Optional[int] = None) bool

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: Optional[str] = None) list

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: Optional[str] = None) list

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() Optional[dict]

Get info about the latest available release

Returns

dict or None

get_latest_version() str

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

Returns

str

get_list_of_depth_caches() list

Get a list of existing depth caches

Returns

list

get_user_agent()

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

Returns

get_version() str

Get the package/module version

Returns

str

is_depth_cache_synchronized(market: Optional[str] = None) bool

Is a specific depth_cache synchronized?

Parameters

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

Returns

bool

is_stop_request(market: Optional[str] = None) bool

Is there a stop request?

Parameters

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

Returns

bool

is_update_available() bool

Is a new release of this package available?

Returns

bool

print_summary(add_string=None)

Print an overview of all streams

Parameters

add_string (str) – text to add to the output

set_refresh_request(markets: Optional[Union[str, list]] = None) bool

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: Optional[Union[str, list]] = None) bool

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_with_all_depth_caches() bool

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

Returns

bool

unicorn_binance_local_depth_cache.unicorn_binance_local_depth_cache_exceptions module

exception unicorn_binance_local_depth_cache.exceptions.DepthCacheOutOfSync

Bases: Exception

Exception if a DepthCache is out of sync

Module contents