Add suspended and ST data helpers
This commit is contained in:
@@ -20,6 +20,14 @@ fn dt(year: i32, month: u32, day: u32, hour: u32, minute: u32, second: u32) -> N
|
||||
.expect("valid datetime")
|
||||
}
|
||||
|
||||
fn bool_flags(values: Vec<bool>) -> String {
|
||||
values
|
||||
.into_iter()
|
||||
.map(|value| if value { "1" } else { "0" })
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
}
|
||||
|
||||
struct HookProbeStrategy {
|
||||
log: Rc<RefCell<Vec<String>>>,
|
||||
}
|
||||
@@ -420,8 +428,10 @@ impl Strategy for DataApiProbeStrategy {
|
||||
let trading_date_count = ctx
|
||||
.get_trading_dates(d(2025, 1, 2), ctx.execution_date)
|
||||
.len();
|
||||
let suspended = bool_flags(ctx.is_suspended("000001.SZ", 3));
|
||||
let st_flags = bool_flags(ctx.is_st_stock("000001.SZ", 3));
|
||||
self.snapshots.borrow_mut().push(format!(
|
||||
"daily={daily_close};previous={previous_close};tick={tick_last};previous_tick={previous_tick_last};current={current_close};instrument={instrument_name};all={};range={trading_date_count};prev={prev_date};next={next_date}",
|
||||
"daily={daily_close};previous={previous_close};tick={tick_last};previous_tick={previous_tick_last};current={current_close};instrument={instrument_name};all={};range={trading_date_count};prev={prev_date};next={next_date};suspended={suspended};st={st_flags}",
|
||||
ctx.all_instruments().len()
|
||||
));
|
||||
}
|
||||
@@ -935,20 +945,24 @@ fn strategy_context_exposes_rqalpha_style_data_helpers() {
|
||||
extra_factors: BTreeMap::new(),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let candidates = [date1, date2, date3]
|
||||
.into_iter()
|
||||
.map(|date| CandidateEligibility {
|
||||
date,
|
||||
symbol: "000001.SZ".to_string(),
|
||||
is_st: false,
|
||||
is_new_listing: false,
|
||||
is_paused: false,
|
||||
allow_buy: true,
|
||||
allow_sell: true,
|
||||
is_kcb: false,
|
||||
is_one_yuan: false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let candidates = [
|
||||
(date1, false, false),
|
||||
(date2, true, true),
|
||||
(date3, false, false),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(date, is_paused, is_st)| CandidateEligibility {
|
||||
date,
|
||||
symbol: "000001.SZ".to_string(),
|
||||
is_st,
|
||||
is_new_listing: false,
|
||||
is_paused,
|
||||
allow_buy: true,
|
||||
allow_sell: true,
|
||||
is_kcb: false,
|
||||
is_one_yuan: false,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
let benchmarks = [
|
||||
(date1, 100.0, 99.0),
|
||||
(date2, 101.0, 100.0),
|
||||
@@ -1045,7 +1059,7 @@ fn strategy_context_exposes_rqalpha_style_data_helpers() {
|
||||
assert_eq!(
|
||||
snapshots.borrow().as_slice(),
|
||||
[
|
||||
"daily=10.10,10.20;previous=10.00,10.10;tick=10.15,10.25;previous_tick=10.15;current=10.20;instrument=Anchor;all=1;range=3;prev=2025-01-03;next=2025-01-06"
|
||||
"daily=10.10,10.20;previous=10.00,10.10;tick=10.15,10.25;previous_tick=10.15;current=10.20;instrument=Anchor;all=1;range=3;prev=2025-01-03;next=2025-01-06;suspended=0,1,0;st=0,1,0"
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user