perf: avoid board normalization allocations
This commit is contained in:
@@ -21,17 +21,29 @@ impl Instrument {
|
||||
}
|
||||
|
||||
pub fn minimum_order_quantity(&self) -> u32 {
|
||||
match self.board.trim().to_ascii_uppercase().as_str() {
|
||||
"KSH" => 200,
|
||||
"BJS" | "BJ" | "BJSE" => 100,
|
||||
_ => self.effective_round_lot(),
|
||||
let board = self.board.trim();
|
||||
if board.eq_ignore_ascii_case("KSH") {
|
||||
200
|
||||
} else if board.eq_ignore_ascii_case("BJS")
|
||||
|| board.eq_ignore_ascii_case("BJ")
|
||||
|| board.eq_ignore_ascii_case("BJSE")
|
||||
{
|
||||
100
|
||||
} else {
|
||||
self.effective_round_lot()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn order_step_size(&self) -> u32 {
|
||||
match self.board.trim().to_ascii_uppercase().as_str() {
|
||||
"KSH" | "BJS" | "BJ" | "BJSE" => 1,
|
||||
_ => self.effective_round_lot(),
|
||||
let board = self.board.trim();
|
||||
if board.eq_ignore_ascii_case("KSH")
|
||||
|| board.eq_ignore_ascii_case("BJS")
|
||||
|| board.eq_ignore_ascii_case("BJ")
|
||||
|| board.eq_ignore_ascii_case("BJSE")
|
||||
{
|
||||
1
|
||||
} else {
|
||||
self.effective_round_lot()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +68,38 @@ fn default_status() -> String {
|
||||
"active".to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Instrument;
|
||||
|
||||
fn instrument(board: &str, round_lot: u32) -> Instrument {
|
||||
Instrument {
|
||||
symbol: "000001.SZ".to_string(),
|
||||
name: "test".to_string(),
|
||||
board: board.to_string(),
|
||||
round_lot,
|
||||
listed_at: None,
|
||||
delisted_at: None,
|
||||
status: "active".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn order_quantity_rules_are_case_insensitive_without_allocating_normalized_boards() {
|
||||
let kcb = instrument(" kSh ", 100);
|
||||
assert_eq!(kcb.minimum_order_quantity(), 200);
|
||||
assert_eq!(kcb.order_step_size(), 1);
|
||||
|
||||
let bjse = instrument("bjse", 100);
|
||||
assert_eq!(bjse.minimum_order_quantity(), 100);
|
||||
assert_eq!(bjse.order_step_size(), 1);
|
||||
|
||||
let main_board = instrument("SZSE", 50);
|
||||
assert_eq!(main_board.minimum_order_quantity(), 50);
|
||||
assert_eq!(main_board.order_step_size(), 50);
|
||||
}
|
||||
}
|
||||
|
||||
mod optional_date_format {
|
||||
use chrono::NaiveDate;
|
||||
use serde::{self, Deserialize, Deserializer, Serializer};
|
||||
|
||||
Reference in New Issue
Block a user