LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT 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.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
677 stars 166 forks source link

issue with separation of spot and margin accounts #331

Closed aleangelin88 closed 1 year ago

aleangelin88 commented 1 year ago

Version of this library.

tried with:

unicorn-binance-rest-api 1.9.0 unicorn-binance-websocket-api 1.45.2

unicorn-binance-rest-api 1.9.0 unicorn-binance-websocket-api 1.46.0

both version have issues

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

Hardware?

Local server/workstation

Operating System?

Windows

Python version?

Python3.10

Installed packages

No response

Logging output

No response

Processing method?

stream_buffer

Used endpoint?

concerns all

Issue

the stream from binance.com and binance,com-margin are mixed. notifications on spot account (binance.com) get DOUBLE broadcasted to BOTH channels created with Create_stream(["arr"], ["!userData"]) on binance.com AND binance.com-margin NO notification arrives for events on margin account

I tested the behavior with: unicorn-binance-rest-api 1.9.0 unicorn-binance-websocket-api 1.45.2 and unicorn-binance-rest-api 1.9.0 unicorn-binance-websocket-api 1.46.0

both versions have issue

version 1.41.0 has no issue from my testing

below is my script and testing

Script

(I removed the keys, but they were provided during testing)


from unicorn_binance_websocket_api import BinanceWebSocketApiManager

API_key_orders = ""
secret_key_orders = ""

API_key_general = ""
secret_key_general = ""

account_handling = {}

account_handling['spot_user_data'] = BinanceWebSocketApiManager(exchange="binance.com")
account_handling['spot_user_data'].create_stream(["arr"], ["!userData"], api_key=API_key_general, api_secret=secret_key_general)
account_handling['margin_user_data'] = BinanceWebSocketApiManager(exchange="binance.com-margin")
account_handling['margin_user_data'].create_stream(["arr"], ["!userData"], api_key=API_key_general, api_secret=secret_key_general)

print("Starting streams")
while True:
    for account_type in ["spot","margin"]:
        current_info_user_data = account_handling[f'{account_type}_user_data'].pop_stream_data_from_stream_buffer()
        if current_info_user_data:
            print(f"{account_type}: {current_info_user_data}")

Testing with 1.41.0

WORKING (margin order shows in margin stream and spot order in spot stream)

Release unicorn-binance-websocket-api_1.46.0 is available, please consider updating! (Changelog: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/blob/master/CHANGELOG.md) Release unicorn-binance-websocket-api_1.46.0 is available, please consider updating! (Changelog: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/blob/master/CHANGELOG.md) BinanceWebSocketApiConnection.receive(9383cade2415-2a42-28d9-d672-52c2ad29) socket_id=3f7169bf-95d3-4f36-b9cf-8b79d109bf11) - Adding timeout to websocket.recv() Release unicorn-binance-websocket-api_1.46.0 is available, please consider updating! (Changelog: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/blob/master/CHANGELOG.md) Release unicorn-binance-websocket-api_1.46.0 is available, please consider updating! (Changelog: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/blob/master/CHANGELOG.md) BinanceWebSocketApiConnection.receive(8294e2f94dcf-5166-3fcd-f3b2-98448451) socket_id=fd5dc60e-e625-47db-a1d6-8ad2ae61b23b) - Adding timeout to websocket.recv() Starting streams In case of order on margin margin: {"e":"executionReport","E":1681707734380,"s":"ETHBUSD","c":"ios_553fe230226b400d986749e8ee725898","S":"SELL","o":"MARKET","f":"GTC","q":"0.01430000","p":"0.00000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"NEW","X":"NEW","r":"NONE","i":7070709767,"l":"0.00000000","z":"0.00000000","L":"0.00000000","n":"0","N":null,"T":1681707734380,"t":-1,"I":14562424595,"w":true,"m":false,"M":false,"O":1681707734380,"Z":"0.00000000","Y":"0.00000000","Q":"0.00000000","W":1681707734380,"V":"NONE"} margin: {"e":"executionReport","E":1681707734380,"s":"ETHBUSD","c":"ios_553fe230226b400d986749e8ee725898","S":"SELL","o":"MARKET","f":"GTC","q":"0.01430000","p":"0.00000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"TRADE","X":"FILLED","r":"NONE","i":7070709767,"l":"0.01430000","z":"0.01430000","L":"2099.02000000","n":"0.00006483","N":"BNB","T":1681707734380,"t":474862380,"I":14562424596,"w":false,"m":false,"M":true,"O":1681707734380,"Z":"30.01598600","Y":"30.01598600","Q":"0.00000000","W":1681707734380,"V":"NONE"} margin: {"e":"outboundAccountPosition","E":1681707734380,"u":1681707734380,"B":[{"a":"ETH","f":"0.00000000","l":"0.00000000"},{"a":"BNB","f":"0.26107951","l":"0.00000000"},{"a":"BUSD","f":"30.01598600","l":"0.00000000"}]} In case of order on spot spot: {"e":"executionReport","E":1681707748197,"s":"BUSDUSDT","c":"XXX","S":"SELL","o":"MARKET","f":"GTC","q":"25.00000000","p":"0.00000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"NEW","X":"NEW","r":"NONE","i":949905345,"l":"0.00000000","z":"0.00000000","L":"0.00000000","n":"0","N":null,"T":1681707748197,"t":-1,"I":2333504421,"w":true,"m":false,"M":false,"O":1681707748197,"Z":"0.00000000","Y":"0.00000000","Q":"0.00000000","W":1681707748197,"V":"NONE"} spot: {"e":"executionReport","E":1681707748197,"s":"BUSDUSDT","c":"XXX","S":"SELL","o":"MARKET","f":"GTC","q":"25.00000000","p":"0.00000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"TRADE","X":"FILLED","r":"NONE","i":949905345,"l":"25.00000000","z":"25.00000000","L":"0.99960000","n":"0.00000000","N":"BNB","T":1681707748197,"t":433746442,"I":2333504422,"w":false,"m":false,"M":true,"O":1681707748197,"Z":"24.99000000","Y":"24.99000000","Q":"0.00000000","W":1681707748197,"V":"NONE"} spot: {"e":"outboundAccountPosition","E":1681707748197,"u":1681707748197,"B":[{"a":"BNB","f":"0.07005597","l":"0.00000000"},{"a":"USDT","f":"232.08484900","l":"0.00000000"},{"a":"BUSD","f":"319.92592704","l":"0.00000000"}]}

