Skip to content

Commit

Permalink
fix tedious logging (#96)
Browse files Browse the repository at this point in the history
* fix issue #94

* cargo clippy

Co-authored-by: Weifan <weifan@blackapi.com>
Co-authored-by: HAOYUatHZ <haoyu@protonmail.com>
  • Loading branch information
3 people authored Mar 9, 2021
1 parent 16bb9a5 commit d06435a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/matchengine/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/storage/database.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -269,6 +269,7 @@ struct DatabaseWriterTask<T> {
data: Vec<T>,
notify_flag: Option<TaskNotifyFlag>,
benchmark: Option<(Instant, u32)>,
err_count: u32,
}

impl<T> DatabaseWriterTask<T> {
Expand All @@ -277,6 +278,7 @@ impl<T> DatabaseWriterTask<T> {
data: Vec::new(),
notify_flag: None,
benchmark: None,
err_count: 0,
}
}

Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 1 addition & 4 deletions src/storage/sqlxextend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,7 @@ where
}
None => self.0.next(),
};
match ret {
Some(i) => Some(Some(i)),
None => None,
}
ret.map(Some)
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//#![macro_use]

use num_enum::TryFromPrimitive;
use serde::{Deserialize, Serialize};

Expand Down

0 comments on commit d06435a

Please sign in to comment.