-
Notifications
You must be signed in to change notification settings - Fork 77
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
Correct way to stop streaming #38
Comments
@rakewell the combined streams feature is new and I have only implemented unsubscribe at the lowest level I am currently working on adding unsubscribe functionality to this class and others so that client instances can be reused after cancelling and restarting the underlying combined stream. Regardless, the only way to alter the data received from Binance is to restart the combined stream once all changes to subscriptions have been made in all higher level classes. If the stream is not canceled, the unsubscribe functionality in progress will ignore data received for any non-subscribed symbols, but that data will still be streaming. Alternatively, you can have a separate Also, I don't understand what you meant by "create multiple instances of CancellationTokenSource and link each instance to a particular symbol." What I think you mean should throw an invalid operation exception when calling |
Many thanks for taking the time to reply and the information. For now, I think I will continue to use a single instance with combined streams as I want to handle socket disconnections from a single web socket.
The multiple instances of the CancellationTokenSevice means that I passed a different cancellation token every time I called the StreamAsync method thinking that the different cancellation token would only apply to the single registration which is a mistake.
I look forward to future updates where it may be possible to cancel a single stream. One suggestion I have is that it would be nice to handle the socket events (Open, Close, perhaps Error?) from the higher level classes like BinanceWebSocketStream. In order to handle these events now I have to use the following:
m_BinanceSocketTradeStreamClient = New DefaultWebSocketClient()
m_BinanceSocketTradeStream = New BinanceWebSocketStream(m_BinanceSocketTradeStreamClient)
m_BinanceAggregateTradeSocket = New AggregateTradeWebSocketClient(m_BinanceSocketTradeStream)
which allows me to handle the web socket events on the m_BinanceSocketTradeStreamClient instance. Another option would be to bubble up these events to the highest level object (AggregateTradeWebSocketClient) so that they can be handled directly from there.
In terms of Socket Errors, whats the best way to handle these in client code? I can’t find an event that gets triggered.
On 28 Jan 2018, at 6:14 am, sonvister <notifications@github.com> wrote:
@rakewell <https://github.com/rakewell> the combined streams feature is new and I have only implemented unsubscribe at the lowest level IWebSocketStream. This Unsubscribe method (you found) is not meant to be paired with the higher level IBinanceWebSocketClient implementations' Subscribe methods. If you want to unsubscribe you must cancel the current stream and initialize a new AggregateTradeWebSocketClient with the desired symbols (if using combined streams).
I am currently working on adding unsubscribe functionality to this class and others so that client instances can be reused after cancelling and restarting the underlying combined stream. Regardless, the only way to alter the data received from Binance is to restart the combined stream once all changes to subscriptions have been made in all higher level classes.
If the stream is not canceled, the unsubscribe functionality in progress will ignore data received for any non-subscribed symbols, but that data will still be streaming.
Alternatively, you can have a separate AggregateTradeWebSocketClient with separate BinanceWebSocketStreams and control them independently (not use combined streams).
Also, I don't understand what you meant by "create multiple instances of CancellationTokenSource and link each instance to a particular symbol." What I think you mean should throw an invalid operation exception when calling StreamAsync multiple times.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#38 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AiNNvrjtSVu-_--8UMhMfL9z-LmDCkLfks5tO3V8gaJpZM4RvR9A>.
|
@rakewell, I've added |
@rakewell, as for the Open and Close events, I already consider them accessible from the higher level classes via |
@rakewell, I wanted to mention I reconsidered your suggestion for the Open and Close events. At first I didn't like the idea of adding layers of event propagation (bubbling) for a minor convenience. But, even though the events are accessible, they are buried. Since they also make sense within context of the higher level classes, I added the events to |
awesome thanks for that sonvister.. I will update to the alpha version in the next few days and do some testing.
On 29 Jan 2018, at 4:40 pm, sonvister <notifications@github.com> wrote:
@rakewell <https://github.com/rakewell>, I wanted to mention I reconsidered your suggestion for the Open and Close events. At first I didn't like the idea of adding layers of event propagation (bubbling) for a minor convenience. But, even though the events are accessible, they are buried. Since they also make sense within context of the higher level classes, I added the events to IBinanceWebSocketClient and used registration (add/remove) forwarding to avoid creating new events and propagation. The lower-level IWebSocketClient is read-only so this works. This change will be in 0.2.0-alpha23.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#38 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AiNNvn5j3tL8vGYLXuDAjYCbx_cXrZhuks5tPVnVgaJpZM4RvR9A>.
|
Hello,
Many thanks for your work on this project.
I am just starting to use your API and have successfully streamed trade information using the AggregateTradeWebSocketClient with the following code:
I retrieve trade updates as expected handling the event on the AggregateTradeWebSocketClient:
I have used the same instance of m_BinanceAggregateTradeSocket to subscribe to multiple symbols and this also works well. The problem is I would like to remove streaming for a symbol at a certain point. When I use the CancellationTokenSource to cancel, it cancels all of the streaming symbols. This is the case even though I create multiple instances of CancellationTokenSource and link each instance to a particular symbol.
What would be the best way to stop streaming a particular symbol?
I have also tried the Unsubscribe function on the WebSocketClient but I can't get this to work.
Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: