Skip to content

Commit

Permalink
remove checking sequence behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Mar 15, 2024
1 parent e3f01c5 commit 08450ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
9 changes: 5 additions & 4 deletions rust/src/quote/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ impl Core {
}
}

tracing::debug!(subscriptions = ?subscriptions, "resubscribe");

for (flags, symbols) in subscriptions {
self.ws_cli
.request(
Expand All @@ -724,17 +726,16 @@ impl Core {
)
.await?;
}

Ok(())
}

async fn handle_push(&mut self, command_code: u8, body: Vec<u8>) -> Result<()> {
match PushEvent::parse(command_code, &body) {
Ok((mut event, tag)) => {
tracing::debug!(event = ?event, tag = ?tag,"push event");

if tag != Some(PushQuoteTag::Eod) {
if !self.store.handle_push(&mut event) {
return Ok(());
}
self.store.handle_push(&mut event);
}

if let PushEventDetail::Trade(trades) = &event.detail {
Expand Down
1 change: 1 addition & 0 deletions rust/src/quote/push_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub enum PushEventDetail {
/// Push event
#[derive(Debug)]
pub struct PushEvent {
#[allow(dead_code)]
pub(crate) sequence: i64,
/// Security code
pub symbol: String,
Expand Down
37 changes: 5 additions & 32 deletions rust/src/quote/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ use crate::quote::{

const MAX_TRADES: usize = 500;

macro_rules! check_sequence {
($prev:expr, $new:expr) => {
if $new != 0 && $new <= $prev {
return false;
}
$prev = $new;
};
}

macro_rules! merge_decimal {
($prev:expr, $new:expr, $field:ident) => {
if !$new.$field.is_zero() {
Expand All @@ -41,18 +32,14 @@ macro_rules! merge_i64 {

#[derive(Debug, Default)]
pub(crate) struct SecuritiesData {
pub(crate) quote_sequence: i64,
pub(crate) quote: PushQuote,

pub(crate) depth_sequence: i64,
pub(crate) asks: Vec<Depth>,
pub(crate) bids: Vec<Depth>,

pub(crate) brokers_sequence: i64,
pub(crate) ask_brokers: Vec<Brokers>,
pub(crate) bid_brokers: Vec<Brokers>,

pub(crate) trades_sequence: i64,
pub(crate) trades: Vec<Trade>,

pub(crate) board: SecurityBoard,
Expand All @@ -65,30 +52,16 @@ pub(crate) struct Store {
}

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

match &mut event.detail {
PushEventDetail::Quote(quote) => {
check_sequence!(data.quote_sequence, event.sequence);
merge_quote(data, quote);
}
PushEventDetail::Depth(depth) => {
check_sequence!(data.depth_sequence, event.sequence);
merge_depth(data, depth);
}
PushEventDetail::Brokers(brokers) => {
check_sequence!(data.brokers_sequence, event.sequence);
merge_brokers(data, brokers);
}
PushEventDetail::Trade(trade) => {
check_sequence!(data.trades_sequence, event.sequence);
merge_trades(data, trade);
}
PushEventDetail::Quote(quote) => merge_quote(data, quote),
PushEventDetail::Depth(depth) => merge_depth(data, depth),
PushEventDetail::Brokers(brokers) => merge_brokers(data, brokers),
PushEventDetail::Trade(trade) => merge_trades(data, trade),
PushEventDetail::Candlestick(_) => unreachable!(),
}

true
}
}

Expand Down

0 comments on commit 08450ee

Please sign in to comment.