Filter fill updates on subscription

This commit is contained in:
Riordan Panayides 2022-12-27 15:03:18 +00:00
parent 9f528603b0
commit 05f42c7352
1 changed files with 22 additions and 16 deletions

View File

@ -348,14 +348,17 @@ async fn main() -> anyhow::Result<()> {
debug!("ws update {} {:?} fill", update.market, update.status);
let mut peer_copy = peers_ref_thread.lock().unwrap().clone();
for (addr, peer) in peer_copy.iter_mut() {
trace!(" > {}", addr);
let json = serde_json::to_string(&update);
let result = peer.sender.send(Message::Text(json.unwrap())).await;
if result.is_err() {
error!(
"ws update {} {:?} fill could not reach {}",
update.market, update.status, addr
);
let json = serde_json::to_string(&update).unwrap();
// only send updates if the peer is subscribed
if peer.subscriptions.contains(&update.market) {
let result = peer.sender.send(Message::Text(json)).await;
if result.is_err() {
error!(
"ws update {} fill could not reach {}",
update.market, addr
);
}
}
}
}
@ -369,14 +372,17 @@ async fn main() -> anyhow::Result<()> {
debug!("ws update {} {:?} serum fill", update.market, update.status);
let mut peer_copy = peers_ref_thread.lock().unwrap().clone();
for (addr, peer) in peer_copy.iter_mut() {
trace!(" > {}", addr);
let json = serde_json::to_string(&update);
let result = peer.sender.send(Message::Text(json.unwrap())).await;
if result.is_err() {
error!(
"ws update {} {:?} serum fill could not reach {}",
update.market, update.status, addr
);
let json = serde_json::to_string(&update).unwrap();
// only send updates if the peer is subscribed
if peer.subscriptions.contains(&update.market) {
let result = peer.sender.send(Message::Text(json)).await;
if result.is_err() {
error!(
"ws update {} fill could not reach {}",
update.market, addr
);
}
}
}
}