Mark outcome positions and report account holdings value
This commit is contained in:
@@ -248,6 +248,9 @@ pub(crate) enum Query {
|
||||
market: String,
|
||||
},
|
||||
Positions(crate::portfolio::Filter),
|
||||
PortfolioValue {
|
||||
account: String,
|
||||
},
|
||||
Activity(crate::activity::Filter),
|
||||
OpenOrders(crate::account_orders::Filter),
|
||||
Trades(crate::account_trades::Filter),
|
||||
@@ -293,6 +296,7 @@ impl Query {
|
||||
Self::Resolution { market } => crate::resolution::read(db, &market),
|
||||
Self::Assets { market } => assets::market_assets(db, &market),
|
||||
Self::Activity(filter) => filter.read(db),
|
||||
Self::PortfolioValue { account } => crate::portfolio::value(db, &account),
|
||||
Self::Positions(filter) => filter.read(db),
|
||||
Self::Trades(filter) => filter.read(db),
|
||||
Self::OpenOrders(filter) => filter.read(db),
|
||||
@@ -320,22 +324,13 @@ impl Query {
|
||||
let phase = market_phase(db, &market, &outcome)?;
|
||||
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 (
|
||||
SELECT f.seq, f.price FROM fills f JOIN orders o ON o.seq=f.bid WHERE o.market=?1 AND o.outcome=?2
|
||||
UNION ALL SELECT seq, CASE WHEN ?2='YES' THEN yes_price ELSE 100-yes_price END FROM paired_fills WHERE market=?1
|
||||
) ORDER BY seq DESC LIMIT 1)",
|
||||
params![market, outcome],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
let (display, source) = match (phase.as_str(), bid, ask, last) {
|
||||
("continuous", Some(b), Some(a), _) if (0..=10).contains(&(a - b)) => {
|
||||
(Some((a + b) * 5000), Some("midpoint"))
|
||||
}
|
||||
("continuous", _, _, Some(p)) => (Some(p * 10000), Some("last_trade")),
|
||||
_ => (None, None),
|
||||
};
|
||||
let last = quote.last;
|
||||
let (display, source) = if phase == "continuous" {
|
||||
quote.mark(&phase)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.unzip();
|
||||
Ok(
|
||||
json!({"asset_id":assets::id(&market,&outcome),"market":market,"outcome":outcome,"phase":phase,
|
||||
"quote_seq":quote.seq,"best_bid_micros":bid.map(|p|p*10000),"best_ask_micros":ask.map(|p|p*10000),
|
||||
|
||||
Reference in New Issue
Block a user