Preview market sweeps and execute protected share sales
This commit is contained in:
@@ -137,7 +137,44 @@ pub(crate) fn apply(tx: &Transaction, books: &Books, command: Command) -> Result
|
||||
expiration,
|
||||
post_only,
|
||||
},
|
||||
),
|
||||
)
|
||||
.map(|result| result.receipt()),
|
||||
Command::MarketSell {
|
||||
market,
|
||||
account,
|
||||
outcome,
|
||||
qty,
|
||||
min_price,
|
||||
tif,
|
||||
} => {
|
||||
let tif = tif.unwrap_or(crate::command::TimeInForce::Fak);
|
||||
ensure!(
|
||||
matches!(
|
||||
tif,
|
||||
crate::command::TimeInForce::Fak | crate::command::TimeInForce::Fok
|
||||
),
|
||||
"market sell requires FAK or FOK"
|
||||
);
|
||||
let result = book::submit(
|
||||
tx,
|
||||
books,
|
||||
book::NewOrder {
|
||||
market,
|
||||
account,
|
||||
outcome,
|
||||
side: "sell".to_owned(),
|
||||
price: min_price,
|
||||
qty,
|
||||
tif,
|
||||
expiration: None,
|
||||
post_only: false,
|
||||
},
|
||||
)?;
|
||||
let mut receipt = result.receipt();
|
||||
receipt["proceeds_cents"] = json!(result.gross_cents);
|
||||
receipt["unsold_shares"] = json!(qty - result.filled);
|
||||
Ok(receipt)
|
||||
}
|
||||
Command::MarketBuy {
|
||||
market,
|
||||
outcome,
|
||||
|
||||
Reference in New Issue
Block a user