Expose the current committed tick size by outcome ID
This commit is contained in:
@@ -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<()> {
|
||||
|
||||
Reference in New Issue
Block a user