oliver-zehentleitner / unicorn-binance-websocket-api

A Python SDK to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.

Home Page:https://oliver-zehentleitner.github.io/unicorn-binance-websocket-api

Repository from Github https://github.comoliver-zehentleitner/unicorn-binance-websocket-apiRepository from Github https://github.comoliver-zehentleitner/unicorn-binance-websocket-api

Can't receive binance futures testnet userData stream

Mozilla88 opened this issue · comments

Version of this library.

unicorn-binance-websocket-api 1.46.1

Solution to Issue cannot be found in the documentation or other Issues and also occurs in the latest version of this library.

  • I checked the documentation and other Issues. I am using the latest version of this library.

Hardware?

Local server/workstation

Operating System?

macOS

Python version?

Python3.10

Installed packages

No response

Logging output

No response

Processing method?

stream_buffer

Used endpoint?

binance.com-futures-testnet

Issue

Hi Oliver,

When I run these test code on binance futures testnet, I can't get user data steam when I place a futures order.

def print_stream_buffer_data(binance_websocket_api_manager: BinanceWebSocketApiManager, stream_id: str, logger: Logger):
    while True:
        if binance_websocket_api_manager.is_manager_stopping():
            exit(0)
        oldest_stream_data_from_stream_buffer = binance_websocket_api_manager.pop_stream_data_from_stream_buffer(stream_id)
        if oldest_stream_data_from_stream_buffer is False:
            time.sleep(0.1)
        else:
            logger.info(oldest_stream_data_from_stream_buffer)

binance_com_websocket_api_manager = BinanceWebSocketApiManager(exchange="binance.com-futures-testnet", process_stream_signals=_process_stream_signals,  socks5_proxy_server="127.0.0.1:1086")

alice_api_key = ""
alice_api_secret = ""
# create the userData streams
alice_stream_id = binance_com_websocket_api_manager.create_stream(["arr"], ["!userData"], stream_label="Alice", stream_buffer_name=True, api_key=alice_api_key, api_secret=alice_api_secret)
# start a worker process to move the received stream_data from the stream_buffer to a print function
worker_thread = threading.Thread(target=print_stream_buffer_data, args=(binance_com_websocket_api_manager, alice_stream_id, logger))
worker_thread.start()

I solved the bug by myself. The bug is in restclient.py:

175,176c175
<             elif self.manager.exchange == "binance.com-futures" or \
<                     self.manager.exchange == "binance.com-futures-testnet":
---
>             elif self.manager.exchange == "binance.com-futures":
260,261c259
<             elif self.manager.exchange == "binance.com-futures" or \
<                     self.manager.exchange == "binance.com-futures-testnet":
---
>             elif self.manager.exchange == "binance.com-futures":

"binance.com-futures-testnet" is omitted here, so I can't get listen key for the user data stream.

I wish this small bug will be corrected in next version.

Good luck!

Thanks! Will be included in release 2.1.4! (released in a few hours)