Post
Topic
Board Off-topic
Topic OP
Python API "UNICORN Binance WebSocket API"
by
alice_bob
on 04/06/2019, 13:42:03 UTC
Hello!

I would like to introduce a python API to manage binance websockets!

Project: https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api

Create a stable, fast and 100% reconnecting websocket connection to binance with just 4 lines of code:
Code:
from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import BinanceWebSocketApiManager
from unicorn_binance_websocket_api_process_streams import BinanceWebSocketApiProcessStreams

binance_websocket_api_manager = BinanceWebSocketApiManager(BinanceWebSocketApiProcessStreams.process_stream_data)
binance_websocket_api_manager.create_stream('trade', 'btcusdt')

Create a multiplex stream with:
Code:
markets = {'bnbbtc', 'ethbtc', 'btcusdt', 'bchabcusdt', 'xrpusdt', 'rvnbtc', 'ltcusdt', 'adausdt', 'eosusdt',
           'neobtc', 'adaeth', 'icxusdt', 'btctusd', 'icxbtc', 'btcusdc', 'wanbtc', 'zecbtc', 'wtcbtc',
           'batbtc', 'adabnb', 'etcusdt', 'qtumusdt', 'xmrbtc', 'trxeth', 'adatusd', 'trxxrp', 'trxbnb',
           'ltctusd', 'polybnb', 'scbtc', 'steembtc', 'trxtusd', 'npxseth', 'kmdbtc', 'polybtc', 'gasbtc',
           'bnbpax', 'linkusdt', 'hceth', 'zrxeth', 'icxeth', 'xmreth', 'neobnb', 'etceth', 'zeceth', 'xmrbnb'}
channels = {'trade', 'kline_1m', 'kline_5m', 'kline_15m', 'kline_30m', 'kline_1h', 'kline_12h', 'kline_1w',
            'miniTicker', 'depth20'}
binance_websocket_api_manager.create_stream(channels, markets)

The benefits of this package are:
- 100% auto-reconnect!
- Streams are processing asynchronous/concurrent (python asyncio) and each stream is started in a separate thread.
- No use of the twisted module, so you can use this lib in a daemonized application (compatible with python-daemon).
- If you can not store your data in cause of a temporary technical issue, you can kick back the data to the stream_buffer which stores the receives in the RAM till you are able to process the data in the normal way again.
- Helpful management features like get_binance_api_status(), get_stream_info(), get_stream_list(), get_stream_statistic(), is_websocket_uri_length_valid(), replace_stream(), wait_till_stream_has_started() and many more, explore them here.
- Monitoring API service and a check_command for ICINGA/Nagios

This example is an output of https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/blob/master/dev_test_full_non_stop.py


Documentation: https://oliver-zehentleitner.github.io/unicorn-binance-websocket-api/
Github: https://github.com/unicorn-data-analysis/unicorn-binance-websocket-api
PyPI: https://pypi.org/project/unicorn-binance-websocket-api/
Icinga Plugin: https://exchange.icinga.com/bithon/check_binance_websocket_api_manager

Best regards!