Omit never-traded assets from batch last-trade responses
This commit is contained in:
@@ -137,8 +137,8 @@ sequenceDiagram
|
||||
participant E as Exchange
|
||||
C->>H: 查询一个或多个资产的最后一笔成交
|
||||
H->>E: last_trade_prices
|
||||
E-->>H: 每个资产的成交价和方向
|
||||
H-->>C: 单笔对象或含 token_id 的数组
|
||||
E-->>H: 仅返回有成交记录的资产及其方向
|
||||
H-->>C: 单查无成交时使用占位值,批查直接返回数组
|
||||
```
|
||||
|
||||
客户端可通过 `GET /tick-size?token_id=…` 或 `GET /tick-size/{token_id}` 读取当前报价步长。URL 路径中的空格编码为 %20,加号表示加号本身。
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user