修正A股涨跌停严格触价规则

This commit is contained in:
boris
2026-06-15 18:50:10 +08:00
parent 5181d0e403
commit 5d2bcd8366
2 changed files with 23 additions and 3 deletions
+2 -2
View File
@@ -159,14 +159,14 @@ impl DailyMarketSnapshot {
if !self.upper_limit.is_finite() || self.upper_limit <= 0.0 { if !self.upper_limit.is_finite() || self.upper_limit <= 0.0 {
return false; return false;
} }
price >= self.upper_limit - self.effective_price_tick() + 1e-6 price >= self.upper_limit - 1e-9
} }
pub fn is_at_lower_limit_price(&self, price: f64) -> bool { pub fn is_at_lower_limit_price(&self, price: f64) -> bool {
if !self.lower_limit.is_finite() || self.lower_limit <= 0.0 { if !self.lower_limit.is_finite() || self.lower_limit <= 0.0 {
return false; return false;
} }
price <= self.lower_limit + self.effective_price_tick() - 1e-6 price <= self.lower_limit + 1e-9
} }
} }
+21 -1
View File
@@ -175,7 +175,7 @@ fn china_rule_hooks_block_buy_at_limit_up_and_sell_at_limit_down() {
} }
#[test] #[test]
fn china_rule_hooks_use_tick_size_tolerance_for_price_limits() { fn china_rule_hooks_use_strict_price_limits() {
let hooks = ChinaEquityRuleHooks; let hooks = ChinaEquityRuleHooks;
let candidate = candidate(); let candidate = candidate();
@@ -184,6 +184,13 @@ fn china_rule_hooks_use_tick_size_tolerance_for_price_limits() {
..snapshot(10.9995, 11.0, 9.0) ..snapshot(10.9995, 11.0, 9.0)
}; };
let buy_check = hooks.can_buy(d(2024, 1, 3), &near_upper, &candidate, PriceField::Open); let buy_check = hooks.can_buy(d(2024, 1, 3), &near_upper, &candidate, PriceField::Open);
assert!(buy_check.allowed);
let exact_upper = DailyMarketSnapshot {
price_tick: 0.001,
..snapshot(11.0, 11.0, 9.0)
};
let buy_check = hooks.can_buy(d(2024, 1, 3), &exact_upper, &candidate, PriceField::Open);
assert!(!buy_check.allowed); assert!(!buy_check.allowed);
let near_lower = DailyMarketSnapshot { let near_lower = DailyMarketSnapshot {
@@ -199,6 +206,19 @@ fn china_rule_hooks_use_tick_size_tolerance_for_price_limits() {
&position, &position,
PriceField::Open, PriceField::Open,
); );
assert!(sell_check.allowed);
let exact_lower = DailyMarketSnapshot {
price_tick: 0.001,
..snapshot(9.0, 11.0, 9.0)
};
let sell_check = hooks.can_sell(
d(2024, 1, 3),
&exact_lower,
&candidate,
&position,
PriceField::Open,
);
assert!(!sell_check.allowed); assert!(!sell_check.allowed);
} }