Filter market clarifications by durable event directory IDs
This commit is contained in:
@@ -235,10 +235,10 @@ sequenceDiagram
|
||||
participant C as 客户端
|
||||
participant H as market_http
|
||||
participant E as Exchange
|
||||
C->>H: GET /market-clarifications?market_id=1
|
||||
H->>E: 用目录 ID、limit、offset 和排序方向查询
|
||||
C->>H: GET /market-clarifications?event_id=1&market_id=3
|
||||
H->>E: 按事件和市场目录 ID 筛选,再排序和翻页
|
||||
E-->>H: 规则说明、清盘标记和本地发布时间
|
||||
H-->>C: 已发布的公告数组
|
||||
```
|
||||
|
||||
market_id 使用 assets 查询中的数字目录 ID,可重复传入。默认按公告 ID 降序,每页 20 条;支持 order=id、ascending、offset 和 0 到 100 的 limit。当前查询对其他筛选参数返回 400。
|
||||
event_id 取自本地 events 或 catalog 查询,market_id 取自 assets 查询。两个参数均可重复,同类 ID 取并集,同时指定事件与市场时取交集。独立市场的公告也能通过 market_id 查询。默认按公告 ID 降序,每页 20 条;支持 order=id、ascending、offset 和 0 到 100 的 limit。当前查询对其他筛选参数返回 400。
|
||||
|
||||
@@ -255,11 +255,13 @@ fn clarifications(engine: &Mutex<Exchange>, query: &str) -> Reply {
|
||||
let invalid = (400, "Invalid clarification query");
|
||||
let fields: Vec<(String, String)> = serde_urlencoded::from_str(query).map_err(|_| invalid)?;
|
||||
let mut ids = Vec::new();
|
||||
let mut events = Vec::new();
|
||||
let mut limit = 20;
|
||||
let mut offset = 0;
|
||||
let mut ascending = false;
|
||||
for (key, value) in fields {
|
||||
match key.as_str() {
|
||||
"event_id" => events.push(value.parse().map_err(|_| invalid)?),
|
||||
"market_id" => ids.push(value.parse().map_err(|_| invalid)?),
|
||||
"limit" => limit = value.parse().map_err(|_| invalid)?,
|
||||
"offset" => offset = value.parse().map_err(|_| invalid)?,
|
||||
@@ -271,7 +273,7 @@ fn clarifications(engine: &Mutex<Exchange>, query: &str) -> Reply {
|
||||
let rows = engine
|
||||
.lock()
|
||||
.map_err(|_| (500, "Internal server error"))?
|
||||
.market_clarifications(&ids, limit, offset, ascending)
|
||||
.filtered_market_clarifications(&ids, &events, limit, offset, ascending)
|
||||
.map_err(|e| match e {
|
||||
exchange::MarketDataError::Invalid(_) => invalid,
|
||||
exchange::MarketDataError::Unavailable => (500, "Internal server error"),
|
||||
@@ -549,6 +551,8 @@ mod tests {
|
||||
"/market-clarifications?market_id=9999&market_id={note_id}&order=id&ascending=true"
|
||||
);
|
||||
let cases = [
|
||||
("GET","/market-clarifications?event_id=1&event_id=2",String::new(),200,Some(json!([]))),
|
||||
("GET","/market-clarifications?event_id=0",String::new(),400,None),
|
||||
("GET",note_query.as_str(),String::new(),200,Some(note)),
|
||||
("GET","/market-clarifications?limit=0",String::new(),200,Some(json!([]))),
|
||||
("GET","/market-clarifications?offset=1",String::new(),200,Some(json!([]))),
|
||||
|
||||
Reference in New Issue
Block a user