Serve V2 token directory queries for local assets
This commit is contained in:
@@ -423,3 +423,5 @@ sequenceDiagram
|
||||
E-->>H: true
|
||||
H-->>C: 200,neg_risk 为真
|
||||
```
|
||||
|
||||
GET /v2/tokens 支持逗号分隔的资产 ID 或条件及互斥组 ID。两个选择器择一,回执按资产关联市场、事件和裁决结果。
|
||||
|
||||
@@ -329,7 +329,12 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
if req.method() == &Method::Get
|
||||
&& matches!(
|
||||
path,
|
||||
"/v2/prices-history" | "/v2/trades" | "/v2/resolutions" | "/v2/value" | "/v2/oi"
|
||||
"/v2/tokens"
|
||||
| "/v2/prices-history"
|
||||
| "/v2/trades"
|
||||
| "/v2/resolutions"
|
||||
| "/v2/value"
|
||||
| "/v2/oi"
|
||||
)
|
||||
{
|
||||
let (status, body) = data_page(path, params, engine);
|
||||
@@ -473,6 +478,7 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
| "/market-clarifications"
|
||||
| "/v2/oi"
|
||||
| "/v2/value"
|
||||
| "/v2/tokens"
|
||||
| "/v2/trades"
|
||||
| "/v2/resolutions"
|
||||
| "/v2/prices-history",
|
||||
@@ -513,6 +519,7 @@ fn read_page<Q: serde::de::DeserializeOwned>(
|
||||
|
||||
fn data_page(path: &str, params: &str, engine: &Mutex<Exchange>) -> (u16, Value) {
|
||||
let page = match path {
|
||||
"/v2/tokens" => read_page(params, engine, Exchange::public_tokens),
|
||||
"/v2/oi" => read_page(params, engine, Exchange::public_open_interest),
|
||||
"/v2/value" => read_page(params, engine, Exchange::public_portfolio_value),
|
||||
"/v2/trades" => read_page(params, engine, Exchange::public_trade_feed),
|
||||
@@ -525,6 +532,10 @@ fn data_page(path: &str, params: &str, engine: &Mutex<Exchange>) -> (u16, Value)
|
||||
400,
|
||||
json!({"code":"invalid_request","error":message,"retryable":false}),
|
||||
),
|
||||
Err(HistoryError::Unavailable) if path == "/v2/tokens" => (
|
||||
503,
|
||||
json!({"code":"unavailable","error":"token directory unavailable","retryable":true}),
|
||||
),
|
||||
Err(HistoryError::Unavailable) if path == "/v2/oi" => (
|
||||
503,
|
||||
json!({"code":"unavailable","error":"open interest unavailable","retryable":true}),
|
||||
@@ -689,6 +700,10 @@ mod tests {
|
||||
assert_eq!(quoted["outcomePrices"], r#"["0.4","0.6"]"#);
|
||||
let empty_trades = json!({"data":[],"pagination":{"limit":100,"offset":0,"has_more":false,"next_cursor":null}});
|
||||
let cases = [
|
||||
("GET","/v2/tokens?token_ids=eb:NO:s,00123,eb:NO:s,eb:YES:s",String::new(),200,Some(db.public_tokens(serde_json::from_value(json!({"token_id":"eb:NO:s,123,eb:YES:s"})).unwrap()).unwrap())),
|
||||
("GET","/v2/tokens?condition=s&token_id=eb:YES:s",String::new(),400,None),
|
||||
("GET","/v2/tokens?token_id=00123,123",String::new(),200,Some(json!({"data":[]}))),
|
||||
("POST","/v2/tokens",String::new(),405,None),
|
||||
("GET","/v2/oi?conditionId=s,s",String::new(),200,Some(json!({"data":[{"condition_id":"s","value":0}]}))),
|
||||
("GET","/v2/oi?condition_id=0x0000000000000000000000000000000000000000000000000000000000000001",String::new(),200,Some(json!({"data":[]}))),
|
||||
("GET","/v2/oi?condition=bad-hash",String::new(),400,Some(json!({"code":"invalid_request","error":"invalid condition: bad-hash","retryable":false}))),
|
||||
|
||||
Reference in New Issue
Block a user