Match fractional share lots and preserve order quantities across restart

This commit is contained in:
2026-12-03 07:01:24 +08:00
parent 2c4179a64e
commit 064b301ebd
27 changed files with 343 additions and 111 deletions
+9 -6
View File
@@ -131,6 +131,7 @@ pub(crate) fn apply(
side,
price,
qty,
size_micros,
tif,
expiration,
post_only,
@@ -144,7 +145,7 @@ pub(crate) fn apply(
outcome,
side,
price,
qty,
qty: crate::lots::amount(qty, size_micros)?,
tif: tif.unwrap_or_else(|| {
if expiration.unwrap_or(0) != 0 {
crate::command::TimeInForce::Gtd
@@ -164,6 +165,7 @@ pub(crate) fn apply(
outcome,
qty,
min_price,
size_micros,
tif,
} => {
let tif = tif.unwrap_or(crate::command::TimeInForce::Fak);
@@ -174,6 +176,7 @@ pub(crate) fn apply(
),
"market sell requires FAK or FOK"
);
let qty = crate::lots::amount(qty, size_micros)?;
let result = book::submit(
tx,
books,
@@ -191,11 +194,11 @@ pub(crate) fn apply(
},
)?;
let mut receipt = result.receipt();
receipt["proceeds_cents"] = json!(result.gross_cents);
receipt["unsold_shares"] = json!(qty - result.filled);
receipt["proceeds_cents"] =
json!(crate::inventory::decimal(result.gross_micros.into(), 10000));
receipt["unsold_shares"] = json!(crate::lots::display(qty - result.filled));
if result.fee_micros > 0 {
receipt["net_proceeds_micros"] =
json!(result.gross_cents * 10000 - result.fee_micros);
receipt["net_proceeds_micros"] = json!(result.gross_micros - result.fee_micros);
}
Ok(receipt)
}
@@ -223,7 +226,7 @@ pub(crate) fn apply(
Command::Cancel { order, account } => {
identifier(&account)?;
let qty = book::release(tx, order, &account, book::CancelReason::Cancelled)?;
Ok(json!({"cancelled":qty}))
Ok(json!({"cancelled":crate::lots::display(qty)}))
}
Command::CancelOrders { account, orders } => {
crate::cancellation::by_id(tx, &account, &orders)