Match observed public last-trade batch semantics

This commit is contained in:
2026-12-03 16:14:25 +08:00
parent 9cc3921e3c
commit d7a77c734d
8 changed files with 53 additions and 25 deletions
+8 -3
View File
@@ -15,11 +15,16 @@ pub(crate) fn taker_side(
}
impl Exchange {
/// Return actual last trades, in request order, from one SQLite snapshot.
/// Return one latest trade per asset, sorted by token ID, from one SQLite snapshot.
pub fn last_trade_prices(&self, tokens: &[String]) -> Result<Vec<Value>, MarketDataError> {
if !(1..=500).contains(&tokens.len()) {
return Err(MarketDataError::Invalid("expected 1 to 500 tokens".into()));
if tokens.len() > 500 {
return Err(MarketDataError::Invalid(
"expected at most 500 tokens".into(),
));
}
let mut tokens: Vec<&str> = tokens.iter().map(String::as_str).collect();
tokens.sort_unstable();
tokens.dedup();
let assets = tokens
.iter()
.map(|token| assets::parse_id(token))