Align order costs and rebalance priority with rqalpha
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use fidc_core::cost::CostModel;
|
||||
use fidc_core::rules::EquityRuleHooks;
|
||||
@@ -74,6 +76,46 @@ fn china_cost_model_switches_stamp_tax_rate_after_2023_08_28() {
|
||||
assert!((after.stamp_tax - 50.0).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn china_cost_model_tracks_minimum_commission_per_order_id() {
|
||||
let model = ChinaAShareCostModel::default();
|
||||
let mut commission_state = BTreeMap::new();
|
||||
|
||||
let first = model.calculate_with_order_state(
|
||||
d(2024, 1, 3),
|
||||
OrderSide::Buy,
|
||||
1_000.0,
|
||||
Some(7),
|
||||
&mut commission_state,
|
||||
);
|
||||
let second = model.calculate_with_order_state(
|
||||
d(2024, 1, 3),
|
||||
OrderSide::Buy,
|
||||
1_000.0,
|
||||
Some(7),
|
||||
&mut commission_state,
|
||||
);
|
||||
let third = model.calculate_with_order_state(
|
||||
d(2024, 1, 3),
|
||||
OrderSide::Buy,
|
||||
20_000.0,
|
||||
Some(7),
|
||||
&mut commission_state,
|
||||
);
|
||||
let another_order = model.calculate_with_order_state(
|
||||
d(2024, 1, 3),
|
||||
OrderSide::Buy,
|
||||
1_000.0,
|
||||
Some(8),
|
||||
&mut commission_state,
|
||||
);
|
||||
|
||||
assert!((first.commission - 5.0).abs() < 1e-9);
|
||||
assert!(second.commission.abs() < 1e-9);
|
||||
assert!((third.commission - 1.6).abs() < 1e-9);
|
||||
assert!((another_order.commission - 5.0).abs() < 1e-9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn china_rule_hooks_block_same_day_sell_under_t_plus_one() {
|
||||
let hooks = ChinaEquityRuleHooks;
|
||||
@@ -107,11 +149,13 @@ fn china_rule_hooks_block_buy_at_limit_up_and_sell_at_limit_down() {
|
||||
PriceField::Open,
|
||||
);
|
||||
assert!(!buy_check.allowed);
|
||||
assert!(buy_check
|
||||
.reason
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.contains("upper limit"));
|
||||
assert!(
|
||||
buy_check
|
||||
.reason
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.contains("upper limit")
|
||||
);
|
||||
|
||||
let sell_check = hooks.can_sell(
|
||||
d(2024, 1, 3),
|
||||
@@ -121,11 +165,13 @@ fn china_rule_hooks_block_buy_at_limit_up_and_sell_at_limit_down() {
|
||||
PriceField::Open,
|
||||
);
|
||||
assert!(!sell_check.allowed);
|
||||
assert!(sell_check
|
||||
.reason
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.contains("lower limit"));
|
||||
assert!(
|
||||
sell_check
|
||||
.reason
|
||||
.as_deref()
|
||||
.unwrap_or_default()
|
||||
.contains("lower limit")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user