Messages from websocket stream are queued
precious-void opened this issue · comments
Hi, thank you for developing this project, it's really great! I'm interested in how to deal with queuing websockets responses.
Here is a code example to explain, what I'm interested in.
let mut web_socket: WebSockets = WebSockets::new(|event: WebsocketEvent| {
if let WebsocketEvent::BookTicker(tick_event) = event {
if tick_event.symbol == "ADAUSDT" {
keep_running.swap(false, Ordering::Relaxed);
println!("Event {:?}\nTime: {}\n{:?}\n", tick_event, Utc::now().format("%Y-%m-%d %H:%M:%S.%f"), keep_running);
thread::sleep(time::Duration::from_secs(5)); // Delay
keep_running.swap(true, Ordering::Relaxed);
}
}
return Ok(());
});
For example, if we received "ADA/USDT" event at 01:00:00, after 5 seconds delay we will receive the rest of the data from 01:00:00 to 01:00:05, which I`m not interested in. Is there a way to check if the event is relevant or just stop queuing messages?
Not sure if I understood what you want to do, but it sounds like https://github.com/binance-exchange/binance-official-api-docs/blob/master/web-socket-streams.md#how-to-manage-a-local-order-book-correctly
The crate does not provide such functionality, you can implement as explained in the binance docs