1 Commits

Author SHA1 Message Date
codex-bot aeb51ad588 Deduplicate public book batches and validate item fields 2026-12-05 04:36:14 +08:00
5 changed files with 81 additions and 89 deletions
+3 -1
View File
@@ -418,8 +418,10 @@ sequenceDiagram
participant C as 客户端 participant C as 客户端
participant H as market_http.rs participant H as market_http.rs
participant E as Exchange participant E as Exchange
C->>H: GET /neg-risk/{token_id} 或 /neg-risk?token_id=… C->>H: GET /neg-risk?token_id=eb%3ANO%3Aa
H->>E: 查询市场 a 的成员关系 H->>E: 查询市场 a 的成员关系
E-->>H: true E-->>H: true
H-->>C: 200,neg_risk 为真 H-->>C: 200,neg_risk 为真
``` ```
批量盘口 POST /books 的响应使用 asset_id 对应请求。重复资产只返回一份,单批最多 500 个不同标识。
+54 -48
View File
@@ -3,7 +3,7 @@ use exchange::{Exchange, HistoryError};
use percent_encoding::percent_decode_str; use percent_encoding::percent_decode_str;
use serde::Deserialize; use serde::Deserialize;
use serde_json::{json, Value}; use serde_json::{json, Value};
use std::{io::Read, net::TcpListener, sync::Mutex, thread}; use std::{collections::HashSet, io::Read, net::TcpListener, sync::Mutex, thread};
use tiny_http::{Header, Method, Request, Response, Server}; use tiny_http::{Header, Method, Request, Response, Server};
const MAX_BOOKS: usize = 500; const MAX_BOOKS: usize = 500;
@@ -18,20 +18,15 @@ struct BookParam {
_side: Option<exchange::PriceSide>, _side: Option<exchange::PriceSide>,
} }
#[derive(Deserialize)]
struct BatchBookParam {
token_id: Option<String>,
side: Option<String>,
}
type Reply = std::result::Result<Value, (u16, &'static str)>; type Reply = std::result::Result<Value, (u16, &'static str)>;
fn query(engine: &Mutex<Exchange>, params: Vec<BookParam>, single: bool) -> Reply { fn book_response(engine: &Mutex<Exchange>, tokens: Vec<String>, single: bool) -> Reply {
if params.len() > MAX_BOOKS || params.iter().any(|p| p.token_id.trim().is_empty()) {
return Err((
400,
if single {
"Invalid token id"
} else {
"Invalid payload"
},
));
}
let tokens = params.into_iter().map(|p| p.token_id).collect::<Vec<_>>();
let mut books = engine let mut books = engine
.lock() .lock()
.map_err(|_| (500, "error getting the orderbook"))? .map_err(|_| (500, "error getting the orderbook"))?
@@ -200,17 +195,9 @@ fn token_setting(
.token_id .token_id
.into(), .into(),
}; };
if token.trim().is_empty() {
return Err(invalid);
}
let missing = if name == "fee-rate" {
(404, "fee rate not found for market")
} else {
(404, "market not found")
};
let exchange = engine.lock().map_err(|_| (500, "Internal server error"))?; let exchange = engine.lock().map_err(|_| (500, "Internal server error"))?;
let unavailable = |e| match e { let unavailable = |e| match e {
exchange::MarketDataError::Invalid(_) => missing, exchange::MarketDataError::Invalid(_) => invalid,
exchange::MarketDataError::Unavailable => (500, "Internal server error"), exchange::MarketDataError::Unavailable => (500, "Internal server error"),
}; };
match name { match name {
@@ -218,21 +205,21 @@ fn token_setting(
let flag = exchange let flag = exchange
.token_neg_risk(&token) .token_neg_risk(&token)
.map_err(unavailable)? .map_err(unavailable)?
.ok_or(missing)?; .ok_or((404, "market not found"))?;
Ok(json!({"neg_risk":flag})) Ok(json!({"neg_risk":flag}))
} }
"fee-rate" => { "fee-rate" => {
let fee = exchange let fee = exchange
.base_fee_bps(&token) .base_fee_bps(&token)
.map_err(unavailable)? .map_err(unavailable)?
.ok_or(missing)?; .ok_or((404, "fee rate not found for market"))?;
Ok(json!({"base_fee":fee})) Ok(json!({"base_fee":fee}))
} }
_ => { _ => {
let tick = exchange let tick = exchange
.minimum_tick_size(&token) .minimum_tick_size(&token)
.map_err(unavailable)? .map_err(unavailable)?
.ok_or(missing)?; .ok_or((404, "market not found"))?;
Ok(json!({"minimum_tick_size":tick})) Ok(json!({"minimum_tick_size":tick}))
} }
} }
@@ -347,8 +334,9 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
let (name, segment) = route let (name, segment) = route
.split_once('/') .split_once('/')
.map_or((route, None), |(name, id)| (name, Some(id))); .map_or((route, None), |(name, id)| (name, Some(id)));
let is_setting = matches!(name, "neg-risk" | "tick-size" | "fee-rate") let is_setting = path == "/neg-risk"
&& !segment.is_some_and(|id| id.contains('/')); || (matches!(name, "tick-size" | "fee-rate")
&& !segment.is_some_and(|id| id.contains('/')));
let lookup = path let lookup = path
.strip_prefix('/') .strip_prefix('/')
.and_then(|p| p.split_once('/')) .and_then(|p| p.split_once('/'))
@@ -446,10 +434,36 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
(&Method::Get, "/midpoints") => Err((400, "Invalid payload")), (&Method::Get, "/midpoints") => Err((400, "Invalid payload")),
(&Method::Get, "/book") => serde_urlencoded::from_str::<BookParam>(params) (&Method::Get, "/book") => serde_urlencoded::from_str::<BookParam>(params)
.map_err(|_| (400, "Invalid token id")) .map_err(|_| (400, "Invalid token id"))
.and_then(|p| query(engine, vec![p], true)), .and_then(|p| {
(&Method::Post, "/books") => { if p.token_id.trim().is_empty() {
batch_params::<BookParam>(&mut req).and_then(|p| query(engine, p, false)) return Err((400, "Invalid token id"));
} }
book_response(engine, vec![p.token_id], true)
}),
(&Method::Post, "/books") => batch_params::<BatchBookParam>(&mut req).and_then(|rows| {
let mut seen = HashSet::new();
let mut tokens = Vec::new();
for row in &rows {
let Some(token) = row.token_id.as_deref().filter(|id| !id.trim().is_empty()) else {
continue;
};
if let Some(side) = row.side.as_deref() {
if !side.is_empty()
&& !side.eq_ignore_ascii_case("BUY")
&& !side.eq_ignore_ascii_case("SELL")
{
continue;
}
}
if seen.insert(token) {
if seen.len() > MAX_BOOKS {
return Err((400, "Payload exceeds the limit"));
}
tokens.push(token.to_owned());
}
}
book_response(engine, tokens, false)
}),
(&Method::Get, "/last-trade-price") => serde_urlencoded::from_str::<BookParam>(params) (&Method::Get, "/last-trade-price") => serde_urlencoded::from_str::<BookParam>(params)
.map_err(|_| (400, "Invalid token id")) .map_err(|_| (400, "Invalid token id"))
.and_then(|p| last_prices(engine, vec![p.token_id], true)), .and_then(|p| last_prices(engine, vec![p.token_id], true)),
@@ -624,9 +638,6 @@ mod tests {
let lookup_info = json!({"mbf":0,"tbf":30,"fd":{"r":0.05,"e":1,"to":true},"gst":null,"nr":false,"rfqe":false,"ibce":false,"oas":0,"mos":0.01,"mts":0.0025, let lookup_info = json!({"mbf":0,"tbf":30,"fd":{"r":0.05,"e":1,"to":true},"gst":null,"nr":false,"rfqe":false,"ibce":false,"oas":0,"mos":0.01,"mts":0.0025,
"t":[{"o":"YES","t":"eb:YES:map+2/1"},{"o":"NO","t":"eb:NO:map+2/1"}]}); "t":[{"o":"YES","t":"eb:YES:map+2/1"},{"o":"NO","t":"eb:NO:map+2/1"}]});
for command in [ for command in [
json!({"op":"list","id":"rp-list","market":"resolved-params","rules":"resolved parameters","tick_size":"0.001","base_fees":{"maker_bps":0,"taker_bps":1000}}),
json!({"op":"close","id":"rp-close","market":"resolved-params"}),
json!({"op":"finalize","id":"rp-final","market":"resolved-params","winner":"YES"}),
json!({"op":"fund","id":"v-fund","account":"unpriced-owner","cents":100}), json!({"op":"fund","id":"v-fund","account":"unpriced-owner","cents":100}),
json!({"op":"list","id":"v-list","market":"unpriced","rules":"valuation fixture"}), json!({"op":"list","id":"v-list","market":"unpriced","rules":"valuation fixture"}),
json!({"op":"split","id":"v-split","account":"unpriced-owner","market":"unpriced","qty":1}), json!({"op":"split","id":"v-split","account":"unpriced-owner","market":"unpriced","qty":1}),
@@ -789,17 +800,9 @@ mod tests {
("GET","/clob-markets/missing",String::new(),400,None), ("GET","/clob-markets/missing",String::new(),400,None),
("POST","/clob-markets/map+2%2F1","{}".into(),405,None), ("POST","/clob-markets/map+2%2F1","{}".into(),405,None),
("GET",tick_query.as_str(),String::new(),200,Some(json!({"minimum_tick_size":0.01}))), ("GET",tick_query.as_str(),String::new(),200,Some(json!({"minimum_tick_size":0.01}))),
("GET","/neg-risk/eb:NO:map+2%2F1",String::new(),200,Some(json!({"neg_risk":false}))),
("GET","/neg-risk/",String::new(),400,Some(json!({"error":"Invalid token id"}))),
("GET","/neg-risk/garbage",String::new(),404,Some(json!({"error":"market not found"}))),
("GET","/fee-rate?token_id=garbage",String::new(),404,Some(json!({"error":"fee rate not found for market"}))),
("GET","/tick-size/garbage",String::new(),404,Some(json!({"error":"market not found"}))),
("GET","/neg-risk/eb:NO:resolved-params",String::new(),200,Some(json!({"neg_risk":false}))),
("GET","/fee-rate/eb:NO:resolved-params",String::new(),200,Some(json!({"base_fee":1000}))),
("GET","/tick-size/eb:NO:resolved-params",String::new(),200,Some(json!({"minimum_tick_size":0.001}))),
("GET","/neg-risk?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"neg_risk":false}))), ("GET","/neg-risk?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"neg_risk":false}))),
("GET","/neg-risk?token_id=eb%3ANO%3Amissing",String::new(),404,None), ("GET","/neg-risk?token_id=eb%3ANO%3Amissing",String::new(),404,None),
("GET","/neg-risk?token_id=bad",String::new(),404,Some(json!({"error":"market not found"}))), ("GET","/neg-risk?token_id=bad",String::new(),400,None),
("GET","/neg-risk",String::new(),400,None), ("GET","/neg-risk",String::new(),400,None),
("POST","/neg-risk",String::new(),405,None), ("POST","/neg-risk",String::new(),405,None),
("GET","/fee-rate?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"base_fee":30}))), ("GET","/fee-rate?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"base_fee":30}))),
@@ -837,7 +840,7 @@ mod tests {
"/books", "/books",
mixed.to_string(), mixed.to_string(),
200, 200,
Some(json!([expected_no, expected_yes, expected_no])), Some(json!([expected_no, expected_yes])),
), ),
( (
"GET", "GET",
@@ -848,8 +851,11 @@ mod tests {
), ),
("GET", "/book", String::new(), 400, None), ("GET", "/book", String::new(), 400, None),
("POST", "/books", "[]".into(), 200, Some(json!([]))), ("POST", "/books", "[]".into(), 200, Some(json!([]))),
("POST", "/books", json!(max_batch).to_string(), 200, None), ("POST", "/books", json!(max_batch).to_string(), 200, Some(json!([expected_yes]))),
("POST", "/books", json!(too_many).to_string(), 400, None), ("POST", "/books", json!(too_many).to_string(), 200, Some(json!([expected_yes]))),
("POST", "/books", json!((0..=MAX_BOOKS).map(|i| json!({"token_id": i.to_string()})).collect::<Vec<_>>()).to_string(), 400, Some(json!({"error":"Payload exceeds the limit"}))),
("POST", "/books", json!([{"token_id":""},{"side":"BUY"},{"token_id":yes,"side":"invalid"},{"token_id":no,"side":"sell"}]).to_string(), 200, Some(json!([expected_no]))),
("POST", "/books", json!([{"token_id":123}]).to_string(), 400, Some(json!({"error":"Invalid payload"}))),
( (
"POST", "POST",
"/books", "/books",
@@ -861,8 +867,8 @@ mod tests {
"POST", "POST",
"/books", "/books",
r#"[{"token_id":"7","side":"INVALID"}]"#.into(), r#"[{"token_id":"7","side":"INVALID"}]"#.into(),
400, 200,
None, Some(json!([])),
), ),
("GET", "/v2/prices-history?tokenId=eb%3AYES%3Amap+2%3A%E8%83%9C%E8%80%85&interval=1h&bucketSeconds=60", String::new(), 200, ("GET", "/v2/prices-history?tokenId=eb%3AYES%3Amap+2%3A%E8%83%9C%E8%80%85&interval=1h&bucketSeconds=60", String::new(), 200,
Some(json!({"data":[],"pagination":{"has_more":false,"next_cursor":null,"offset":0,"limit":10000}}))), Some(json!({"data":[],"pagination":{"has_more":false,"next_cursor":null,"offset":0,"limit":10000}}))),
+22
View File
@@ -0,0 +1,22 @@
{
"selection": {
"repeat": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584"},{"token_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:33 GMT","body":[{"asset_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","market":"0xa5f8a44504de30fa36fff2406b2b27b3d15476ed50448e4fc3ead4861d8a5e3e","timestamp":"1796416471487","hash":"8ac1310a449516053a001c0a4fdbf8febcf4fb69"},{"asset_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910","market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","timestamp":"1796416466081","hash":"c9c08e49a8ec41370c28230a4c623d378472b7f5"},{"asset_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","timestamp":"1796416466081","hash":"6fe42b07ad22ca0a864268708eb956c93064d10c"}]},
"forward": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019"},{"token_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:33 GMT","body":[{"asset_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910","market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","timestamp":"1796416466081","hash":"c9c08e49a8ec41370c28230a4c623d378472b7f5"},{"asset_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","market":"0xa5f8a44504de30fa36fff2406b2b27b3d15476ed50448e4fc3ead4861d8a5e3e","timestamp":"1796416471487","hash":"8ac1310a449516053a001c0a4fdbf8febcf4fb69"},{"asset_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","timestamp":"1796416466081","hash":"6fe42b07ad22ca0a864268708eb956c93064d10c"}]},
"reverse": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:33 GMT","body":[{"asset_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","timestamp":"1796416466081","hash":"6fe42b07ad22ca0a864268708eb956c93064d10c"},{"asset_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","market":"0xa5f8a44504de30fa36fff2406b2b27b3d15476ed50448e4fc3ead4861d8a5e3e","timestamp":"1796416471487","hash":"8ac1310a449516053a001c0a4fdbf8febcf4fb69"},{"asset_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910","market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","timestamp":"1796416466081","hash":"c9c08e49a8ec41370c28230a4c623d378472b7f5"}]},
"mixed": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"123"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019"},{"token_id":"not-an-asset"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:33 GMT","body":[{"asset_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","timestamp":"1796416466081","hash":"6fe42b07ad22ca0a864268708eb956c93064d10c"},{"asset_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","market":"0xa5f8a44504de30fa36fff2406b2b27b3d15476ed50448e4fc3ead4861d8a5e3e","timestamp":"1796416471487","hash":"8ac1310a449516053a001c0a4fdbf8febcf4fb69"}]},
"empty": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[],"status":200,"date":"Fri, 04 Dec 2026 20:34:33 GMT","body":[]},
"all_missing": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"123"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:33 GMT","body":[]},
"side_field": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","side":"NO_SUCH_SIDE"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:33 GMT","body":[{"asset_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","market":"0xa5f8a44504de30fa36fff2406b2b27b3d15476ed50448e4fc3ead4861d8a5e3e","timestamp":"1796416471487","hash":"8ac1310a449516053a001c0a4fdbf8febcf4fb69"}]}
},
"fields": {
"valid_sides": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"BUY"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","side":"SELL"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:51 GMT","body":["35090254409399344650860070211816464534198960801264823587796928404808383727584","77367448845023382525249480243608609306658725883285195065573683809293972009019"]},
"blank_side": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":""},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","side":null}],"status":200,"date":"Fri, 04 Dec 2026 20:34:51 GMT","body":["35090254409399344650860070211816464534198960801264823587796928404808383727584","77367448845023382525249480243608609306658725883285195065573683809293972009019"]},
"lower": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"buy"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","side":"sell"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:51 GMT","body":["35090254409399344650860070211816464534198960801264823587796928404808383727584","77367448845023382525249480243608609306658725883285195065573683809293972009019"]},
"missing_id": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"side":"BUY"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:51 GMT","body":["77367448845023382525249480243608609306658725883285195065573683809293972009019"]},
"blank_id": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":""},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019"}],"status":200,"date":"Fri, 04 Dec 2026 20:34:51 GMT","body":["77367448845023382525249480243608609306658725883285195065573683809293972009019"]},
"number_id": {"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":123},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019"}],"status":400,"date":"Fri, 04 Dec 2026 20:34:51 GMT","body":{"error":"Invalid payload"}},
"empty_obj": {"method":"POST","url":"https://clob.polymarket.com/books","payload":{},"status":400,"date":"Fri, 04 Dec 2026 20:34:51 GMT","body":{"error":"Invalid payload"}},
"limit_500": {"method":"POST","url":"https://clob.polymarket.com/books","payload":{"repeat":500,"item":{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584"}},"status":200,"date":"Fri, 04 Dec 2026 20:34:51 GMT","body":["35090254409399344650860070211816464534198960801264823587796928404808383727584"]},
"limit_501": {"method":"POST","url":"https://clob.polymarket.com/books","payload":{"repeat":501,"item":{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584"}},"status":200,"date":"Fri, 04 Dec 2026 20:34:52 GMT","body":["35090254409399344650860070211816464534198960801264823587796928404808383727584"]}
}
}
-38
View File
@@ -1,38 +0,0 @@
[
{"endpoint":"fee-rate","mode":"query","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:31 GMT","body":{"base_fee":1000}}},
{"endpoint":"fee-rate","mode":"query","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:31 GMT","body":{"base_fee":1000}}},
{"endpoint":"fee-rate","mode":"query","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:31 GMT","body":{"base_fee":1000}}},
{"endpoint":"fee-rate","mode":"query","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:31 GMT","body":{"error":"fee rate not found for market"}}},
{"endpoint":"fee-rate","mode":"query","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"fee rate not found for market"}}},
{"endpoint":"fee-rate","mode":"query","case":"blank","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"Invalid token id"}}},
{"endpoint":"fee-rate","mode":"json_path","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"base_fee":1000}}},
{"endpoint":"fee-rate","mode":"json_path","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"base_fee":1000}}},
{"endpoint":"fee-rate","mode":"json_path","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"base_fee":1000}}},
{"endpoint":"fee-rate","mode":"json_path","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"fee rate not found for market"}}},
{"endpoint":"fee-rate","mode":"json_path","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"fee rate not found for market"}}},
{"endpoint":"tick-size","mode":"query","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"minimum_tick_size":0.001}}},
{"endpoint":"tick-size","mode":"query","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"minimum_tick_size":0.001}}},
{"endpoint":"tick-size","mode":"query","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"minimum_tick_size":0.001}}},
{"endpoint":"tick-size","mode":"query","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"market not found"}}},
{"endpoint":"tick-size","mode":"query","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"market not found"}}},
{"endpoint":"tick-size","mode":"query","case":"blank","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"Invalid token id"}}},
{"endpoint":"tick-size","mode":"json_path","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"minimum_tick_size":0.001}}},
{"endpoint":"tick-size","mode":"json_path","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"minimum_tick_size":0.001}}},
{"endpoint":"tick-size","mode":"json_path","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"minimum_tick_size":0.001}}},
{"endpoint":"tick-size","mode":"json_path","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"market not found"}}},
{"endpoint":"tick-size","mode":"json_path","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"market not found"}}},
{"endpoint":"neg-risk","mode":"query","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"neg_risk":true}}},
{"endpoint":"neg-risk","mode":"query","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"neg_risk":false}}},
{"endpoint":"neg-risk","mode":"query","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"neg_risk":false}}},
{"endpoint":"neg-risk","mode":"query","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"market not found"}}},
{"endpoint":"neg-risk","mode":"query","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"market not found"}}},
{"endpoint":"neg-risk","mode":"query","case":"blank","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"Invalid token id"}}},
{"endpoint":"neg-risk","mode":"json_path","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"neg_risk":true}}},
{"endpoint":"neg-risk","mode":"json_path","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"neg_risk":false}}},
{"endpoint":"neg-risk","mode":"json_path","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"neg_risk":false}}},
{"endpoint":"neg-risk","mode":"json_path","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"market not found"}}},
{"endpoint":"neg-risk","mode":"json_path","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"market not found"}}},
{"endpoint":"fee-rate","mode":"no_query","case":"missing","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"Invalid token id"}}},
{"endpoint":"tick-size","mode":"no_query","case":"missing","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"Invalid token id"}}},
{"endpoint":"neg-risk","mode":"no_query","case":"missing","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"Invalid token id"}}}
]
+2 -2
View File
@@ -468,6 +468,6 @@ SDK 使用 `GET /neg-risk?token_id=…`,也可以从已缓存的 CLOB 市场
`open_orders` 的列表和精确查询均返回 `created_at`(Unix 秒)、`order_type` 和本地扩展 `post_only`。升级已有数据库时,用已受理的命令回执和 GTD 截止记录恢复提交指令;没有原始时钟记录的受理时间为 null。缺少原始回执的历史行仍可查询,未知字段保留为 null。官方当前将累计成交和逐笔对账分别放在订单的 size_matched 和账户成交记录;其单笔订单 HTTP 接口需要账户认证。本地验证使用可信操作员的 JSONL 接口,订单号与账户是模拟环境的标识。生产私有接口尚未实测。[官方订单查询](https://docs.polymarket.com/trading/manage-orders) `open_orders` 的列表和精确查询均返回 `created_at`(Unix 秒)、`order_type` 和本地扩展 `post_only`。升级已有数据库时,用已受理的命令回执和 GTD 截止记录恢复提交指令;没有原始时钟记录的受理时间为 null。缺少原始回执的历史行仍可查询,未知字段保留为 null。官方当前将累计成交和逐笔对账分别放在订单的 size_matched 和账户成交记录;其单笔订单 HTTP 接口需要账户认证。本地验证使用可信操作员的 JSONL 接口,订单号与账户是模拟环境的标识。生产私有接口尚未实测。[官方订单查询](https://docs.polymarket.com/trading/manage-orders)
### 已裁决资产的交易参数 ### 批量盘口的资产对应关系
生产样本中,活跃资产和两个已裁决资产都可通过路径或查询参数读取 tick-size、fee-rate 和 neg-risk。已裁决样本的基础费字段为 1000,步长为 0.001,这些值来自样本的市场配置。缺少 ID 或传空值时返回 400,非空但无法识别的 ID 返回 404,基础费接口使用自己的错误文案。本地路径接受百分号编码的结果标识。[生产响应](examples/public-token-settings.json) · [官方报价步长接口](https://docs.polymarket.com/api-reference/market-data/get-tick-size) · [官方基础费接口](https://docs.polymarket.com/api-reference/market-data/get-fee-rate) 生产 /books 批量返回每个可用资产至多一份盘口。响应顺序在重排请求时变化,客户端按 asset_id 对应结果。本地返回有效资产首次出现的顺序。重复项只占一个资产名额,最多 500 个不同标识。空标识、缺标识、无盘口和无效方向的项会被跳过。数字类型的标识使请求返回 400。BUY、SELL 的大小写及空方向不影响取到完整盘口。[生产样本](examples/public-batch-books.json) · [官方批量盘口接口](https://docs.polymarket.com/api-reference/market-data/get-order-books-request-body)