perf: avoid board normalization allocations
This commit is contained in:
@@ -21,17 +21,29 @@ impl Instrument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn minimum_order_quantity(&self) -> u32 {
|
pub fn minimum_order_quantity(&self) -> u32 {
|
||||||
match self.board.trim().to_ascii_uppercase().as_str() {
|
let board = self.board.trim();
|
||||||
"KSH" => 200,
|
if board.eq_ignore_ascii_case("KSH") {
|
||||||
"BJS" | "BJ" | "BJSE" => 100,
|
200
|
||||||
_ => self.effective_round_lot(),
|
} 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 {
|
pub fn order_step_size(&self) -> u32 {
|
||||||
match self.board.trim().to_ascii_uppercase().as_str() {
|
let board = self.board.trim();
|
||||||
"KSH" | "BJS" | "BJ" | "BJSE" => 1,
|
if board.eq_ignore_ascii_case("KSH")
|
||||||
_ => self.effective_round_lot(),
|
|| 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()
|
"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 {
|
mod optional_date_format {
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use serde::{self, Deserialize, Deserializer, Serializer};
|
use serde::{self, Deserialize, Deserializer, Serializer};
|
||||||
|
|||||||
Reference in New Issue
Block a user