Record committed best-bid and ask changes for resumable quote history
This commit is contained in:
@@ -236,6 +236,7 @@ impl Listing {
|
||||
pub(crate) enum Query {
|
||||
Estimate(crate::estimate::Request),
|
||||
PricesHistory(crate::prices_history::Request),
|
||||
QuoteHistory(crate::quotes::Filter),
|
||||
Resolution {
|
||||
market: String,
|
||||
},
|
||||
@@ -276,6 +277,7 @@ pub(crate) enum Query {
|
||||
impl Query {
|
||||
pub fn read(self, db: &Transaction, books: &mut crate::resident::Books) -> Result<Value> {
|
||||
match self {
|
||||
Self::QuoteHistory(request) => request.read(db),
|
||||
Self::PricesHistory(request) => request.read(db),
|
||||
Self::Estimate(request) => request.read(db, books),
|
||||
Self::Resolution { market } => crate::resolution::read(db, &market),
|
||||
@@ -306,13 +308,8 @@ impl Query {
|
||||
}
|
||||
Self::Quote { market, outcome } => {
|
||||
let phase = market_phase(db, &market, &outcome)?;
|
||||
let (bid, ask): (Option<i64>, Option<i64>) = db.query_row(
|
||||
"SELECT MAX(CASE WHEN side='buy' THEN price END),
|
||||
MIN(CASE WHEN side='sell' THEN price END)
|
||||
FROM visible_orders WHERE market=?1 AND outcome=?2",
|
||||
params![market, outcome],
|
||||
|r| Ok((r.get(0)?, r.get(1)?)),
|
||||
)?;
|
||||
let quote = crate::quotes::Quote::current(db, &market, &outcome)?;
|
||||
let (bid, ask) = (quote.bid, quote.ask);
|
||||
// Fills also cover databases created before timestamped history was introduced.
|
||||
let last: Option<i64> = db.query_row(
|
||||
"SELECT (SELECT price FROM (
|
||||
@@ -331,7 +328,7 @@ impl Query {
|
||||
};
|
||||
Ok(
|
||||
json!({"asset_id":assets::id(&market,&outcome),"market":market,"outcome":outcome,"phase":phase,
|
||||
"best_bid_micros":bid.map(|p|p*10000),"best_ask_micros":ask.map(|p|p*10000),
|
||||
"quote_seq":quote.seq,"best_bid_micros":bid.map(|p|p*10000),"best_ask_micros":ask.map(|p|p*10000),
|
||||
"last_trade_micros":last.map(|p|p*10000),"display_price_micros":display,"source":source}),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user