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
678 stars 166 forks source link

Futures markprice @1s #101

Closed slipp1 closed 3 years ago

slipp1 commented 3 years ago

Hi, Im trying to subscribe to this stream: !markPrice@arr@1s and I can't figure out a way. https://binance-docs.github.io/apidocs/futures/en/#mark-price-stream-for-all-market

This works, but it updates every 3seconds: binance_websocket_api_manager.create_stream(['arr'], ['!markPrice'])

Also, specifying the market it works in both cases (3seconds and 1second): binance_websocket_api_manager.create_stream(['markPrice'], ['btcusdt', 'ethusdt'] binance_websocket_api_manager.create_stream(['markPrice@1s'], ['btcusdt', 'ethusdt']

I've tried a lot of combinations including the @1s after the 'arr' parameter but haven't got it working.

Any help appreciated, for the time being Im specifying each symbol, but the 'arr' stream would be way easier for my code. Thanks.

oliver-zehentleitner commented 3 years ago

Hm.

Something similar I am doing here: https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/blob/master/example_stream_everything.py#L73

But I think we need to extend to code to be able to do what you want: create_payload() in the section for centralized exchanges (cex): https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/blob/master/unicorn_binance_websocket_api/unicorn_binance_websocket_api_manager.py#L695

slipp1 commented 3 years ago

Thanks for the quick reply! I got it working by adding @1s after each case of @arr in unicorn_binance_websocket_api_manager.py.

However, Im pretty sure that's not the proper way to do it, since it will create problems with other streams. But it's a work around in my case for now. Thank you so much.

oliver-zehentleitner commented 3 years ago

Really? Thats great!

I think its good if you make dedicated streams. If you mix different kinds of streams they start much more than if you make dedicated streams by stream type.

kimchirichie commented 3 years ago

i am also experiencing the same problem. I am unable to subscribe to !markPrice@arr@1s

oliver-zehentleitner commented 3 years ago

Try this: binance_websocket_api_manager.create_stream(["!markPrice"], "arr@1s", stream_label="!markPrice@arr@1s")

kimchirichie commented 3 years ago

as example, i am subscribing like so:

self.__futures_socket.create_stream(["!markPrice"], "arr@1s", stream_label="!markPrice@arr@1s")

starting a thread like so:

self.__futures_socket_worker_thread = Thread(target=self.__futures_socket_thread)

thread reading the buffer like so:

def __futures_socket_thread(self):
    while not self.__futures_socket.is_manager_stopping():
        oldest_stream_data_from_stream_buffer = self.__futures_socket.pop_stream_data_from_stream_buffer()
        if oldest_stream_data_from_stream_buffer is False:
            self.__exit.wait(0.01)
            continue

        buffer = json.loads(oldest_stream_data_from_stream_buffer)
        if 'stream' in buffer and buffer['stream'] == '!markPrice@arr':
            print(time.time())
            for data in buffer['data']:
                self.__mark_price_callback(data)
        elif 'e' not in buffer and 'u' in buffer:
            self.__future_price_callback(buffer)

i get a print out of:

...
1599950172.358498
1599950175.1926148
1599950178.342974
1599950181.542018
1599950184.241941
...

printing time every 3s

using v1.16.9

i would like request reopening this issue

oliver-zehentleitner commented 3 years ago

Is very possible that, the lib replace arr@1s with arr.

Please create the stream and then use get_stream_subscriptions(stream_id) - this will return, the subscription accepted by binance... Please post me that result!

slipp1 commented 3 years ago

This is how I got it working on my end:

  1. Edited lines 703 and 708 in unicorn_binance_websocket_api_manager.py with: L703: params.append(channel + "@arr@1s") L708: params.append(market + "@arr@1s")
  2. Subscribed using: binance_websocket_api_manager.create_stream(['arr@1s'], ['!markPrice'])

I have got no issues so far.

oliver-zehentleitner commented 3 years ago

It will be supported with the next release!

oliver-zehentleitner commented 3 years ago

https://github.com/oliver-zehentleitner/unicorn-binance-websocket-api/releases/tag/1.17.0

RichestSmoke commented 1 year ago

binance_websocket_api_manager.create_stream(["!markPrice"], "arr@1s", stream_label="!markPrice@arr@1s") this stream takes price information from all coins, how to make it work for only one coin?