binance-rs-async icon indicating copy to clipboard operation
binance-rs-async copied to clipboard

Is futures websocket stream not implemented?

Open SpaceMonkeyForever opened this issue 1 year ago • 3 comments

I see the endpoint is available in the code but it is not used anywhere, spot endpoint is used by default in connect and connect_multiple.

SpaceMonkeyForever avatar Aug 10 '22 22:08 SpaceMonkeyForever

I think it's not implemented. I also need this feature, and I am currently working on it.

It's going smooth so far, but it will still take some time to do it right, especially since I'm new with Rust.

fdary avatar Aug 11 '22 14:08 fdary

I actually managed to get it working yesterday by just changing the URL.

However, I didn't have time to look into whether the library is building the orderbook from deltas or just getting the entire orderbook every time because that wouldn't be very efficient. Do you know? I don't even know if Binance supports sending orderbook deltas to avoid sending the entire book every 100 ms

SpaceMonkeyForever avatar Aug 11 '22 14:08 SpaceMonkeyForever

I don't use the orderbooks in my application. Fom what I understood you can ask for the orderbook of a market, specifying the depth you want, and after that you can subscribe to a websocket that will send you new additions to the order book in real time. You are supposed to match the orders yourself.

fdary avatar Aug 12 '22 12:08 fdary

Hi, sorry for the long delay, I was unavailable. Futures need some work to work properly.

In spot, binance offers two modes for orderbooks, one with deltas and one where you get updates every 100ms. It maybe your opinion that getting ticks for orderbooks is overkill, however you will find that maintaining an orderbook from deltas is quite the headache because of failure management.

If you'd like example/library code for orderbook management specifically we can work on that.

Igosuki avatar Oct 18 '22 09:10 Igosuki

however you will find that maintaining an orderbook from deltas is quite the headache because of failure management.

@Igosuki is there a better way than just refreshing the book from a new snapshot when you miss a delta, it doesn't seem to happen often to me?

I'm using the following flow in general for Binance:

  1. Start buffering deltas into a channel BEFORE I take a snapshot
  2. Initiate the data structure for the orderbook from a snapshot
  3. Start updating from deltas and just discard deltas which are pre-snapshot timestamp
  4. If there is some count or timestamp mismatch on the incoming delta then refresh the snapshot and continue

It would be great to see a suggested example implementation though in this library of following the futures orderbooks. I've had to write my own implementation by hacking together logic from this package and binance-rs as I couldn't get it to work either. Also re-initiating on failure can make the data collection for backtesting buggy

CodeForcer avatar Jan 03 '23 13:01 CodeForcer

Ideally, you'll manage fault tolerance with having multiple websocket streams up, and a way to realign your data with live data in case the main data stream fails. Each stream has to monitor update ids and they have to be continuous, if they aren't, the stream should go into failure and restart.

I have code from last year I can rework to match this spec, it's not complicated.

Igosuki avatar Feb 16 '23 15:02 Igosuki

Hi @Igosuki are futures coming to the library?

Also, I can see that Binance allows live subscription/unsubscription to new instruments for depth, for example:

https://binance-docs.github.io/apidocs/spot/en/#live-subscribing-unsubscribing-to-streams

However this doesn't seem to be supported in the library.

I'm quite happy to help with the coding, in needed :)

zelenij avatar Aug 16 '23 12:08 zelenij

Hey, I'm up for it but I wanted to wait to see if binance could produce an open API spec for futures. Let me get back to you on that.

On Wed, Aug 16, 2023, 14:35 zelenij @.***> wrote:

Hi @Igosuki https://github.com/Igosuki are futures coming to the library?

Also, I can see that Binance allows live subscription/unsubscription to new instruments for depth, for example:

https://binance-docs.github.io/apidocs/spot/en/#live-subscribing-unsubscribing-to-streams

However this doesn't seem to be supported in the library

— Reply to this email directly, view it on GitHub https://github.com/Igosuki/binance-rs-async/issues/46#issuecomment-1680524451, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADDFBT6AUFJ24K7TWUZHQ3XVS5C5ANCNFSM56GHABAQ . You are receiving this because you were mentioned.Message ID: @.***>

Igosuki avatar Aug 17 '23 12:08 Igosuki

Hasn't it been published and in use for quite a bit? The .NET library has had support for futures for awhile now.

Also, the "dynamic subscription" support sounds like an easy win. Without it, if you want to subscribe to more/fewer instruments with this library, you have to recreate the web sockets (unless I'm missing something?)

zelenij avatar Aug 18 '23 10:08 zelenij

The latest PRs added support for futures websocket streaming

Igosuki avatar Jan 19 '24 12:01 Igosuki