Icinga Plugin:


You can install the library with `pip install unicorn-binance-websocket-api` from PyPI or you download the latest release or the dev-stage. The easiest way to test the examples is to clone the repository from git with `git clone` to your local system.

How to use the class?

Import the `BinanceWebSocketApiManager` class:

from unicorn_binance_websocket_api.manager import BinanceWebSocketApiManager

Additionally we need more imports for this example:

import logging
import time
import os

Configure logging, to get a very verbose mode use DEBUG instead of INFO:

                    filename=os.path.basename(__file__) + '.log',
                    format="{asctime} [{levelname:8}] {process} {thread} {module}: {message}",

Create an instance of the `BinanceWebSocketApiManager` to connect to Binance (

ubwa = BinanceWebSocketApiManager(exchange="")

If you would like to use the Binance Jersey API then use:

ubwa = BinanceWebSocketApiManager(exchange="")

If you would like to use the Binance US API then use:

ubwa = BinanceWebSocketApiManager(exchange="")

For Binance DEX/chain use:

ubwa = BinanceWebSocketApiManager(exchange="")
ubwa = BinanceWebSocketApiManager(exchange="")

In this tutorial we continue with streams for (,,

Now define the channels and markets you wish to stream. In this example we define a multiplex stream with 3 channels and 5 markets, resulting in 15 different streams (in one multistream – only one connection) Unfortunately you can not receive !userData with the other streams combined and must be created as a single websocket stream. Be also aware, that Binance allows up to 1024 subscriptions in one stream, more subscriptions will lead to a crashed stream.

channels = {'trade', 'kline_5m', 'depth5'}
markets = {'bnbbtc', 'ethbtc', 'btcusdt', 'bchabcusdt', 'eosusdt'}

Then create and start the multiplex stream:

multi_stream_id = ubwa.create_stream(channels, markets)

And create a `!userData` stream:

user_data_stream_id = ubwa.create_stream('arr', '!userData', api_key="aaa", api_secret="bbb")

And a `!ticker` and `!miniTicker` stream:

ticker_stream_id = ubwa.create_stream(["arr"], ["!miniTicker"])
miniticker_stream_id = ubwa.create_stream(["arr"], ["!ticker"])

To watch what your streams are doing use:

while True:
print_summary() Image

Now your streams should be running, and everything happening with the received data is, its stored in the stream_buffer. To get and remove the oldest entry from the stream_buffer stack do:

oldest_stream_data_from_stream_buffer = ubwa.pop_stream_data_from_stream_buffer()

Then you can do with it what every you want. If your database is down for a restart or anything else, you can kick the data back to the stream_buffer with:


View this stream_buffer example!

If you would like to unify the received data with UnicornFy, please follow this guide.

Here are some working example files (just clone the repository and run them):