Settle sub-cent orders and migrate historical book prices
This commit is contained in:
@@ -19,6 +19,7 @@ pub(crate) enum Request {
|
||||
outcome: String,
|
||||
amount_cents: i64,
|
||||
max_price: Option<i64>,
|
||||
max_price_micros: Option<i64>,
|
||||
tif: Option<TimeInForce>,
|
||||
},
|
||||
Sell {
|
||||
@@ -27,6 +28,7 @@ pub(crate) enum Request {
|
||||
qty: Option<i64>,
|
||||
size_micros: Option<i64>,
|
||||
min_price: Option<i64>,
|
||||
min_price_micros: Option<i64>,
|
||||
tif: Option<TimeInForce>,
|
||||
},
|
||||
}
|
||||
@@ -39,27 +41,40 @@ impl Request {
|
||||
outcome,
|
||||
amount_cents,
|
||||
max_price,
|
||||
max_price_micros,
|
||||
tif,
|
||||
} => (market, outcome, Side::Buy, amount_cents, max_price, tif),
|
||||
} => (
|
||||
market,
|
||||
outcome,
|
||||
Side::Buy,
|
||||
amount_cents,
|
||||
crate::tick_size::input(max_price, max_price_micros)?,
|
||||
tif,
|
||||
),
|
||||
Self::Sell {
|
||||
market,
|
||||
outcome,
|
||||
qty,
|
||||
size_micros,
|
||||
min_price,
|
||||
min_price_micros,
|
||||
tif,
|
||||
} => (
|
||||
market,
|
||||
outcome,
|
||||
Side::Sell,
|
||||
crate::lots::amount(qty, size_micros)?,
|
||||
min_price,
|
||||
crate::tick_size::input(min_price, min_price_micros)?,
|
||||
tif,
|
||||
),
|
||||
};
|
||||
let tick = crate::tick_size::TickSize::load(tx, &market)?;
|
||||
let edge = tick.as_ref().map_or(0, |t| i64::from(t.local_step().get()));
|
||||
let limit = limit.unwrap_or(if side == Side::Buy { 100 - edge } else { edge });
|
||||
let limit = limit.unwrap_or(if side == Side::Buy {
|
||||
crate::tick_size::PAR - edge
|
||||
} else {
|
||||
edge
|
||||
});
|
||||
let tif = tif.unwrap_or(TimeInForce::Fak);
|
||||
if side == Side::Buy {
|
||||
amount(requested)?;
|
||||
@@ -69,12 +84,11 @@ impl Request {
|
||||
"estimate requires FAK or FOK"
|
||||
);
|
||||
ensure!(
|
||||
matches!(outcome.as_str(), "YES" | "NO") && (0..=100).contains(&limit),
|
||||
matches!(outcome.as_str(), "YES" | "NO")
|
||||
&& (0..=crate::tick_size::PAR).contains(&limit),
|
||||
"invalid outcome or price"
|
||||
);
|
||||
if let Some(tick) = tick {
|
||||
tick.check(limit * 10000)?;
|
||||
}
|
||||
crate::tick_size::validate(tick.as_ref(), limit)?;
|
||||
phase(tx, &market, &["continuous"])?;
|
||||
let rate = crate::fees::rate(tx, &market)?;
|
||||
if let Some(minimum) = crate::minimum_size::MinimumSize::load(tx, &market)? {
|
||||
@@ -89,7 +103,7 @@ impl Request {
|
||||
let mut fills = books
|
||||
.get(&market, &outcome)
|
||||
.map(|b| match side {
|
||||
Side::Buy => b.match_budget_buy(i64::MAX, limit, requested * 100),
|
||||
Side::Buy => b.match_budget_buy(i64::MAX, limit, requested * 10000),
|
||||
Side::Sell => b.match_incoming(&Order {
|
||||
seq: i64::MAX,
|
||||
side,
|
||||
@@ -114,8 +128,8 @@ impl Request {
|
||||
Side::Sell => requested == shares,
|
||||
};
|
||||
let mut result = json!({"asset_id":assets::id(&market,&outcome),"filled_shares":crate::lots::display(shares),
|
||||
"gross_cents":crate::inventory::decimal(gross.into(),10000),"best_fill_price":fills.first().map(|f|f.price),
|
||||
"worst_fill_price":fills.last().map(|f|f.price),
|
||||
"gross_cents":crate::inventory::decimal(gross.into(),10000),"best_fill_price":fills.first().map(|f|crate::inventory::decimal(f.price.into(),100)),
|
||||
"worst_fill_price":fills.last().map(|f|crate::inventory::decimal(f.price.into(),100)),
|
||||
"average_price_micros":(i128::from(gross)*100).checked_div(i128::from(shares)),
|
||||
"fee_micros":fee,"taker_fee_rate_ppm":rate,
|
||||
"fully_fillable":fully_fillable,"executable":shares>0 && (tif==TimeInForce::Fak || fully_fillable)});
|
||||
|
||||
Reference in New Issue
Block a user