Skip to content

Commit

Permalink
skip invalid push events
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Mar 8, 2024
1 parent d1dfe7f commit df11758
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion rust/src/quote/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,9 @@ impl Core {
async fn handle_push(&mut self, command_code: u8, body: Vec<u8>) -> Result<()> {
match PushEvent::parse(command_code, &body) {
Ok(mut event) => {
self.store.handle_push(&mut event);
if !self.store.handle_push(&mut event) {
return Ok(());
}

if let PushEventDetail::Trade(trades) = &event.detail {
// merge candlesticks
Expand Down
8 changes: 5 additions & 3 deletions rust/src/quote/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const MAX_TRADES: usize = 500;
macro_rules! check_sequence {
($prev:expr, $new:expr) => {
if $new != 0 && $new <= $prev {
return;
return false;
}
$prev = $new;
};
Expand Down Expand Up @@ -65,7 +65,7 @@ pub(crate) struct Store {
}

impl Store {
pub(crate) fn handle_push(&mut self, event: &mut PushEvent) {
pub(crate) fn handle_push(&mut self, event: &mut PushEvent) -> bool {
let data = self.securities.entry(event.symbol.clone()).or_default();

match &mut event.detail {
Expand All @@ -85,8 +85,10 @@ impl Store {
check_sequence!(data.trades_sequence, event.sequence);
merge_trades(data, trade);
}
PushEventDetail::Candlestick(_) => {}
PushEventDetail::Candlestick(_) => unreachable!(),
}

true
}
}

Expand Down

0 comments on commit df11758

Please sign in to comment.