Omit never-traded assets from batch last-trade responses

This commit is contained in:
2026-12-03 10:15:38 +08:00
parent 1b2376ccb4
commit 74749bfdb8
6 changed files with 17 additions and 17 deletions
+5 -4
View File
@@ -193,8 +193,10 @@ fn last_prices(engine: &Mutex<Exchange>, tokens: Vec<String>, single: bool) -> R
exchange::MarketDataError::Unavailable => (500, "Internal server error"),
})?;
if single {
let row = rows.pop().ok_or((500, "Internal server error"))?;
Ok(json!({"price":row["price"],"side":row["side"]}))
Ok(match rows.pop() {
Some(row) => json!({"price":row["price"],"side":row["side"]}),
None => json!({"price":"0.5","side":""}),
})
} else {
Ok(Value::Array(rows))
}
@@ -457,8 +459,7 @@ mod tests {
{"token_id":no}, {"token_id":"7"}, {"token_id":yes,"side":"BUY"}, {"token_id":no}
]);
let no_fills = json!({"price":"0.5","side":""});
let batch_no_fills = json!([{"token_id":yes,"price":"0.5","side":""},
{"token_id":no,"price":"0.5","side":""}]);
let batch_no_fills = json!([]);
let csv = serde_urlencoded::to_string([("token_ids", format!("{yes},{no}"))]).unwrap();
let last_batch = format!("/last-trades-prices?{csv}");
let last_single = encoded.replacen("/book?", "/last-trade-price?", 1);