Settle sub-cent orders and migrate historical book prices
This commit is contained in:
@@ -7,6 +7,34 @@ use std::num::NonZeroU32;
|
||||
|
||||
pub(crate) struct TickSize(pub i64);
|
||||
|
||||
// A stored price is in 0.0001 dollars. One price unit times one order lot
|
||||
// (0.01 shares) is exactly one cash micro.
|
||||
pub(crate) const PAR: i64 = 10_000;
|
||||
pub(crate) const PRICE_MICROS: i64 = 100;
|
||||
pub(crate) fn input(cents: Option<i64>, micros: Option<i64>) -> Result<Option<i64>> {
|
||||
match (cents, micros) {
|
||||
(None, None) => Ok(None),
|
||||
(Some(c), None) if (0..=100).contains(&c) => Ok(Some(c * 100)),
|
||||
(None, Some(m)) if (0..=1_000_000).contains(&m) && m % PRICE_MICROS == 0 => {
|
||||
Ok(Some(m / PRICE_MICROS))
|
||||
}
|
||||
_ => anyhow::bail!("provide one valid price in cents or micros"),
|
||||
}
|
||||
}
|
||||
pub(crate) fn required(cents: Option<i64>, micros: Option<i64>) -> Result<i64> {
|
||||
input(cents, micros)?.ok_or_else(|| anyhow::anyhow!("price required"))
|
||||
}
|
||||
pub(crate) fn validate(tick: Option<&TickSize>, price: i64) -> Result<()> {
|
||||
if let Some(tick) = tick {
|
||||
tick.check(price * PRICE_MICROS)
|
||||
} else {
|
||||
ensure!(
|
||||
(0..=PAR).contains(&price) && price % 100 == 0,
|
||||
"legacy market requires a whole-cent price"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
impl TickSize {
|
||||
pub(crate) fn parse(value: &str) -> Result<Self> {
|
||||
let micros = match value.trim_end_matches('0') {
|
||||
@@ -51,8 +79,7 @@ impl TickSize {
|
||||
}
|
||||
|
||||
pub fn local_step(&self) -> NonZeroU32 {
|
||||
// Each supported sub-cent step divides one cent exactly.
|
||||
NonZeroU32::new((self.0 / 10_000).max(1) as u32).unwrap()
|
||||
NonZeroU32::new((self.0 / PRICE_MICROS) as u32).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +123,7 @@ impl LimitAmounts {
|
||||
json!({"asset_id":assets::id(&self.market,&self.outcome),"tick_size":tick.text(),
|
||||
"price_micros":self.price_micros,"size_micros":shares,"collateral_micros":collateral,
|
||||
"makerAmount":maker.to_string(),"takerAmount":taker.to_string(),
|
||||
"local_precision_supported":self.price_micros%10000==0}),
|
||||
"local_precision_supported":true}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user