Use snapshot last price for jq intraday execution
This commit is contained in:
@@ -593,10 +593,8 @@ impl JqMicroCapStrategy {
|
||||
market: &crate::data::DailyMarketSnapshot,
|
||||
side: OrderSide,
|
||||
) -> f64 {
|
||||
match side {
|
||||
OrderSide::Buy => market.buy_price(PriceField::Last),
|
||||
OrderSide::Sell => market.sell_price(PriceField::Last),
|
||||
}
|
||||
let _ = side;
|
||||
market.price(PriceField::Last)
|
||||
}
|
||||
|
||||
fn project_order_value(
|
||||
@@ -814,6 +812,40 @@ impl JqMicroCapStrategy {
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(market) = ctx.data.market(date, symbol) {
|
||||
let execution_price = self.projected_execution_price(market, side);
|
||||
if execution_price.is_finite() && execution_price > 0.0 {
|
||||
let quantity = match side {
|
||||
OrderSide::Buy => {
|
||||
let cash = cash_limit.unwrap_or(f64::INFINITY);
|
||||
let mut take_qty = self.round_lot_quantity(requested_qty, round_lot.max(1));
|
||||
while take_qty > 0 {
|
||||
let candidate_gross = execution_price * take_qty as f64;
|
||||
if gross_limit.is_some_and(|limit| candidate_gross > limit + 1e-6) {
|
||||
take_qty = take_qty.saturating_sub(round_lot.max(1));
|
||||
continue;
|
||||
}
|
||||
if candidate_gross <= cash + 1e-6 {
|
||||
break;
|
||||
}
|
||||
take_qty = take_qty.saturating_sub(round_lot.max(1));
|
||||
}
|
||||
take_qty
|
||||
}
|
||||
OrderSide::Sell => requested_qty,
|
||||
};
|
||||
if quantity > 0 {
|
||||
let next_cursor = date.and_time(self.intraday_execution_start_time())
|
||||
+ Duration::seconds(1);
|
||||
return Some(ProjectedExecutionFill {
|
||||
price: execution_price,
|
||||
quantity,
|
||||
next_cursor,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let lot = round_lot.max(1);
|
||||
let start_cursor = self.projected_execution_start_cursor(date, symbol, execution_state);
|
||||
let quotes = ctx.data.execution_quotes_on(date, symbol);
|
||||
|
||||
Reference in New Issue
Block a user