Derive market order protection from visible opposing depth
This commit is contained in:
@@ -179,7 +179,12 @@ pub(crate) fn apply(
|
||||
"market sell requires FAK or FOK"
|
||||
);
|
||||
let qty = crate::lots::amount(qty, size_micros)?;
|
||||
let price = crate::tick_size::required(min_price, min_price_micros)?;
|
||||
let limit = crate::tick_size::input(min_price, min_price_micros)?;
|
||||
let price = books
|
||||
.protection_price(&market, &outcome, matching::Side::Sell, qty, limit, tif)
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!("insufficient opposing depth for market sell protection price")
|
||||
})?;
|
||||
let tick = crate::tick_size::TickSize::load(tx, &market)?;
|
||||
let amounts = crate::market_amounts::Amounts::for_order(
|
||||
tick.as_ref(),
|
||||
@@ -207,6 +212,7 @@ pub(crate) fn apply(
|
||||
if let Some(amounts) = amounts {
|
||||
receipt["order_amounts"] = amounts.json();
|
||||
}
|
||||
receipt["protection_price_micros"] = json!(price * crate::tick_size::PRICE_MICROS);
|
||||
receipt["proceeds_cents"] =
|
||||
json!(crate::inventory::decimal(result.gross_micros.into(), 10000));
|
||||
receipt["unsold_shares"] = json!(crate::lots::display(qty - result.filled));
|
||||
@@ -234,7 +240,7 @@ pub(crate) fn apply(
|
||||
account,
|
||||
key_id,
|
||||
amount_cents: crate::market_amounts::cash_cents(amount_cents, amount_micros)?,
|
||||
max_price: crate::tick_size::required(max_price, max_price_micros)?,
|
||||
max_price: crate::tick_size::input(max_price, max_price_micros)?,
|
||||
tif: tif.unwrap_or(crate::command::TimeInForce::Fak),
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user