Expose the current committed tick size by outcome ID

This commit is contained in:
2026-12-03 09:32:49 +08:00
parent b523a8890f
commit 81595a89ee
10 changed files with 149 additions and 4 deletions
+2 -2
View File
@@ -92,8 +92,8 @@ fn find(
.map(|s| s.text())
.unwrap_or_else(|| "0.01".into()),
tick_size: TickSize::load(tx, market)?
.map(|s| s.text())
.unwrap_or_else(|| "0.01".into()),
.unwrap_or(TickSize::WHOLE_CENT)
.text(),
neg_risk,
last_trade_price: Quote::current(tx, market, outcome)?
.last
+26 -2
View File
@@ -1,4 +1,4 @@
use crate::{assets, minimum_size::MinimumSize};
use crate::{assets, inventory, minimum_size::MinimumSize, Exchange, MarketDataError};
use anyhow::{ensure, Result};
use rusqlite::{params, Connection, OptionalExtension, Transaction};
use serde::Deserialize;
@@ -35,7 +35,31 @@ pub(crate) fn validate(tick: Option<&TickSize>, price: i64) -> Result<()> {
Ok(())
}
}
impl Exchange {
/// Current grid for a listed local outcome, including the whole-cent legacy grid.
pub fn minimum_tick_size(
&self,
token: &str,
) -> Result<Option<serde_json::Number>, MarketDataError> {
let (_, market) = assets::parse_id(token)
.map_err(|_| MarketDataError::Invalid("Invalid token id".into()))?;
let mut stmt = self.db.prepare_cached(
"SELECT s.step_micros FROM markets m LEFT JOIN market_tick_sizes s ON s.market=m.id WHERE m.id=?1"
)?;
let tick = stmt
.query_row([market], |r| r.get::<_, Option<i64>>(0))
.optional()?;
Ok(tick.map(|step| step.map(TickSize).unwrap_or(TickSize::WHOLE_CENT).number()))
}
}
impl TickSize {
pub(crate) const WHOLE_CENT: Self = Self(10_000);
fn number(&self) -> serde_json::Number {
inventory::decimal(self.0.into(), inventory::UNIT)
}
pub(crate) fn parse(value: &str) -> Result<Self> {
let micros = match value.trim_end_matches('0') {
"0.1" => 100_000,
@@ -66,7 +90,7 @@ impl TickSize {
}
pub fn text(&self) -> String {
format!("0.{:06}", self.0).trim_end_matches('0').to_owned()
self.number().to_string()
}
pub fn check(&self, price: i64) -> Result<()> {