Testing with 1.46.0

**NOT working

unicorn-binance-rest-api 1.9.0 unicorn-binance-websocket-api 1.46.0

Starting streams In case of order on spot spot: {"e":"executionReport","E":1681707899279,"s":"BUSDUSDT","c":"XXX","S":"SELL","o":"MARKET","f":"GTC","q":"25.00000000","p":"0.00000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"NEW","X":"NEW","r":"NONE","i":949906278,"l":"0.00000000","z":"0.00000000","L":"0.00000000","n":"0","N":null,"T":1681707899279,"t":-1,"I":2333506746,"w":true,"m":false,"M":false,"O":1681707899279,"Z":"0.00000000","Y":"0.00000000","Q":"0.00000000","W":1681707899279,"V":"NONE"} margin: {"e":"executionReport","E":1681707899279,"s":"BUSDUSDT","c":"XXX","S":"SELL","o":"MARKET","f":"GTC","q":"25.00000000","p":"0.00000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"NEW","X":"NEW","r":"NONE","i":949906278,"l":"0.00000000","z":"0.00000000","L":"0.00000000","n":"0","N":null,"T":1681707899279,"t":-1,"I":2333506746,"w":true,"m":false,"M":false,"O":1681707899279,"Z":"0.00000000","Y":"0.00000000","Q":"0.00000000","W":1681707899279,"V":"NONE"} spot: {"e":"executionReport","E":1681707899279,"s":"BUSDUSDT","c":"XXX","S":"SELL","o":"MARKET","f":"GTC","q":"25.00000000","p":"0.00000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"TRADE","X":"FILLED","r":"NONE","i":949906278,"l":"25.00000000","z":"25.00000000","L":"0.99960000","n":"0.00000000","N":"BNB","T":1681707899279,"t":433746902,"I":2333506747,"w":false,"m":false,"M":true,"O":1681707899279,"Z":"24.99000000","Y":"24.99000000","Q":"0.00000000","W":1681707899279,"V":"NONE"} margin: {"e":"executionReport","E":1681707899279,"s":"BUSDUSDT","c":"XXX","S":"SELL","o":"MARKET","f":"GTC","q":"25.00000000","p":"0.00000000","P":"0.00000000","F":"0.00000000","g":-1,"C":"","x":"TRADE","X":"FILLED","r":"NONE","i":949906278,"l":"25.00000000","z":"25.00000000","L":"0.99960000","n":"0.00000000","N":"BNB","T":1681707899279,"t":433746902,"I":2333506747,"w":false,"m":false,"M":true,"O":1681707899279,"Z":"24.99000000","Y":"24.99000000","Q":"0.00000000","W":1681707899279,"V":"NONE"} spot: {"e":"outboundAccountPosition","E":1681707899279,"u":1681707899279,"B":[{"a":"BNB","f":"0.07005597","l":"0.00000000"},{"a":"USDT","f":"257.07484900","l":"0.00000000"},{"a":"BUSD","f":"294.92592704","l":"0.00000000"}]} margin: {"e":"outboundAccountPosition","E":1681707899279,"u":1681707899279,"B":[{"a":"BNB","f":"0.07005597","l":"0.00000000"},{"a":"USDT","f":"257.07484900","l":"0.00000000"},{"a":"BUSD","f":"294.92592704","l":"0.00000000"}]} In case of order on margin

oliver-zehentleitner commented 1 year ago

Please try: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/releases/tag/1.46.1

aleangelin88 commented 1 year ago

nice job, it seems be working now after one testing. I will test more and let you know in case anything comes up. if not, you can consider it fixed. I would deprecate 1.46.0 maybe? thank you again

oliver-zehentleitner commented 1 year ago

Thank you! I personally would love to delete all old versions and only let people install the latest one, but other devs see that different. :D

Please reopen/post if you neeed it. I will close this. Thanks for reporting that bug!

aleangelin88 commented 1 year ago

I see :D Sure, I will reopen in case I need. Thanks again