Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
333187c646 | ||
|
|
aeb51ad588 |
No files matched your search
+2
-17
@@ -11,8 +11,6 @@ flowchart LR
|
||||
main["src/main.rs"] -->|把标准输入输出交给 serve| stream["src/stream.rs"]
|
||||
main -.->|打开数据库| api["exchange crate"]
|
||||
stream -.->|执行命令| api
|
||||
main --> http["src/market_http.rs"]
|
||||
http -.->|读取组合候选腿| api
|
||||
```
|
||||
|
||||
## 一次命令会话
|
||||
@@ -88,21 +86,6 @@ sequenceDiagram
|
||||
|
||||
`cli DATABASE --market-http 127.0.0.1:9002` 启动公开盘口读取服务。可与写入会话和 WebSocket 服务共用数据库文件。[HTTP 请求样例](../../docs/examples/clob-http.http)
|
||||
|
||||
### 组合候选市场
|
||||
|
||||
`GET /v1/rfq/combo-markets?limit=50` 按成交额倒序返回可选市场。下一页传入 `cursor`,可用 `exclude` 排除逗号分隔的已选条件。返回的三个结果数组按 YES、NO 顺序对齐。
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant C as 客户端
|
||||
participant H as market_http.rs
|
||||
participant E as Exchange
|
||||
C->>H: GET /v1/rfq/combo-markets
|
||||
H->>E: 查询 limit、cursor、exclude
|
||||
E-->>H: 组合候选市场和下一页游标
|
||||
H-->>C: markets 与 next_cursor
|
||||
```
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
main["main.rs"] --> http["market_http.rs"]
|
||||
@@ -442,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"))?
|
||||
@@ -325,17 +320,6 @@ fn clarifications(engine: &Mutex<Exchange>, query: &str) -> Reply {
|
||||
|
||||
fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
let (path, params) = req.url().split_once('?').unwrap_or((req.url(), ""));
|
||||
if path == "/v1/rfq/combo-markets" {
|
||||
if req.method() != &Method::Get {
|
||||
return send(req, 405, json!({"error":"Method not allowed"}), Some("GET"));
|
||||
}
|
||||
let (status, body) = match read_page(params, engine, Exchange::public_combo_markets) {
|
||||
Ok(data) => (200, data),
|
||||
Err(HistoryError::Invalid(message)) => (400, json!({"error":message})),
|
||||
Err(HistoryError::Unavailable) => (503, json!({"error":"combo markets unavailable"})),
|
||||
};
|
||||
return send(req, status, body, None);
|
||||
}
|
||||
let mut allow = None;
|
||||
if req.method() == &Method::Get
|
||||
&& matches!(
|
||||
@@ -450,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)),
|
||||
@@ -706,9 +716,6 @@ mod tests {
|
||||
("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}))),
|
||||
("GET","/v1/rfq/combo-markets?limit=1",String::new(),200,None),
|
||||
("GET","/v1/rfq/combo-markets?limit=0",String::new(),400,Some(json!({"error":"invalid limit"}))),
|
||||
("POST","/v1/rfq/combo-markets",String::new(),405,None),
|
||||
("GET","/v2/oi",String::new(),503,None),
|
||||
("POST","/v2/oi",String::new(),405,None),
|
||||
("GET","/v2/value?user=0x0000000000000000000000000000000000000001",String::new(),200,Some(json!({"data":{"proxy_wallet":"0x0000000000000000000000000000000000000001","value":0}}))),
|
||||
@@ -844,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",
|
||||
@@ -855,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",
|
||||
@@ -868,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}}))),
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
flowchart LR
|
||||
test["tests/market.rs"] -->|通过公开 API 驱动市场| api["src/lib.rs"]
|
||||
api -->|解析结果资产 ID| assets["src/assets.rs"]
|
||||
api -->|查询组合候选腿| combo_directory["src/combo_market_directory.rs"]
|
||||
combo_directory -->|排序并分页| combo_rank["src/combo_market_directory.sql"]
|
||||
combo_directory -->|生成两侧资产| assets
|
||||
queries -->|解析单笔和批量报价| marks
|
||||
marks -->|拆解每个 token_id| assets
|
||||
queries -->|生成目录中的结果资产| assets
|
||||
@@ -1437,20 +1434,3 @@ sequenceDiagram
|
||||
E-->>C: 返回本次两侧销毁量和实付金额
|
||||
end
|
||||
```
|
||||
|
||||
## 组合候选市场
|
||||
|
||||
`combo_market_directory.rs` 校验筛选和游标,在同一 SQLite 读事务中查询排序结果和盘口详情。排序使用单边吃单成交额,同额按稳定的市场目录 ID 排序。
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant H as HTTP
|
||||
participant E as combo_market_directory.rs
|
||||
participant D as SQLite
|
||||
H->>E: 分页参数和已选条件
|
||||
E->>D: 筛选活跃可交易盘口,按成交额读取一页加一条
|
||||
loop 本页候选
|
||||
E->>D: 读取目录字段及两侧行情
|
||||
end
|
||||
E-->>H: 对齐两侧结果,返回下一页游标或 null
|
||||
```
|
||||
@@ -1,128 +0,0 @@
|
||||
use crate::{
|
||||
assets,
|
||||
inventory::{decimal, UNIT},
|
||||
quotes::display_price,
|
||||
tick_size::PAR,
|
||||
validation::{hex_id, identifier},
|
||||
Exchange, MarketDataError,
|
||||
};
|
||||
use data_encoding::BASE64URL_NOPAD;
|
||||
use rusqlite::{params, Row};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ComboMarketsQuery {
|
||||
limit: Option<u32>,
|
||||
cursor: Option<String>,
|
||||
exclude: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct Cursor {
|
||||
volume: i64,
|
||||
id: i64,
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
fn decode(token: &str) -> Result<Self, MarketDataError> {
|
||||
let invalid = || MarketDataError::Invalid("invalid combo markets cursor".into());
|
||||
if token.len() > 128 {
|
||||
return Err(invalid());
|
||||
}
|
||||
let bytes = BASE64URL_NOPAD
|
||||
.decode(token.as_bytes())
|
||||
.map_err(|_| invalid())?;
|
||||
let cursor: Self = serde_json::from_slice(&bytes).map_err(|_| invalid())?;
|
||||
if cursor.id <= 0 || cursor.volume < 0 {
|
||||
return Err(invalid());
|
||||
}
|
||||
Ok(cursor)
|
||||
}
|
||||
|
||||
fn encode(&self) -> Result<String, MarketDataError> {
|
||||
let bytes = serde_json::to_vec(self).map_err(|_| MarketDataError::Unavailable)?;
|
||||
Ok(BASE64URL_NOPAD.encode(&bytes))
|
||||
}
|
||||
}
|
||||
|
||||
fn market(row: &Row<'_>, volume: i64) -> rusqlite::Result<Value> {
|
||||
let key: String = row.get("market")?;
|
||||
let phase: String = row.get("phase")?;
|
||||
let bid: Option<i64> = row.get("yes_bid")?;
|
||||
let ask: Option<i64> = row.get("yes_ask")?;
|
||||
let price = |bid, ask, last| {
|
||||
display_price(bid, ask, last, &phase).map(|(p, _)| decimal(p.into(), UNIT).to_string())
|
||||
};
|
||||
Ok(json!({
|
||||
"id": row.get::<_, String>("id")?,
|
||||
"condition_id": key,
|
||||
"position_ids": [assets::id(&key, "YES"), assets::id(&key, "NO")],
|
||||
"slug": row.get::<_, String>("slug")?,
|
||||
"title": row.get::<_, String>("question")?,
|
||||
"outcomes": [row.get::<_, String>("yes_label")?, row.get::<_, String>("no_label")?],
|
||||
"outcome_prices": [
|
||||
price(bid, ask, row.get("yes_last")?),
|
||||
price(ask.map(|p| PAR - p), bid.map(|p| PAR - p), row.get("no_last")?),
|
||||
],
|
||||
"image": "",
|
||||
"volume": decimal(volume.into(), PAR * 100),
|
||||
"tags": [],
|
||||
}))
|
||||
}
|
||||
|
||||
impl Exchange {
|
||||
pub fn public_combo_markets(&self, query: ComboMarketsQuery) -> Result<Value, MarketDataError> {
|
||||
let limit = query.limit.unwrap_or(50);
|
||||
if !(1..=100).contains(&limit) {
|
||||
return Err(MarketDataError::Invalid("invalid limit".into()));
|
||||
}
|
||||
let cursor = query.cursor.as_deref().map(Cursor::decode).transpose()?;
|
||||
let mut excluded = Vec::new();
|
||||
if let Some(raw) = query.exclude {
|
||||
for id in raw.split(',').map(str::trim) {
|
||||
identifier(id).map_err(|_| MarketDataError::Invalid("invalid exclude".into()))?;
|
||||
excluded.push(if hex_id(id, 64) {
|
||||
id.to_ascii_lowercase()
|
||||
} else {
|
||||
id.to_owned()
|
||||
});
|
||||
}
|
||||
}
|
||||
let tx = self.db.unchecked_transaction()?;
|
||||
let (markets, next_cursor) = {
|
||||
let mut scan = tx.prepare_cached(include_str!("combo_market_directory.sql"))?;
|
||||
let mut rows = scan.query(params![
|
||||
json!(excluded).to_string(),
|
||||
cursor.as_ref().map(|c| c.volume),
|
||||
cursor.as_ref().map(|c| c.id),
|
||||
limit + 1
|
||||
])?;
|
||||
let mut detail = tx.prepare_cached(concat!(
|
||||
include_str!("gamma_market.sql"),
|
||||
" AND w.market=?1"
|
||||
))?;
|
||||
let mut markets = Vec::new();
|
||||
let mut after = None;
|
||||
for _ in 0..limit {
|
||||
let Some(row) = rows.next()? else { break };
|
||||
let key: String = row.get(0)?;
|
||||
let volume = row.get(2)?;
|
||||
markets.push(detail.query_row([key], |r| market(r, volume))?);
|
||||
after = Some(Cursor {
|
||||
volume,
|
||||
id: row.get(1)?,
|
||||
});
|
||||
}
|
||||
let next = if rows.next()?.is_some() {
|
||||
after.map(|anchor| anchor.encode()).transpose()?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
(markets, next)
|
||||
};
|
||||
tx.commit()?;
|
||||
Ok(json!({ "markets": markets, "next_cursor": next_cursor }))
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
WITH eligible AS MATERIALIZED (
|
||||
SELECT m.id AS market, d.id AS directory_id
|
||||
FROM markets m JOIN market_directory_ids d ON d.market=m.id
|
||||
LEFT JOIN market_visibility v ON v.market=m.id
|
||||
LEFT JOIN augmented_outcomes a ON a.market=m.id
|
||||
WHERE m.phase IN ('preopen','continuous')
|
||||
AND COALESCE(v.active,1)=1 AND COALESCE(v.archived,0)=0
|
||||
AND COALESCE(a.role,'')<>'placeholder'
|
||||
AND (CASE WHEN length(m.id)=66 AND m.id GLOB '0x*'
|
||||
AND substr(m.id,3) NOT GLOB '*[^0-9a-fA-F]*'
|
||||
THEN lower(m.id) ELSE m.id END) NOT IN (SELECT value FROM json_each(?1))
|
||||
), executions AS (
|
||||
SELECT e.market, f.quantity * f.price AS notional
|
||||
FROM eligible e CROSS JOIN orders o ON o.market=e.market AND o.side='buy'
|
||||
CROSS JOIN fills f ON f.bid=o.seq
|
||||
JOIN execution_context c ON c.execution=f.seq AND c.taker_order IS NOT NULL
|
||||
UNION ALL
|
||||
SELECT e.market, f.quantity * CASE c.taker_order
|
||||
WHEN f.yes_order THEN f.yes_price WHEN f.no_order THEN 10000-f.yes_price END
|
||||
FROM eligible e CROSS JOIN paired_fills f ON f.market=e.market
|
||||
JOIN execution_context c ON c.execution=f.seq AND c.taker_order IS NOT NULL
|
||||
), totals AS (
|
||||
SELECT market, SUM(notional) AS notional FROM executions GROUP BY market
|
||||
), ranked AS (
|
||||
SELECT e.market, e.directory_id, COALESCE(t.notional,0) AS volume
|
||||
FROM eligible e LEFT JOIN totals t ON t.market=e.market
|
||||
)
|
||||
SELECT market, directory_id, volume FROM ranked
|
||||
WHERE ?2 IS NULL OR volume<?2 OR (volume=?2 AND directory_id>?3)
|
||||
ORDER BY volume DESC, directory_id ASC
|
||||
LIMIT ?4
|
||||
@@ -21,8 +21,6 @@ mod book_snapshot;
|
||||
mod cancellation;
|
||||
mod clarifications;
|
||||
mod clob_market;
|
||||
mod combo_market_directory;
|
||||
pub use combo_market_directory::ComboMarketsQuery;
|
||||
mod command;
|
||||
mod inventory;
|
||||
mod kickoff;
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
use exchange::{Exchange, MarketDataError};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
fn page(db: &Exchange, query: Value) -> Result<Value, MarketDataError> {
|
||||
db.public_combo_markets(serde_json::from_value(query).unwrap())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn combo_candidates_rank_by_volume_and_keep_outcome_alignment() {
|
||||
let mut db = Exchange::open(":memory:").unwrap();
|
||||
for cmd in [
|
||||
json!({"op":"list","id":"quiet","market":"quiet","rules":"赛果"}),
|
||||
json!({"op":"list","id":"archived","market":"archived","rules":"赛果"}),
|
||||
json!({"op":"set_market_visibility","id":"hide","market":"archived","active":true,"archived":true}),
|
||||
json!({"op":"list","id":"closed","market":"closed","rules":"赛果"}),
|
||||
json!({"op":"close","id":"stop","market":"closed"}),
|
||||
] {
|
||||
db.execute(cmd).unwrap();
|
||||
}
|
||||
for line in include_str!("../../../docs/examples/valuation.jsonl")
|
||||
.lines()
|
||||
.take(7)
|
||||
{
|
||||
db.execute(serde_json::from_str(line).unwrap()).unwrap();
|
||||
}
|
||||
let first = page(&db, json!({"limit":1})).unwrap();
|
||||
assert_eq!(first["markets"][0]["condition_id"], "e");
|
||||
assert_eq!(first["markets"][0]["volume"], json!(1.2));
|
||||
assert_eq!(
|
||||
first["markets"][0]["position_ids"],
|
||||
json!(["eb:YES:e", "eb:NO:e"])
|
||||
);
|
||||
assert_eq!(first["markets"][0]["outcomes"], json!(["YES", "NO"]));
|
||||
assert_eq!(first["markets"][0]["outcome_prices"][0], "0.6");
|
||||
let next = first["next_cursor"].as_str().unwrap();
|
||||
let second = page(&db, json!({"cursor":next,"limit":1,"exclude":"e"})).unwrap();
|
||||
assert_eq!(second["markets"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(second["markets"][0]["condition_id"], "quiet");
|
||||
assert_eq!(second["markets"][0]["outcome_prices"], json!([null, null]));
|
||||
assert!(second["next_cursor"].is_null());
|
||||
assert_eq!(
|
||||
page(&db, json!({"exclude":"e,quiet"})).unwrap(),
|
||||
json!({"markets":[],"next_cursor":null})
|
||||
);
|
||||
assert!(matches!(
|
||||
page(&db, json!({"limit":101})),
|
||||
Err(MarketDataError::Invalid(_))
|
||||
));
|
||||
assert!(matches!(
|
||||
page(&db, json!({"cursor":"bad"})),
|
||||
Err(MarketDataError::Invalid(_))
|
||||
));
|
||||
}
|
||||
@@ -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"]}
|
||||
}
|
||||
}
|
||||
@@ -472,10 +472,6 @@ SDK 使用 `GET /neg-risk?token_id=…`,也可以从已缓存的 CLOB 市场
|
||||
|
||||
对电竞、乒乓球和 SOL 涨跌盘的六个已裁决结果单查 /book,全部返回 404。批量 /books 和 /prices 忽略已裁决资产,混合批次保留可用资产。中点和价差多数同样返回 404,但一个 V2 市场的两侧分别仍能读到价差 1 或中点 0.5。Eventbook 对已裁决结果统一省略四种公开行情,保留内部快照供交易状态和回放。封盘待裁决阶段、外场淘汰时延和例外是否由服务缓存触发仍待验证。[生产响应](examples/public-resolved-books.json)
|
||||
|
||||
### 组合候选市场目录
|
||||
### 批量盘口的资产对应关系
|
||||
|
||||
官方 `GET /v1/rfq/combo-markets` 提供按成交量倒序的公开候选目录。用 `cursor` 翻页,用 `exclude` 排除一组条件。默认每页 50 条,上限 100 条。资产、结果标签和价格按 YES、NO 顺序对齐。[官方接口](https://docs.polymarket.com/api-reference/combo-markets/get-combo-markets)
|
||||
|
||||
本地只列活跃、未归档、可交易且可见的盘口。使用与本地成交量报告相同的单边吃单美元成交额,等额按目录 ID 升序。市场在翻页期间可能成交或改变状态,游标依照查询时的排序继续。无价用 `null`,保留对应结果的位置。图标和标签返回空值,资产和条件使用本地标识。生产端点查询超时,资格细则、排序成交量口径及缺价格式仍待实测。
|
||||
|
||||
在空数据库重放 [估值样例](examples/valuation.jsonl) 的前七条命令,再查询 `GET /v1/rfq/combo-markets?limit=1`。市场 `e` 居首,成交额为 1.2,YES 展示价为字符串 `0.6`。传入 `exclude=e` 时应得到空页与 `next_cursor: null`。
|
||||
生产 /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