Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 333187c646 | |||
| aeb51ad588 |
@@ -90,7 +90,6 @@ sequenceDiagram
|
||||
flowchart LR
|
||||
main["main.rs"] --> http["market_http.rs"]
|
||||
http --> api["exchange::Exchange::public_books"]
|
||||
http --> clock["exchange::Exchange::server_time"]
|
||||
```
|
||||
|
||||
```mermaid
|
||||
@@ -98,20 +97,12 @@ sequenceDiagram
|
||||
participant C as SDK
|
||||
participant H as market_http
|
||||
participant E as Exchange
|
||||
opt 需要计算 GTD 截止时间
|
||||
C->>H: GET /time
|
||||
H->>E: server_time
|
||||
E-->>H: Unix 秒
|
||||
H-->>C: JSON 整数
|
||||
end
|
||||
C->>H: GET /book?token_id=... 或 POST /books
|
||||
H->>E: 提交本次请求的资产 ID
|
||||
E-->>H: 一个数据库快照中的盘口列表
|
||||
H-->>C: 单盘 JSON 对象或批量 JSON 数组
|
||||
```
|
||||
|
||||
`GET /time` 返回一个 JSON 整数,单位为 Unix 秒。客户端可用它估算本机与交易服务的时钟差,再填写 GTD 的 `expiration`。这是读取时钟的端点,无需账户或资产 ID。
|
||||
|
||||
同一个 HTTP 监听器提供 `GET /v2/prices-history`。客户端按资产查询历史,接续页可以只发同一资产和上一页的游标。[请求样例](../../docs/examples/clob-http.http)
|
||||
|
||||
```mermaid
|
||||
@@ -434,3 +425,5 @@ sequenceDiagram
|
||||
E-->>H: true
|
||||
H-->>C: 200,neg_risk 为真
|
||||
```
|
||||
|
||||
批量盘口 POST /books 的响应使用 asset_id 对应请求。重复资产只返回一份,单批最多 500 个不同标识。
|
||||
|
||||
@@ -3,7 +3,7 @@ use exchange::{Exchange, HistoryError};
|
||||
use percent_encoding::percent_decode_str;
|
||||
use serde::Deserialize;
|
||||
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};
|
||||
|
||||
const MAX_BOOKS: usize = 500;
|
||||
@@ -18,20 +18,15 @@ struct BookParam {
|
||||
_side: Option<exchange::PriceSide>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct BatchBookParam {
|
||||
token_id: Option<String>,
|
||||
side: Option<String>,
|
||||
}
|
||||
|
||||
type Reply = std::result::Result<Value, (u16, &'static str)>;
|
||||
|
||||
fn query(engine: &Mutex<Exchange>, params: Vec<BookParam>, 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<_>>();
|
||||
fn book_response(engine: &Mutex<Exchange>, tokens: Vec<String>, single: bool) -> Reply {
|
||||
let mut books = engine
|
||||
.lock()
|
||||
.map_err(|_| (500, "error getting the orderbook"))?
|
||||
@@ -404,14 +399,6 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
Err(HistoryError::Unavailable) => Err((500, "Internal server error")),
|
||||
}
|
||||
}
|
||||
(&Method::Get, "/time") => engine
|
||||
.lock()
|
||||
.map_err(|_| (500, "Internal server error"))
|
||||
.and_then(|db| {
|
||||
db.server_time()
|
||||
.map(|seconds| json!(seconds))
|
||||
.map_err(|_| (500, "Internal server error"))
|
||||
}),
|
||||
(&Method::Get, "/price") => serde_urlencoded::from_str::<WirePrice>(params)
|
||||
.map_err(|_| (400, "Invalid token id"))
|
||||
.and_then(|p| book_prices(engine, vec![p], true)),
|
||||
@@ -447,10 +434,36 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
(&Method::Get, "/midpoints") => Err((400, "Invalid payload")),
|
||||
(&Method::Get, "/book") => serde_urlencoded::from_str::<BookParam>(params)
|
||||
.map_err(|_| (400, "Invalid token id"))
|
||||
.and_then(|p| query(engine, vec![p], true)),
|
||||
(&Method::Post, "/books") => {
|
||||
batch_params::<BookParam>(&mut req).and_then(|p| query(engine, p, false))
|
||||
}
|
||||
.and_then(|p| {
|
||||
if p.token_id.trim().is_empty() {
|
||||
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)
|
||||
.map_err(|_| (400, "Invalid token id"))
|
||||
.and_then(|p| last_prices(engine, vec![p.token_id], true)),
|
||||
@@ -474,7 +487,6 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
| "/midpoint"
|
||||
| "/spread"
|
||||
| "/book"
|
||||
| "/time"
|
||||
| "/last-trade-price"
|
||||
| "/prices-history"
|
||||
| "/markets"
|
||||
@@ -590,11 +602,7 @@ pub(crate) fn serve(engine: Exchange, listener: TcpListener) -> Result<()> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::{
|
||||
io::Write,
|
||||
net::TcpStream,
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
use std::{io::Write, net::TcpStream, time::Duration};
|
||||
|
||||
#[test]
|
||||
fn socket_serves_single_and_batch_books_and_rejects_invalid_requests() {
|
||||
@@ -843,7 +851,7 @@ mod tests {
|
||||
"/books",
|
||||
mixed.to_string(),
|
||||
200,
|
||||
Some(json!([expected_no, expected_yes, expected_no])),
|
||||
Some(json!([expected_no, expected_yes])),
|
||||
),
|
||||
(
|
||||
"GET",
|
||||
@@ -854,8 +862,11 @@ mod tests {
|
||||
),
|
||||
("GET", "/book", String::new(), 400, None),
|
||||
("POST", "/books", "[]".into(), 200, Some(json!([]))),
|
||||
("POST", "/books", json!(max_batch).to_string(), 200, None),
|
||||
("POST", "/books", json!(too_many).to_string(), 400, None),
|
||||
("POST", "/books", json!(max_batch).to_string(), 200, Some(json!([expected_yes]))),
|
||||
("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",
|
||||
"/books",
|
||||
@@ -867,8 +878,8 @@ mod tests {
|
||||
"POST",
|
||||
"/books",
|
||||
r#"[{"token_id":"7","side":"INVALID"}]"#.into(),
|
||||
400,
|
||||
None,
|
||||
200,
|
||||
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,
|
||||
Some(json!({"data":[],"pagination":{"has_more":false,"next_cursor":null,"offset":0,"limit":10000}}))),
|
||||
@@ -876,8 +887,6 @@ mod tests {
|
||||
("POST","/v2/prices-history",String::new(),405,None),
|
||||
("GET", "/books", String::new(), 405, None),
|
||||
("POST", "/order", "{}".into(), 404, None),
|
||||
("GET", "/time", String::new(), 200, None),
|
||||
("POST", "/time", String::new(), 405, None),
|
||||
];
|
||||
let count = cases.len();
|
||||
let worker = thread::spawn(move || {
|
||||
@@ -891,10 +900,6 @@ mod tests {
|
||||
}
|
||||
});
|
||||
for (method, path, body, status, expected) in cases {
|
||||
let before = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
let mut socket = TcpStream::connect(port).unwrap();
|
||||
socket
|
||||
.set_read_timeout(Some(Duration::from_secs(5)))
|
||||
@@ -916,15 +921,6 @@ mod tests {
|
||||
let actual: Value = serde_json::from_str(body).unwrap();
|
||||
if let Some(expected) = expected {
|
||||
assert_eq!(actual, expected);
|
||||
} else if path == "/time" && status == 200 {
|
||||
let after = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
assert!((before..=after).contains(&actual.as_u64().unwrap()));
|
||||
} else if path == "/time" {
|
||||
assert!(headers.to_ascii_lowercase().contains("allow: get"));
|
||||
assert!(actual["error"].is_string());
|
||||
} else if status == 200 {
|
||||
assert_eq!(actual.as_array().unwrap().len(), MAX_BOOKS);
|
||||
} else {
|
||||
|
||||
@@ -34,8 +34,6 @@ flowchart LR
|
||||
expiry -->|清理到期注册| beat
|
||||
beat -->|释放订单尚未成交的预留| book
|
||||
api -->|启动和请求时检查到期时间| expiry["src/expiry.rs"]
|
||||
api -->|读取服务端 Unix 秒| expiry
|
||||
book -->|使用同一时钟校验 GTD| expiry
|
||||
expiry -->|释放订单剩余预留| book["src/book.rs"]
|
||||
api -->|初始化数据库| schema["src/schema.sql"]
|
||||
api -->|校验请求键| valid["src/validation.rs"]
|
||||
@@ -233,12 +231,6 @@ sequenceDiagram
|
||||
participant E as Exchange
|
||||
participant D as SQLite
|
||||
participant B as 常驻盘口
|
||||
opt HTTP 客户端校时
|
||||
C->>E: server_time
|
||||
E->>D: 读取与 GTD 共用的 Unix 秒
|
||||
D-->>E: 服务器时间
|
||||
E-->>C: Unix 秒整数
|
||||
end
|
||||
C->>E: 提交 GTD,含 Unix 秒时间戳
|
||||
E->>D: 校验申报时间并原子记录委托与期限
|
||||
C->>E: 到达有效截止点后查询或提交新单
|
||||
@@ -251,7 +243,7 @@ sequenceDiagram
|
||||
E-->>C: 返回查询结果或新单回执
|
||||
```
|
||||
|
||||
模拟 CLI 在等待输入时会按最近的截止点唤醒。盘口查询、交易或进程重启也会先结清已到期余单。单纯读时钟不会触发清理。成交、手动撤单和停盘会同步移除相应的待到期项。
|
||||
没有请求时,模拟 CLI 会等待输入。下一次查询、交易或进程重启会先结清已到期的余单。成交、手动撤单和停盘会同步移除相应的待到期项。
|
||||
|
||||
## 用结果资产 ID 下单
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{command::TimeInForce, resident::Books};
|
||||
use crate::{
|
||||
expiry, ledger,
|
||||
ledger,
|
||||
validation::{amount, identifier, phase},
|
||||
};
|
||||
use anyhow::{ensure, Result};
|
||||
@@ -109,7 +109,7 @@ pub(crate) fn submit(tx: &Transaction, books: &Books, order: NewOrder) -> Result
|
||||
TimeInForce::Gtd => {
|
||||
let expiration =
|
||||
expiration.ok_or_else(|| anyhow::anyhow!("GTD requires expiration"))?;
|
||||
let now = expiry::unix_seconds(tx)?;
|
||||
let now: i64 = tx.query_row("SELECT unixepoch()", [], |r| r.get(0))?;
|
||||
ensure!(
|
||||
expiration >= now + 180,
|
||||
"GTD expiration must be at least 180 seconds ahead"
|
||||
|
||||
@@ -2,10 +2,6 @@ use crate::book::{release, CancelReason};
|
||||
use anyhow::Result;
|
||||
use rusqlite::{Connection, Transaction, TransactionBehavior};
|
||||
|
||||
pub(crate) fn unix_seconds(db: &Connection) -> rusqlite::Result<i64> {
|
||||
db.query_row("SELECT unixepoch()", [], |row| row.get(0))
|
||||
}
|
||||
|
||||
/// Return a snapshot whose live book was current when the snapshot was acquired.
|
||||
/// Expirations commit separately so a rejected command cannot revive an order.
|
||||
pub(crate) fn transaction(
|
||||
|
||||
@@ -168,11 +168,6 @@ impl Exchange {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Unix seconds on the same database clock used to validate GTD orders.
|
||||
pub fn server_time(&self) -> Result<i64, MarketDataError> {
|
||||
Ok(expiry::unix_seconds(&self.db)?)
|
||||
}
|
||||
|
||||
/// Time until the next pending GTD stops trading, measured on the database clock.
|
||||
pub fn next_gtd_expiry(&self) -> Result<Option<Duration>> {
|
||||
let (first, now): (Option<i64>, i64) = self.db.query_row(
|
||||
|
||||
@@ -683,7 +683,9 @@ fn gtd_expiry_survives_rejection_and_recovery() {
|
||||
e.execute(json!({"op":"open","id":"start","market":"e"}))
|
||||
.unwrap();
|
||||
let db = rusqlite::Connection::open(&path).unwrap();
|
||||
let now = e.server_time().unwrap();
|
||||
let now: i64 = db
|
||||
.query_row("SELECT unixepoch()", [], |r| r.get(0))
|
||||
.unwrap();
|
||||
assert_eq!(e.next_gtd_expiry().unwrap(), None);
|
||||
let mut ask = order("dated", "alice", "sell", 60, 5);
|
||||
ask["tif"] = json!("GTD");
|
||||
|
||||
@@ -90,6 +90,3 @@ GET http://127.0.0.1:9002/clob-markets/cup
|
||||
|
||||
### Load neg-risk.jsonl to query either token of a member of the election group.
|
||||
GET http://127.0.0.1:9002/neg-risk?token_id=eb%3ANO%3Aa
|
||||
|
||||
### Exchange clock in Unix seconds, used to calculate GTD expiration.
|
||||
GET http://127.0.0.1:9002/time
|
||||
|
||||
@@ -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"]}
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ Polymarket 的查询使用认证身份,部分凭证有会话级可见范围。
|
||||
|
||||
连续交易的 order 支持 `"tif":"GTD"` 及整数秒 `expiration`,也可与 `"post_only":true` 合用。省略 tif 且提供正的到期时间时,本地采用 GTD。若数据库时钟为 T,申报 T+179 会拒绝;申报 T+180 时,有效截止点是 T+120,达到该秒就释放剩余预留。使用原请求键重试仍返回原受理回执,可通过 open_orders 指定订单号查看当前状态和申报时间。JSONL 输入空闲时用数据库时钟计算距离最近一笔待到期 GTD 的毫秒数,到点唤醒并释放余单。进程重启时先清理已到期订单,再恢复盘口。操作系统调度或 SQLite 写锁会影响实际清理延迟。[官方限价委托说明](https://docs.polymarket.com/trading/place-orders.md)
|
||||
|
||||
通过 `GET /time` 可读取与 GTD 受理校验共用的 SQLite 时钟。成功响应是单个 Unix 秒整数。客户端若以服务器时间 `T` 计划有效挂单 600 秒,可填写 `T+660`;服务按实际受理时刻校验最短申报期限。读时钟本身不会更改挂单。回归用例 gtd_expiry_survives_rejection_and_recovery 从公开时钟取值,覆盖过早申报、部分成交后到期、FOK 拒单、幂等重试和重启时解冻。生产 `/time` 直连未取得可用响应,本轮依据官方接口定义。外场终态字符串及逐秒延迟仍待验证。[官方时钟接口](https://docs.polymarket.com/api-reference/data/get-server-time)
|
||||
模拟器以每次请求取得数据库快照的时间判断是否到期。无人请求时的独立定时通知、外场终态字符串及逐秒延迟仍待验证。回归用例 gtd_expiry_survives_rejection_and_recovery 覆盖部分成交后到期、FOK 拒单、幂等重试和重启时解冻。
|
||||
|
||||
## 结果资产与订单路由
|
||||
|
||||
@@ -471,3 +471,7 @@ SDK 使用 `GET /neg-risk?token_id=…`,也可以从已缓存的 CLOB 市场
|
||||
### 已裁决市场的公开盘口
|
||||
|
||||
对电竞、乒乓球和 SOL 涨跌盘的六个已裁决结果单查 /book,全部返回 404。批量 /books 和 /prices 忽略已裁决资产,混合批次保留可用资产。中点和价差多数同样返回 404,但一个 V2 市场的两侧分别仍能读到价差 1 或中点 0.5。Eventbook 对已裁决结果统一省略四种公开行情,保留内部快照供交易状态和回放。封盘待裁决阶段、外场淘汰时延和例外是否由服务缓存触发仍待验证。[生产响应](examples/public-resolved-books.json)
|
||||
|
||||
### 批量盘口的资产对应关系
|
||||
|
||||
生产 /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)
|
||||
|
||||
Reference in New Issue
Block a user