Match observed public last-trade batch semantics
This commit is contained in:
@@ -125,7 +125,7 @@ sequenceDiagram
|
||||
E-->>C: 后续点及是否还有数据
|
||||
```
|
||||
|
||||
行情客户端也可以调用 `GET /last-trade-price`、`GET /last-trades-prices` 和 `POST /last-trades-prices`。GET 批量参数 token_ids 用逗号分隔;本地资产 ID 自身包含逗号时可使用 POST 的 JSON 数组。
|
||||
行情客户端通过 `GET /last-trade-price` 查询单个结果,通过 `POST /last-trades-prices` 发送资产数组。只带 token_ids 查询参数的批量 GET 在生产样本中返回 400。
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
@@ -140,7 +140,7 @@ sequenceDiagram
|
||||
C->>H: 查询一个或多个资产的最后一笔成交
|
||||
H->>E: last_trade_prices
|
||||
E-->>H: 仅返回有成交记录的资产及其方向
|
||||
H-->>C: 单查无成交时使用占位值,批查直接返回数组
|
||||
H-->>C: 单查无成交时使用占位值,批查按资产 ID 排序并去重
|
||||
```
|
||||
|
||||
客户端可通过 `GET /tick-size?token_id=…` 或 `GET /tick-size/{token_id}` 读取当前报价步长。URL 路径中的空格编码为 %20,加号表示加号本身。
|
||||
|
||||
@@ -161,11 +161,6 @@ fn batch_params<T: serde::de::DeserializeOwned>(
|
||||
serde_json::from_slice(&data).map_err(|_| (400, "Invalid payload"))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct TokenList {
|
||||
token_ids: String,
|
||||
}
|
||||
|
||||
fn last_prices(engine: &Mutex<Exchange>, tokens: Vec<String>, single: bool) -> Reply {
|
||||
let mut rows = engine
|
||||
.lock()
|
||||
@@ -451,15 +446,7 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
(&Method::Get, "/last-trade-price") => serde_urlencoded::from_str::<BookParam>(params)
|
||||
.map_err(|_| (400, "Invalid token id"))
|
||||
.and_then(|p| last_prices(engine, vec![p.token_id], true)),
|
||||
(&Method::Get, "/last-trades-prices") => serde_urlencoded::from_str::<TokenList>(params)
|
||||
.map_err(|_| (400, "Invalid payload"))
|
||||
.and_then(|p| {
|
||||
last_prices(
|
||||
engine,
|
||||
p.token_ids.split(',').map(str::to_owned).collect(),
|
||||
false,
|
||||
)
|
||||
}),
|
||||
(&Method::Get, "/last-trades-prices") => Err((400, "Invalid payload")),
|
||||
(&Method::Post, "/last-trades-prices") => {
|
||||
batch_params::<BookParam>(&mut req).and_then(|p| {
|
||||
last_prices(
|
||||
@@ -811,8 +798,10 @@ mod tests {
|
||||
("GET","/tick-size",String::new(),400,Some(json!({"error":"Invalid token id"}))),
|
||||
("POST","/tick-size/eb:YES:e",String::new(),405,None),
|
||||
("GET",last_single.as_str(),String::new(),200,Some(no_fills)),
|
||||
("GET",last_batch.as_str(),String::new(),200,Some(batch_no_fills.clone())),
|
||||
("GET",last_batch.as_str(),String::new(),400,Some(json!({"error":"Invalid payload"}))),
|
||||
("POST","/last-trades-prices",json!([{"token_id":yes,"side":"SELL"},{"token_id":no}]).to_string(),200,Some(batch_no_fills)),
|
||||
("POST","/last-trades-prices","[]".into(),200,Some(json!([]))),
|
||||
("GET","/last-trade-price?token_id=eb:YES:missing",String::new(),200,Some(json!({"price":"0.5","side":""}))),
|
||||
("GET","/last-trade-price?token_id=",String::new(),400,Some(json!({"error":"Invalid token id"}))),
|
||||
("POST","/last-trades-prices",json!(too_many).to_string(),400,Some(json!({"error":"Invalid payload"}))),
|
||||
("DELETE","/last-trades-prices",String::new(),405,None),
|
||||
|
||||
Reference in New Issue
Block a user