Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsubscribe/Subscribe to stream #315

Closed
1 task done
dima-dmytruk23 opened this issue Apr 3, 2023 · 4 comments
Closed
1 task done

Unsubscribe/Subscribe to stream #315

dima-dmytruk23 opened this issue Apr 3, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@dima-dmytruk23
Copy link
Contributor

dima-dmytruk23 commented Apr 3, 2023

Version of this library.

1.42.0

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?

Linux

Python version?

Python3.7

Installed packages

unicorn-binance-websocket-api 1.42.0
unicorn-fy                    0.12.2
websockets                    10.4

Logging output

https://gist.github.com/dima-dmytruk23/0e7500d94292a3889e3eecfa769385f8

Processing method?

stream_buffer

Used endpoint?

concerns all

Issue

I initially have a stream that is subscribed to futures (at the time of launch, this is an empty list). This list is filled/changed by messages from the message broker. I was thinking of doing this with

self.manager.unsubscribe_from_stream(stream_id=self.stream_id, markets=old_symbols)
self.manager.subscribe_to_stream(stream_id=self.stream_id, markets=new_symbols)

But for some reason after that - I do not receive data from the Binance. As far as I can see, this only happens if I initially have an empty list of tickers.

@dima-dmytruk23 dima-dmytruk23 added the bug Something isn't working label Apr 3, 2023
@oliver-zehentleitner
Copy link
Member

this is the expected behavior for me, since the websocket uri in our method must always contain at least one valid subscription.

@oliver-zehentleitner
Copy link
Member

uri = self.websocket_base_uri + "ws/" + str(response['listenKey'])

We build the URI for a "raw stream": https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams

If you want to update this a PR is welcome.

@dima-dmytruk23
Copy link
Contributor Author

uri = self.websocket_base_uri + "ws/" + str(response['listenKey'])

We build the URI for a "raw stream": https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams

If you want to update this a PR is welcome.

Any idea how to handle this correctly? Use a combined stream? Do not create a stream if there are no tickers?

@oliver-zehentleitner
Copy link
Member

In itself, it is not intended that ubwa can create an empty stream. I also think that create_stream() returns False in your case. (I hope I'm not wrong now, but that's what I would expect ^^) Which would actually implement it "correctly".

If you want to use the full potential of the Binance API and create a combined stream instead of raw, then check if an empty stream is allowed. for that method i'm not sure...

I personally would be reluctant to attack this because it is now copatible with all APIs even binancechain. It's a lot of work and needs a lot of testing and the surplus is minimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants