Open naquad opened 3 years ago
python3 -m pip install unicorn-binance-websocket-api
#!/usr/bin/env python3
from pprint import pprint
from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import BinanceWebSocketApiManager
import logging
import time
logging.basicConfig(level=logging.INFO)
def event_printer(msg):
print('<<< socket event >>>', end='\r\n')
pprint(msg)
ubwa = BinanceWebSocketApiManager(exchange="binance.com-testnet")
ubwa.create_stream("depth", "BTCUSDT", output="dict")
while True:
received_data_record = ubwa.pop_stream_data_from_stream_buffer()
if received_data_record:
event_printer(received_data_record)
else:
time.sleep(0.01)
https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api
I don´t get why everyone knows the websockets in this repo are broken but does nothing about it... sigh, I guess I should stop complaining and do something myself
I would gladly merge in a fix for websocket. Otherwise, please use oliver-zehentleitner/unicorn-binance-websocket-api
for websocket
Would it be acceptable to add unicorn-binance-websocket-api as a dependency for this project? You guys seem to like it a lot
its not a dependency. websocket interface for this library is old, and unmaintained. unicorn is actively maintained.
in fact @oliver-zehentleitner is the maintainer of that library. lol
this repository is fully community driven and i only merge things in here and there. i would recommend unicorn lib for websockets.
I meant adding the unicorn library into python-binance as a dependency for the websocket part
I don't think that would be practical. Users already using the WS implementation of python-binance would not be able to update python-binance to access updates to the REST methods.
I rather play with the idea to fork python-binance and create a pure REST package. This would have the additional advantage that you could drop the support for <Python_3.5 and remove e.g. Twisted.
I wouldn´t change the architecture for the ws, any code using the broken classes are going to still work, but with unicorn under the hood... is this still impractical?
maybe then not, but ubwa would need an update to support python-binance structure of callback functions for each stream....
@badjano i dont think thats necessary. i recommend that if you need ws, add ubwa to your project as an additional dependency
python3 -m pip install unicorn-binance-websocket-api
#!/usr/bin/env python3 from pprint import pprint from unicorn_binance_websocket_api.unicorn_binance_websocket_api_manager import BinanceWebSocketApiManager import logging import time logging.basicConfig(level=logging.INFO) def event_printer(msg): print('<<< socket event >>>', end='\r\n') pprint(msg) ubwa = BinanceWebSocketApiManager(exchange="binance.com-testnet") ubwa.create_stream("depth", "BTCUSDT", output="dict") while True: received_data_record = ubwa.pop_stream_data_from_stream_buffer() if received_data_record: event_printer(received_data_record) else: time.sleep(0.01)
https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api
I tried the code but I get the following message once it enters the loop:
<<< socket event >>> {'id': 1, 'result': None}
Does this mean that there may be something wrong with the actual Testnet ?
Thanks.
Thats perfect :)
{'id': 1, 'result': None}
is the confirmation that Binance accepted the subscriptions: https://binance-docs.github.io/apidocs/spot/en/#live-subscribing-unsubscribing-to-streams
Thanks for the quick response!
The following code is made for python-binance version 0.7.5:
It behaves like it can't connect, but the same time using other tools to connect to the same URLs work as expected (wscat displays incoming depth events).