Align market order cancellation semantics
This commit is contained in:
@@ -942,7 +942,7 @@ where
|
||||
side: OrderSide::Sell,
|
||||
requested_quantity: requested_qty,
|
||||
filled_quantity: 0,
|
||||
status: OrderStatus::Rejected,
|
||||
status: zero_fill_status_for_reason(&limit_reason),
|
||||
reason: format!("{reason}: {limit_reason}"),
|
||||
});
|
||||
return Ok(());
|
||||
@@ -1063,7 +1063,7 @@ where
|
||||
*intraday_turnover.entry(symbol.to_string()).or_default() += filled_qty;
|
||||
|
||||
let status = if filled_qty < requested_qty {
|
||||
OrderStatus::PartiallyFilled
|
||||
final_partial_fill_status(partial_fill_reason.as_deref())
|
||||
} else {
|
||||
OrderStatus::Filled
|
||||
};
|
||||
@@ -1075,6 +1075,14 @@ where
|
||||
"order_partial_fill symbol={symbol} side=sell requested={requested_qty} filled={filled_qty} reason={detail}"
|
||||
));
|
||||
format!("{reason}: partial fill due to {detail}")
|
||||
} else if status == OrderStatus::Canceled && filled_qty < requested_qty {
|
||||
let detail = partial_fill_reason
|
||||
.as_deref()
|
||||
.unwrap_or("remaining quantity could not be filled");
|
||||
report.diagnostics.push(format!(
|
||||
"order_remainder_canceled symbol={symbol} side=sell requested={requested_qty} filled={filled_qty} reason={detail}"
|
||||
));
|
||||
format!("{reason}: partial fill due to {detail}; remaining quantity canceled")
|
||||
} else {
|
||||
reason.to_string()
|
||||
};
|
||||
@@ -1340,7 +1348,7 @@ where
|
||||
side: OrderSide::Buy,
|
||||
requested_quantity: requested_qty,
|
||||
filled_quantity: 0,
|
||||
status: OrderStatus::Rejected,
|
||||
status: zero_fill_status_for_reason(&limit_reason),
|
||||
reason: format!("{reason}: {limit_reason}"),
|
||||
});
|
||||
return Ok(());
|
||||
@@ -1488,7 +1496,7 @@ where
|
||||
*intraday_turnover.entry(symbol.to_string()).or_default() += filled_qty;
|
||||
|
||||
let status = if filled_qty < requested_qty {
|
||||
OrderStatus::PartiallyFilled
|
||||
final_partial_fill_status(partial_fill_reason.as_deref())
|
||||
} else {
|
||||
OrderStatus::Filled
|
||||
};
|
||||
@@ -1500,6 +1508,14 @@ where
|
||||
"order_partial_fill symbol={symbol} side=buy requested={requested_qty} filled={filled_qty} reason={detail}"
|
||||
));
|
||||
format!("{reason}: partial fill due to {detail}")
|
||||
} else if status == OrderStatus::Canceled && filled_qty < requested_qty {
|
||||
let detail = partial_fill_reason
|
||||
.as_deref()
|
||||
.unwrap_or("remaining quantity could not be filled");
|
||||
report.diagnostics.push(format!(
|
||||
"order_remainder_canceled symbol={symbol} side=buy requested={requested_qty} filled={filled_qty} reason={detail}"
|
||||
));
|
||||
format!("{reason}: partial fill due to {detail}; remaining quantity canceled")
|
||||
} else {
|
||||
reason.to_string()
|
||||
};
|
||||
@@ -2011,6 +2027,26 @@ fn merge_partial_fill_reason(current: Option<String>, next: Option<&str>) -> Opt
|
||||
}
|
||||
}
|
||||
|
||||
fn zero_fill_status_for_reason(reason: &str) -> OrderStatus {
|
||||
match reason {
|
||||
"tick no volume" | "tick volume limit" => OrderStatus::Canceled,
|
||||
_ => OrderStatus::Rejected,
|
||||
}
|
||||
}
|
||||
|
||||
fn final_partial_fill_status(partial_reason: Option<&str>) -> OrderStatus {
|
||||
match partial_reason {
|
||||
Some(reason)
|
||||
if reason.contains("market liquidity or volume limit")
|
||||
|| reason.contains("intraday quote liquidity exhausted")
|
||||
|| reason.contains("no execution quotes after start") =>
|
||||
{
|
||||
OrderStatus::Canceled
|
||||
}
|
||||
_ => OrderStatus::PartiallyFilled,
|
||||
}
|
||||
}
|
||||
|
||||
fn price_field_name(field: PriceField) -> &'static str {
|
||||
match field {
|
||||
PriceField::DayOpen => "day_open",
|
||||
|
||||
Reference in New Issue
Block a user