From d06435a2fba7415acf04a258a4b4b50602204b2b Mon Sep 17 00:00:00 2001 From: Fan Date: Tue, 9 Mar 2021 09:49:40 +0800 Subject: [PATCH] fix tedious logging (#96) * fix issue #94 * cargo clippy Co-authored-by: Weifan Co-authored-by: HAOYUatHZ --- src/matchengine/market.rs | 13 ++++++------- src/storage/database.rs | 7 ++++++- src/storage/sqlxextend.rs | 5 +---- src/types/mod.rs | 2 -- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/matchengine/market.rs b/src/matchengine/market.rs index a0712928..5f40885e 100644 --- a/src/matchengine/market.rs +++ b/src/matchengine/market.rs @@ -517,10 +517,10 @@ impl Market { ask_order_state, bid_order_state, balance: VerboseBalanceState { - ask_user_base, - ask_user_quote, bid_user_base, bid_user_quote, + ask_user_base, + ask_user_quote, }, } } @@ -723,8 +723,8 @@ impl Market { let price = order_input.price.round_dp(quote_prec); //println!("decimal {} {} {} {} ", self.base, base_prec, self.quote, quote_prec); let order_input = OrderInput { - price, amount, + price, ..order_input }; if order_input.type_ == OrderType::MARKET { @@ -734,11 +734,10 @@ impl Market { if order_input.side == OrderSide::ASK && self.bids.is_empty() || order_input.side == OrderSide::BID && self.asks.is_empty() { return Err(anyhow!("no counter orders")); } - } else { - if order_input.price.is_zero() { - return Err(anyhow!("invalid price for limit order")); - } + } else if order_input.price.is_zero() { + return Err(anyhow!("invalid price for limit order")); } + if order_input.side == OrderSide::ASK { if balance_manager .balance_get(order_input.user_id, BalanceType::AVAILABLE, &self.base) diff --git a/src/storage/database.rs b/src/storage/database.rs index 749c30b8..55c3bf5d 100644 --- a/src/storage/database.rs +++ b/src/storage/database.rs @@ -1,6 +1,6 @@ use std::collections::{hash_map, HashMap, VecDeque}; use std::marker::PhantomData; -use std::time::Instant; +use std::time::{Duration, Instant}; use tokio::sync::mpsc::error::TrySendError; use tokio::{sync, task}; @@ -269,6 +269,7 @@ struct DatabaseWriterTask { data: Vec, notify_flag: Option, benchmark: Option<(Instant, u32)>, + err_count: u32, } impl DatabaseWriterTask { @@ -277,6 +278,7 @@ impl DatabaseWriterTask { data: Vec::new(), notify_flag: None, benchmark: None, + err_count: 0, } } @@ -338,6 +340,9 @@ where ret.send(WriterMsg::Done(self)).await } Err((resident, e)) => { + //TODO: we can adjust waiting time by err_count + tokio::time::sleep(Duration::from_secs(1)).await; + self.err_count += 1; self.data = resident; ret.send(WriterMsg::Fail(e, self)).await } diff --git a/src/storage/sqlxextend.rs b/src/storage/sqlxextend.rs index 24cd61bd..802aa8ae 100644 --- a/src/storage/sqlxextend.rs +++ b/src/storage/sqlxextend.rs @@ -149,10 +149,7 @@ where } None => self.0.next(), }; - match ret { - Some(i) => Some(Some(i)), - None => None, - } + ret.map(Some) } } diff --git a/src/types/mod.rs b/src/types/mod.rs index bf914385..6f74d50f 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,5 +1,3 @@ -//#![macro_use] - use num_enum::TryFromPrimitive; use serde::{Deserialize, Serialize};