Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 333187c646 | |||
| 30e4a5cd17 | |||
| 74b7655723 | |||
| aeb51ad588 | |||
| 9d541c563b | |||
| e6a914b381 |
+5
-13
@@ -86,22 +86,10 @@ sequenceDiagram
|
||||
|
||||
`cli DATABASE --market-http 127.0.0.1:9002` 启动公开盘口读取服务。可与写入会话和 WebSocket 服务共用数据库文件。[HTTP 请求样例](../../docs/examples/clob-http.http)
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant C as 客户端
|
||||
participant H as market_http.rs
|
||||
participant E as exchange::Exchange
|
||||
C->>H: GET /v2/live-volume?event_id=20,10
|
||||
H->>E: public_live_volume
|
||||
E-->>H: 各条件累计吃单份额及总和
|
||||
H-->>C: 200 与 data 对象
|
||||
```
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
main["main.rs"] --> http["market_http.rs"]
|
||||
http --> api["exchange::Exchange::public_books"]
|
||||
http --> volume["exchange::Exchange::public_live_volume"]
|
||||
```
|
||||
|
||||
```mermaid
|
||||
@@ -195,6 +183,8 @@ sequenceDiagram
|
||||
|
||||
路径参数使用百分号编码。即使查询从 NO 开始,primary_token_id 仍对应 YES。可重放请求见[行情 HTTP 示例](../../docs/examples/clob-http.http)。
|
||||
|
||||
已裁决资产的公开盘口、买卖报价、中点和价差单查返回 404,批查跳过该资产。
|
||||
|
||||
### 查询盘口价差与中点
|
||||
|
||||
```mermaid
|
||||
@@ -233,7 +223,7 @@ sequenceDiagram
|
||||
participant E as prices_history/legacy.rs
|
||||
C->>H: GET /prices-history,market 与 interval 或 startTs、endTs
|
||||
H->>E: clob_price_history,fidelity 以分钟计
|
||||
E-->>H: 返回窗口内盘口中点样本,末尾追加最近可用点
|
||||
E-->>H: 返回窗口内盘口中点样本,未封盘时追加最近可用点
|
||||
H-->>C: history 数组,每点包含 t 和 p
|
||||
```
|
||||
|
||||
@@ -435,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"))?
|
||||
@@ -329,12 +324,7 @@ 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/live-volume"
|
||||
"/v2/prices-history" | "/v2/trades" | "/v2/resolutions" | "/v2/value" | "/v2/oi"
|
||||
)
|
||||
{
|
||||
let (status, body) = data_page(path, params, engine);
|
||||
@@ -444,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)),
|
||||
@@ -477,7 +493,6 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
| "/events"
|
||||
| "/market-clarifications"
|
||||
| "/v2/oi"
|
||||
| "/v2/live-volume"
|
||||
| "/v2/value"
|
||||
| "/v2/trades"
|
||||
| "/v2/resolutions"
|
||||
@@ -520,7 +535,6 @@ fn read_page<Q: serde::de::DeserializeOwned>(
|
||||
fn data_page(path: &str, params: &str, engine: &Mutex<Exchange>) -> (u16, Value) {
|
||||
let page = match path {
|
||||
"/v2/oi" => read_page(params, engine, Exchange::public_open_interest),
|
||||
"/v2/live-volume" => read_page(params, engine, Exchange::public_live_volume),
|
||||
"/v2/value" => read_page(params, engine, Exchange::public_portfolio_value),
|
||||
"/v2/trades" => read_page(params, engine, Exchange::public_trade_feed),
|
||||
"/v2/resolutions" => read_page(params, engine, Exchange::public_resolutions),
|
||||
@@ -536,10 +550,6 @@ fn data_page(path: &str, params: &str, engine: &Mutex<Exchange>) -> (u16, Value)
|
||||
503,
|
||||
json!({"code":"unavailable","error":"open interest unavailable","retryable":true}),
|
||||
),
|
||||
Err(HistoryError::Unavailable) if path == "/v2/live-volume" => (
|
||||
503,
|
||||
json!({"code":"unavailable","error":"live volume unavailable","retryable":true}),
|
||||
),
|
||||
Err(HistoryError::Unavailable) if path == "/v2/value" => (
|
||||
503,
|
||||
json!({"code":"unavailable","error":"portfolio valuation unavailable","retryable":true}),
|
||||
@@ -628,6 +638,9 @@ 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,
|
||||
"t":[{"o":"YES","t":"eb:YES:map+2/1"},{"o":"NO","t":"eb:NO:map+2/1"}]});
|
||||
for command in [
|
||||
json!({"op":"list","id":"resolved-list","market":"resolved-test","rules":"resolved fixture"}),
|
||||
json!({"op":"close","id":"resolved-close","market":"resolved-test"}),
|
||||
json!({"op":"finalize","id":"resolved-final","market":"resolved-test","winner":"YES"}),
|
||||
json!({"op":"fund","id":"v-fund","account":"unpriced-owner","cents":100}),
|
||||
json!({"op":"list","id":"v-list","market":"unpriced","rules":"valuation fixture"}),
|
||||
json!({"op":"split","id":"v-split","account":"unpriced-owner","market":"unpriced","qty":1}),
|
||||
@@ -669,43 +682,6 @@ mod tests {
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let event_path = format!("/events/{}", topic["id"].as_str().unwrap());
|
||||
for command in include_str!("../../../docs/examples/football.jsonl")
|
||||
.lines()
|
||||
.chain(include_str!("../../../docs/examples/volume.jsonl").lines())
|
||||
{
|
||||
db.execute(serde_json::from_str(command).unwrap()).unwrap();
|
||||
}
|
||||
let cup = db
|
||||
.gamma_event(exchange::DirectoryKey::Slug("cup-a-b"))
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let cup_id = cup["id"].as_str().unwrap();
|
||||
let topic_id = topic["id"].as_str().unwrap();
|
||||
let volume_query = format!("/v2/live-volume?eventId={topic_id},bad,{cup_id},{cup_id}");
|
||||
let cup_volume_query = format!("/v2/live-volume?event_id={cup_id}");
|
||||
let too_many_events = format!(
|
||||
"/v2/live-volume?event_id={}",
|
||||
(1..=21)
|
||||
.map(|id| id.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
);
|
||||
let cup_conditions = json!([
|
||||
{"condition_id":"full-2-1","taker_volume":3},
|
||||
{"condition_id":"half-1-0","taker_volume":2},
|
||||
{"condition_id":"first-home","taker_volume":0},
|
||||
{"condition_id":"first-ten","taker_volume":0},
|
||||
{"condition_id":"home-minus","taker_volume":0},
|
||||
{"condition_id":"over-25","taker_volume":0}
|
||||
]);
|
||||
let mut joint_conditions = cup_conditions.as_array().unwrap().clone();
|
||||
joint_conditions.splice(
|
||||
5..5,
|
||||
[
|
||||
json!({"condition_id":"nvda-200","taker_volume":0}),
|
||||
json!({"condition_id":"nvda-300","taker_volume":0}),
|
||||
],
|
||||
);
|
||||
let first_child = &topic["markets"][0];
|
||||
assert_eq!(first_child["conditionId"], "nvda-200");
|
||||
assert_eq!(topic["markets"].as_array().unwrap().len(), 2);
|
||||
@@ -742,13 +718,6 @@ mod tests {
|
||||
("GET","/v2/oi?condition=bad-hash",String::new(),400,Some(json!({"code":"invalid_request","error":"invalid condition: bad-hash","retryable":false}))),
|
||||
("GET","/v2/oi",String::new(),503,None),
|
||||
("POST","/v2/oi",String::new(),405,None),
|
||||
("GET",volume_query.as_str(),String::new(),200,Some(json!({"data":{"conditions":joint_conditions,"taker_volume_total":5}}))),
|
||||
("GET",cup_volume_query.as_str(),String::new(),200,Some(json!({"data":{"conditions":cup_conditions,"taker_volume_total":5}}))),
|
||||
("GET","/v2/live-volume?id=9223372036854775807",String::new(),200,Some(json!({"data":{"conditions":[],"taker_volume_total":0}}))),
|
||||
("GET","/v2/live-volume?event_id=bad,,oops",String::new(),400,None),
|
||||
("GET","/v2/live-volume",String::new(),400,None),
|
||||
("GET",too_many_events.as_str(),String::new(),400,None),
|
||||
("POST","/v2/live-volume",String::new(),405,None),
|
||||
("GET","/v2/value?user=0x0000000000000000000000000000000000000001",String::new(),200,Some(json!({"data":{"proxy_wallet":"0x0000000000000000000000000000000000000001","value":0}}))),
|
||||
("GET","/v2/value",String::new(),400,None),
|
||||
("GET","/v2/value?user=unpriced-owner",String::new(),503,None),
|
||||
@@ -810,6 +779,14 @@ mod tests {
|
||||
("POST","/prices",json!([{"token_id":"eb:YES:s"}]).to_string(),200,Some(json!({"eb:YES:s":{"SELL":"0.41"}}))),
|
||||
("POST","/prices",json!(vec![json!({"token_id":"eb:YES:s","side":"BUY"}); MAX_BOOKS+1]).to_string(),400,None),
|
||||
("DELETE","/prices",String::new(),405,None),
|
||||
("GET","/book?token_id=eb:YES:resolved-test",String::new(),404,Some(json!({"error":MISSING}))),
|
||||
("GET","/price?token_id=eb:YES:resolved-test&side=BUY",String::new(),404,Some(json!({"error":MISSING}))),
|
||||
("GET","/midpoint?token_id=eb:NO:resolved-test",String::new(),404,Some(json!({"error":MISSING}))),
|
||||
("GET","/spread?token_id=eb:NO:resolved-test",String::new(),404,Some(json!({"error":MISSING}))),
|
||||
("POST","/books",json!([{"token_id":"eb:YES:resolved-test"},{"token_id":yes}]).to_string(),200,Some(json!([expected_yes.clone()]))),
|
||||
("POST","/prices",json!([{"token_id":"eb:YES:resolved-test","side":"BUY"},{"token_id":"eb:YES:s","side":"BUY"}]).to_string(),200,Some(json!({"eb:YES:s":{"BUY":"0.39"}}))),
|
||||
("POST","/midpoints",json!([{"token_id":"eb:YES:resolved-test"},{"token_id":"eb:YES:s"}]).to_string(),200,Some(json!({"eb:YES:s":"0.4"}))),
|
||||
("POST","/spreads",json!([{"token_id":"eb:YES:resolved-test"}]).to_string(),200,Some(json!({}))),
|
||||
("GET","/midpoint?token_id=eb:YES:mid-example",String::new(),200,Some(json!({"mid":"0.085"}))),
|
||||
("POST","/midpoints",json!([{"token_id":"eb:YES:mid-example"},{"token_id":"eb:NO:mid-example"}]).to_string(),200,Some(sample)),
|
||||
("GET","/midpoint?token_id=eb:YES:s",String::new(),200,Some(json!({"mid":"0.4"}))),
|
||||
@@ -874,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",
|
||||
@@ -885,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",
|
||||
@@ -898,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}}))),
|
||||
|
||||
@@ -41,7 +41,6 @@ flowchart LR
|
||||
api -->|事务内派发| market["src/market.rs"]
|
||||
api -->|解析只读查询| queries["src/catalog.rs"]
|
||||
queries -->|查询各盘及赛事成交量| volume["src/volume.rs"]
|
||||
api -->|公开多赛事吃单份额| volume
|
||||
volume -->|按市场汇总普通及互补成交| volumesql["src/volume.sql"]
|
||||
volumesql -->|成交、时间及吃单方| schema
|
||||
queries -->|市价预估| estimate["src/estimate.rs"]
|
||||
@@ -484,8 +483,8 @@ sequenceDiagram
|
||||
participant C as 客户端
|
||||
participant E as Exchange
|
||||
participant D as SQLite
|
||||
C->>E: catalog、volume 或 GET /v2/live-volume
|
||||
E->>D: 打开读快照,按赛事键或数字目录 ID 选择市场
|
||||
C->>E: catalog(event) 或 volume(event)
|
||||
E->>D: 打开同一读快照,选择已展示的市场
|
||||
E->>D: 普通成交按 bid 定位市场,互补成交按 market 定位
|
||||
D-->>E: 每笔取一次份额,按吃单方实际结果价统计金额
|
||||
E->>E: 汇总每盘的累计及最近 24 小时,再求赛事总量
|
||||
@@ -493,8 +492,6 @@ sequenceDiagram
|
||||
E-->>C: 保留目录顺序,事件和各市场附带 volume
|
||||
else volume
|
||||
E-->>C: 统计时刻、总量及按累计吃单份额降序的成员
|
||||
else /v2/live-volume
|
||||
E-->>C: 各条件累计吃单份额与跨赛事合计
|
||||
end
|
||||
```
|
||||
|
||||
@@ -1110,7 +1107,7 @@ sequenceDiagram
|
||||
E->>D: 先处理到期订单,再从同一快照读取各市场最新 quote_events
|
||||
D-->>E: 返回 YES 的买一和卖一
|
||||
E->>E: 换算结果方向,缺买盘取 0、缺卖盘取 1,计算价差或中点
|
||||
E-->>C: 按结果资产索引,未上市资产无条目
|
||||
E-->>C: 按结果资产索引,跳过未上市和已裁决资产
|
||||
```
|
||||
|
||||
HTTP 盘口查询由 public_book_prices 读取 quote_events,先清理到期任务,再在同一快照中读取各市场。BUY 取买一,SELL 取卖一。下单面板的 JSONL 命令继续查询最优对手价。
|
||||
@@ -1136,7 +1133,7 @@ flowchart LR
|
||||
L --> A["assets.rs"]
|
||||
L --> Q["prices_history/legacy.sql"]
|
||||
Q --> T["quote_schema.sql 中的 quote_events"]
|
||||
Q --> O["prices_history/chart_schema.sql 中的采样起点和时间索引"]
|
||||
Q --> O["prices_history/chart_schema.sql 中的采样起点、封盘时间和时间索引"]
|
||||
API["lib.rs"] --> O
|
||||
Q --> S["schema.sql 中的 price_settlements"]
|
||||
```
|
||||
@@ -1148,7 +1145,7 @@ sequenceDiagram
|
||||
participant D as SQLite
|
||||
C->>E: clob_price_history
|
||||
E->>D: 清理到期委托并取得读快照与数据库时钟
|
||||
E->>D: 按 UTC 分钟网格重放各采样点当时的盘口,再读取最近可用点
|
||||
E->>D: 按 UTC 分钟网格重放盘口,封盘后只取窗口内的封盘前样本
|
||||
D-->>E: 观测时间和定点价格
|
||||
E-->>C: t 为 Unix 秒,p 为十进制数
|
||||
```
|
||||
|
||||
@@ -45,7 +45,7 @@ impl Snapshot {
|
||||
|
||||
fn build(tx: &Transaction, books: &Books, token: &str) -> Result<Snapshot> {
|
||||
let (outcome, market) = assets::parse_id(token)?;
|
||||
find(tx, books, token, outcome, market)?
|
||||
find(tx, books, token, outcome, market, false)?
|
||||
.context("No orderbook exists for the requested token id")
|
||||
}
|
||||
|
||||
@@ -55,12 +55,14 @@ fn find(
|
||||
token: &str,
|
||||
outcome: &str,
|
||||
market: &str,
|
||||
public_only: bool,
|
||||
) -> Result<Option<Snapshot>> {
|
||||
let row: Option<(i64, bool)> = tx
|
||||
.query_row(
|
||||
"SELECT at_ms,EXISTS(SELECT 1 FROM neg_risk_members WHERE market=?1)
|
||||
FROM book_snapshot_times WHERE market=?1",
|
||||
[market],
|
||||
FROM book_snapshot_times b JOIN markets m ON m.id=b.market
|
||||
WHERE b.market=?1 AND (NOT ?2 OR m.phase<>'resolved')",
|
||||
rusqlite::params![market, public_only],
|
||||
|r| Ok((r.get(0)?, r.get(1)?)),
|
||||
)
|
||||
.optional()?;
|
||||
@@ -114,7 +116,7 @@ pub(crate) fn read_many(
|
||||
let mut result = Vec::with_capacity(tokens.len());
|
||||
for token in tokens {
|
||||
if let Ok((outcome, market)) = assets::parse_id(token) {
|
||||
if let Some(book) = find(tx, books, token, outcome, market)? {
|
||||
if let Some(book) = find(tx, books, token, outcome, market, true)? {
|
||||
result.push(serde_json::to_value(book)?);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,6 @@ pub use prices_history::legacy::ClobHistoryQuery;
|
||||
pub use public_trades::http::TradeQuery;
|
||||
pub use quotes::{PriceQueryError, PriceRequest, PriceSide};
|
||||
pub use resolution::http::ResolutionQuery;
|
||||
pub use volume::LiveVolumeQuery;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MarketDataError {
|
||||
@@ -122,7 +121,7 @@ impl Exchange {
|
||||
db.execute_batch(include_str!("quote_schema.sql"))?;
|
||||
}
|
||||
let history_ready: bool = db.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='trigger' AND name='chart_market_listed')",
|
||||
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='trigger' AND name='chart_market_closed')",
|
||||
[], |r| r.get(0),
|
||||
)?;
|
||||
if !history_ready {
|
||||
|
||||
@@ -12,4 +12,12 @@ END;
|
||||
INSERT OR IGNORE INTO chart_origins
|
||||
SELECT id,COALESCE((SELECT MIN(at_ms) FROM quote_events WHERE market=m.id),
|
||||
CAST(unixepoch('subsec')*1000 AS INTEGER)) FROM markets m;
|
||||
CREATE TABLE IF NOT EXISTS chart_closures (
|
||||
market TEXT PRIMARY KEY REFERENCES markets,
|
||||
at_ms INTEGER NOT NULL
|
||||
);
|
||||
CREATE TRIGGER IF NOT EXISTS chart_market_closed AFTER UPDATE OF phase ON markets
|
||||
WHEN NEW.phase='closed' AND OLD.phase<>'closed' BEGIN
|
||||
INSERT INTO chart_closures VALUES(NEW.id,CAST(unixepoch('subsec')*1000 AS INTEGER));
|
||||
END;
|
||||
COMMIT;
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
-- The local sampler uses a UTC minute grid. The venue's collector has clock jitter.
|
||||
WITH RECURSIVE horizon AS (
|
||||
SELECT (SELECT at_ms FROM chart_origins WHERE market=?1) AS first_ms,
|
||||
(SELECT at_ms FROM price_settlements WHERE market=?1) AS resolved_ms,
|
||||
(SELECT winner FROM price_settlements WHERE market=?1) AS winner,
|
||||
(SELECT phase FROM markets WHERE id=?1) AS phase
|
||||
(SELECT at_ms FROM chart_closures WHERE market=?1) AS closed_ms,
|
||||
(SELECT phase IN ('closed','resolved') FROM markets WHERE id=?1) AS closed
|
||||
), bounds AS (
|
||||
SELECT first_ms, resolved_ms, winner,
|
||||
CASE WHEN phase='resolved' THEN COALESCE(resolved_ms,
|
||||
(SELECT MAX(at_ms) FROM quote_events WHERE market=?1))
|
||||
ELSE ?6/60000*60000 END AS last_ms
|
||||
SELECT first_ms, closed,
|
||||
CASE WHEN NOT closed THEN ?6/60000*60000
|
||||
WHEN closed_ms IS NOT NULL THEN closed_ms-1
|
||||
-- Old closed markets lack the close time. Use the last
|
||||
-- recorded nonempty quote and exclude the closing clear.
|
||||
ELSE (SELECT MAX(at_ms) FROM quote_events WHERE market=?1
|
||||
AND (yes_bid IS NOT NULL OR yes_ask IS NOT NULL)) END AS last_ms
|
||||
FROM horizon
|
||||
), grid(ms) AS (
|
||||
SELECT ((MAX(?3,first_ms)+?5-1)/?5)*?5 FROM bounds
|
||||
@@ -19,14 +21,12 @@ WITH RECURSIVE horizon AS (
|
||||
), points(ms,tail) AS (
|
||||
SELECT ms,0 FROM grid
|
||||
UNION ALL
|
||||
SELECT last_ms,1 FROM bounds WHERE resolved_ms IS NOT NULL OR first_ms<=last_ms
|
||||
SELECT last_ms,1 FROM bounds WHERE NOT closed AND first_ms<=last_ms
|
||||
)
|
||||
SELECT points.ms/1000,
|
||||
CASE WHEN points.ms=b.resolved_ms THEN
|
||||
CASE WHEN b.winner='VOID' THEN 500000 WHEN b.winner=?2 THEN 1000000 ELSE 0 END
|
||||
WHEN ?2='YES' THEN (COALESCE(q.yes_bid,0)+COALESCE(q.yes_ask,10000))*50
|
||||
CASE WHEN ?2='YES' THEN (COALESCE(q.yes_bid,0)+COALESCE(q.yes_ask,10000))*50
|
||||
ELSE 1000000-(COALESCE(q.yes_bid,0)+COALESCE(q.yes_ask,10000))*50 END
|
||||
FROM points CROSS JOIN bounds b
|
||||
FROM points
|
||||
LEFT JOIN quote_events q ON q.seq=(
|
||||
SELECT seq FROM quote_events WHERE market=?1 AND at_ms<=points.ms
|
||||
ORDER BY at_ms DESC,seq DESC LIMIT 1
|
||||
|
||||
@@ -200,7 +200,7 @@ impl PriceRequest {
|
||||
// Use the last committed top of book, even when only one side has liquidity.
|
||||
// All requested markets share the caller's read snapshot.
|
||||
fn price_rows(db: &Connection, requests: &[PriceRequest]) -> Result<Vec<Option<String>>> {
|
||||
quote_rows(db, requests)?
|
||||
quote_rows(db, requests, false)?
|
||||
.into_iter()
|
||||
.zip(requests)
|
||||
.map(|(quote, request)| {
|
||||
@@ -220,7 +220,11 @@ fn price_rows(db: &Connection, requests: &[PriceRequest]) -> Result<Vec<Option<S
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn quote_rows(db: &Connection, requests: &[PriceRequest]) -> Result<Vec<Option<Quote>>> {
|
||||
fn quote_rows(
|
||||
db: &Connection,
|
||||
requests: &[PriceRequest],
|
||||
public_only: bool,
|
||||
) -> Result<Vec<Option<Quote>>> {
|
||||
if !(1..=500).contains(&requests.len()) {
|
||||
return Err(PriceQueryError::RequestCount.into());
|
||||
}
|
||||
@@ -234,11 +238,11 @@ fn quote_rows(db: &Connection, requests: &[PriceRequest]) -> Result<Vec<Option<Q
|
||||
}
|
||||
let mut stmt = db.prepare_cached(
|
||||
"SELECT COALESCE(q.seq,0),q.yes_bid,q.yes_ask,q.at_ms,m.id,j.key
|
||||
FROM json_each(?1) j LEFT JOIN markets m ON m.id=j.value
|
||||
FROM json_each(?1) j LEFT JOIN markets m ON m.id=j.value AND (NOT ?2 OR m.phase<>'resolved')
|
||||
LEFT JOIN quote_events q ON q.seq=(SELECT MAX(seq) FROM quote_events WHERE market=m.id)
|
||||
ORDER BY j.key",
|
||||
)?;
|
||||
let mut rows = stmt.query([serde_json::to_string(&markets)?])?;
|
||||
let mut rows = stmt.query(params![serde_json::to_string(&markets)?, public_only])?;
|
||||
let mut quotes = Vec::with_capacity(requests.len());
|
||||
while let Some(row) = rows.next()? {
|
||||
let index: usize = row.get(5)?;
|
||||
@@ -284,7 +288,7 @@ impl crate::Exchange {
|
||||
pub fn public_book_prices(&self, requests: &[PriceRequest]) -> Result<Value> {
|
||||
let tx = crate::expiry::transaction(&self.db, rusqlite::TransactionBehavior::Deferred)?;
|
||||
let mut result = json!({});
|
||||
for (request, quote) in requests.iter().zip(quote_rows(&tx, requests)?) {
|
||||
for (request, quote) in requests.iter().zip(quote_rows(&tx, requests, true)?) {
|
||||
if let Some(quote) = quote {
|
||||
let (bid, ask) = quote.public_sides();
|
||||
let ticks = match request.side {
|
||||
@@ -333,7 +337,7 @@ impl crate::Exchange {
|
||||
.map_err(|_| crate::MarketDataError::Unavailable)?;
|
||||
let mut stmt = tx.prepare_cached(
|
||||
"SELECT COALESCE(q.seq,0),q.yes_bid,q.yes_ask,q.at_ms,j.key FROM json_each(?1) j
|
||||
JOIN markets m ON m.id=json_extract(j.value,'$[1]')
|
||||
JOIN markets m ON m.id=json_extract(j.value,'$[1]') AND m.phase<>'resolved'
|
||||
LEFT JOIN quote_events q ON q.seq=(SELECT MAX(seq) FROM quote_events WHERE market=m.id)"
|
||||
)?;
|
||||
let mut rows = stmt.query([input])?;
|
||||
|
||||
@@ -1,57 +1,8 @@
|
||||
use crate::{Exchange, MarketDataError};
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use rusqlite::{params, Transaction};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Serialize;
|
||||
use serde_json::{json, Value};
|
||||
use std::{
|
||||
cmp::Reverse,
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct LiveVolumeQuery {
|
||||
#[serde(alias = "eventId", alias = "id")]
|
||||
event_id: Option<String>,
|
||||
}
|
||||
|
||||
impl LiveVolumeQuery {
|
||||
fn event_ids(&self) -> Result<BTreeSet<i64>, MarketDataError> {
|
||||
let mut ids = BTreeSet::new();
|
||||
for id in self.event_id.as_deref().unwrap_or_default().split(',') {
|
||||
if let Ok(id) = id.trim().parse::<i64>() {
|
||||
ids.insert(id);
|
||||
if ids.len() > 20 {
|
||||
return Err(MarketDataError::Invalid(
|
||||
"expected at most 20 distinct event IDs".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ids.is_empty() {
|
||||
return Err(MarketDataError::Invalid(
|
||||
"event_id must contain an integer".into(),
|
||||
));
|
||||
}
|
||||
Ok(ids)
|
||||
}
|
||||
}
|
||||
|
||||
impl Exchange {
|
||||
pub fn public_live_volume(&self, query: LiveVolumeQuery) -> Result<Value, MarketDataError> {
|
||||
let events = json!(query.event_ids()?).to_string();
|
||||
let tx = self.db.unchecked_transaction()?;
|
||||
let report = Report::read_selection(&tx, Some(&events), None, None)
|
||||
.map_err(|_| MarketDataError::Unavailable)?;
|
||||
let conditions: Vec<_> = report.ranked().into_iter().map(|(market, volume)| {
|
||||
json!({"condition_id":market,"taker_volume":crate::lots::display(volume.all_time.taker_shares)})
|
||||
}).collect();
|
||||
tx.commit()?;
|
||||
Ok(
|
||||
json!({"data":{"conditions":conditions,"taker_volume_total":crate::lots::display(report.total.all_time.taker_shares)}}),
|
||||
)
|
||||
}
|
||||
}
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn serialize_hundredths<S: serde::Serializer>(
|
||||
value: &i64,
|
||||
@@ -118,23 +69,13 @@ impl Report {
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
let events = event.map(|event| json!([event]).to_string());
|
||||
Self::read_selection(db, events.as_deref(), market, Some(as_of_ms))
|
||||
}
|
||||
|
||||
fn read_selection(
|
||||
db: &Transaction,
|
||||
events: Option<&str>,
|
||||
market: Option<&str>,
|
||||
as_of_ms: Option<i64>,
|
||||
) -> Result<Self> {
|
||||
let mut report = Self {
|
||||
as_of_ms: as_of_ms.unwrap_or_default(),
|
||||
as_of_ms,
|
||||
total: Volume::default(),
|
||||
markets: BTreeMap::new(),
|
||||
};
|
||||
let mut stmt = db.prepare_cached(include_str!("volume.sql"))?;
|
||||
let mut rows = stmt.query(params![events, market, as_of_ms])?;
|
||||
let mut rows = stmt.query(params![event, market, as_of_ms])?;
|
||||
while let Some(row) = rows.next()? {
|
||||
let volume = report.markets.entry(row.get(0)?).or_default();
|
||||
let recent: Option<bool> = row.get(1)?;
|
||||
@@ -148,7 +89,7 @@ impl Report {
|
||||
v.all_time.add(&totals)?;
|
||||
if recent == Some(true) {
|
||||
v.last_24h.add(&totals)?;
|
||||
} else if as_of_ms.is_some() && recent.is_none() {
|
||||
} else if recent.is_none() {
|
||||
v.unknown_time_shares = v
|
||||
.unknown_time_shares
|
||||
.checked_add(totals.matched_shares)
|
||||
@@ -163,17 +104,10 @@ impl Report {
|
||||
Ok(report)
|
||||
}
|
||||
|
||||
fn ranked(&self) -> Vec<(&String, &Volume)> {
|
||||
let mut conditions: Vec<_> = self.markets.iter().collect();
|
||||
conditions.sort_by(|(a_id, a), (b_id, b)| {
|
||||
(Reverse(a.all_time.taker_shares), a_id).cmp(&(Reverse(b.all_time.taker_shares), b_id))
|
||||
});
|
||||
conditions
|
||||
}
|
||||
|
||||
pub fn response(&self) -> Value {
|
||||
let conditions: Vec<_> = self
|
||||
.ranked()
|
||||
let mut conditions: Vec<_> = self.markets.iter().collect();
|
||||
conditions.sort_by_key(|(id, v)| (std::cmp::Reverse(v.all_time.taker_shares), *id));
|
||||
let conditions: Vec<_> = conditions
|
||||
.into_iter()
|
||||
.map(|(market, volume)| json!({"market":market,"volume":volume}))
|
||||
.collect();
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
-- ?1 contains local event keys (strings) or public directory ids (integers).
|
||||
-- ?2 selects a single market. A null ?3 requests cumulative share totals only.
|
||||
WITH event_keys(event) AS (
|
||||
SELECT value FROM json_each(?1) WHERE type='text'
|
||||
UNION ALL
|
||||
SELECT d.event FROM json_each(?1) j JOIN event_directory_ids d ON d.id=j.value
|
||||
WHERE j.type='integer'
|
||||
), selected(market) AS MATERIALIZED (
|
||||
-- ?1 selects an event's visible conditions; ?2 selects a single market.
|
||||
WITH selected(market) AS MATERIALIZED (
|
||||
SELECT s.market FROM listed_markets s
|
||||
LEFT JOIN augmented_outcomes a ON a.market=s.market
|
||||
WHERE s.event IN (SELECT event FROM event_keys) AND (a.role IS NULL OR a.role<>'placeholder')
|
||||
WHERE s.event=?1 AND (a.role IS NULL OR a.role<>'placeholder')
|
||||
UNION ALL SELECT id FROM markets WHERE id=?2
|
||||
), executions AS (
|
||||
SELECT s.market, f.seq, f.quantity, p.at_ms, f.price AS taker_price
|
||||
@@ -24,7 +18,7 @@ WITH event_keys(event) AS (
|
||||
SELECT s.market, e.at_ms BETWEEN ?3-86400000 AND ?3 AS recent,
|
||||
COALESCE(SUM(e.quantity),0),
|
||||
COALESCE(SUM(e.quantity) FILTER (WHERE c.taker_order IS NOT NULL),0),
|
||||
COALESCE(SUM(e.quantity*e.taker_price) FILTER (WHERE ?3 IS NOT NULL AND c.taker_order IS NOT NULL),0),
|
||||
COALESCE(SUM(e.quantity*e.taker_price) FILTER (WHERE c.taker_order IS NOT NULL),0),
|
||||
COALESCE(SUM(e.quantity) FILTER (WHERE c.execution IS NULL),0)
|
||||
FROM selected s LEFT JOIN executions e ON e.market=s.market
|
||||
LEFT JOIN execution_context c ON c.execution=e.seq
|
||||
|
||||
@@ -1553,21 +1553,23 @@ fn legacy_history_samples_the_book_without_fills_and_appends_the_latest_mark() {
|
||||
exchange
|
||||
.execute(json!({"op":"close","id":"close","market":"mid-example"}))
|
||||
.unwrap();
|
||||
db.execute("UPDATE chart_closures SET at_ms=273000", [])
|
||||
.unwrap();
|
||||
db.execute(
|
||||
"UPDATE quote_events SET at_ms=273000 WHERE yes_bid IS NULL AND yes_ask IS NULL",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
let before_close = vec![json!({"t":240,"p":0.915})];
|
||||
assert_eq!(read(&exchange, "NO", 180.001, 400.0), before_close);
|
||||
exchange
|
||||
.execute(json!({"op":"finalize","id":"verdict","market":"mid-example","winner":"NO"}))
|
||||
.unwrap();
|
||||
db.execute("UPDATE price_settlements SET at_ms=273000", [])
|
||||
.unwrap();
|
||||
drop(exchange);
|
||||
let reopened = Exchange::open(path).unwrap();
|
||||
assert_eq!(
|
||||
read(&reopened, "NO", 180.001, 240.0),
|
||||
vec![json!({"t":240,"p":0.915}), json!({"t":273,"p":1})]
|
||||
);
|
||||
assert_eq!(
|
||||
read(&reopened, "YES", 5.0, 5.0),
|
||||
vec![json!({"t":273,"p":0})]
|
||||
);
|
||||
assert_eq!(read(&reopened, "NO", 180.001, 400.0), before_close);
|
||||
assert!(read(&reopened, "YES", 273.0, 400.0).is_empty());
|
||||
assert!(read(&reopened, "YES", 5.0, 5.0).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -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"]}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,597 @@
|
||||
[
|
||||
{
|
||||
"catalog_url": "https://gamma-api.polymarket.com/markets?closed=true&limit=100&order=closedTime&ascending=false",
|
||||
"catalog": {
|
||||
"id": "7554899",
|
||||
"slug": "cs2-bb3-lgc-2026-12-03-game1-round-total-30pt5",
|
||||
"version": "v1",
|
||||
"conditionId": "0xdf04a0495b0a16dbce386acdc16d9aed19784db9888be53d150354b83b7c18b1",
|
||||
"closed": true,
|
||||
"closedTime": "2026-12-03 08:32:03.519799+00",
|
||||
"acceptingOrders": false,
|
||||
"umaResolutionStatus": "resolved",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"outcomes": "[\"Over\", \"Under\"]",
|
||||
"positionIds": null,
|
||||
"clobTokenIds": "[\"73979342585906843441145134109923710004884703083095161594360108477170435492453\", \"78188826358032258311424545486331333398838521699262460256542567713692269401385\"]"
|
||||
},
|
||||
"sides": [
|
||||
{
|
||||
"asset": "73979342585906843441145134109923710004884703083095161594360108477170435492453",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=73979342585906843441145134109923710004884703083095161594360108477170435492453&startTs=1796284923&endTs=1796288523&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:56 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796285541,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796285655,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796285780,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796285889,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796286038,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796286155,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.005
|
||||
},
|
||||
{
|
||||
"t": 1796286383,
|
||||
"p": 0.0005
|
||||
},
|
||||
{
|
||||
"t": 1796286495,
|
||||
"p": 0.0005
|
||||
},
|
||||
{
|
||||
"t": 1796286646,
|
||||
"p": 0.0005
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=73979342585906843441145134109923710004884703083095161594360108477170435492453&startTs=1796290323&endTs=1796290623&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:56 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=73979342585906843441145134109923710004884703083095161594360108477170435492453&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:56 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"asset": "78188826358032258311424545486331333398838521699262460256542567713692269401385",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=78188826358032258311424545486331333398838521699262460256542567713692269401385&startTs=1796284923&endTs=1796288523&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:58 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796285780,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796285889,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796286037,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796286155,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.995
|
||||
},
|
||||
{
|
||||
"t": 1796286383,
|
||||
"p": 0.9995
|
||||
},
|
||||
{
|
||||
"t": 1796286495,
|
||||
"p": 0.9995
|
||||
},
|
||||
{
|
||||
"t": 1796286646,
|
||||
"p": 0.9995
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=78188826358032258311424545486331333398838521699262460256542567713692269401385&startTs=1796290323&endTs=1796290623&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:58 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=78188826358032258311424545486331333398838521699262460256542567713692269401385&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:58 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"catalog_url": "https://gamma-api.polymarket.com/markets?closed=true&limit=100&order=closedTime&ascending=false",
|
||||
"catalog": {
|
||||
"id": "7543472",
|
||||
"slug": "setkameua-anat-illia-2026-12-03",
|
||||
"version": "v2",
|
||||
"conditionId": "0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000",
|
||||
"closed": true,
|
||||
"closedTime": "2026-12-03 08:31:00.370625+00",
|
||||
"acceptingOrders": false,
|
||||
"umaResolutionStatus": null,
|
||||
"outcomePrices": "[\"1\", \"0\"]",
|
||||
"outcomes": "[\"Nikolenko Anatolii\", \"Fokin Illia\"]",
|
||||
"positionIds": [
|
||||
"759916398134244316868652908232832573045153963965173623897622651599218278400",
|
||||
"759916398134244316868652908232832573045153963965173623897622651599218278401"
|
||||
],
|
||||
"clobTokenIds": "[\"759916398134244316868652908232832573045153963965173623897622651599218278400\", \"759916398134244316868652908232832573045153963965173623897622651599218278401\"]"
|
||||
},
|
||||
"sides": [
|
||||
{
|
||||
"asset": "759916398134244316868652908232832573045153963965173623897622651599218278400",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278400&startTs=1796284860&endTs=1796288460&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:59 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796284969,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285059,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285176,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285310,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285335,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285416,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285779,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285889,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286037,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286154,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286382,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286494,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286645,
|
||||
"p": 0.999
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278400&startTs=1796290260&endTs=1796290560&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:59 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278400&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:59 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"asset": "759916398134244316868652908232832573045153963965173623897622651599218278401",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278401&startTs=1796284860&endTs=1796288460&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:00 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796284969,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285059,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285176,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285310,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285335,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285416,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285779,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285889,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286037,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286154,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286382,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286494,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286645,
|
||||
"p": 0.001
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278401&startTs=1796290260&endTs=1796290560&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:00 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278401&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:01 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"catalog_url": "https://gamma-api.polymarket.com/markets?closed=true&limit=100&order=closedTime&ascending=false",
|
||||
"catalog": {
|
||||
"id": "7528433",
|
||||
"slug": "sol-updown-15m-1796285700",
|
||||
"version": "v2",
|
||||
"conditionId": "0x0190f69570a8ebb0d5608f8f773ffc068b000000000000000000000000000000",
|
||||
"closed": true,
|
||||
"closedTime": "2026-12-03 08:30:28.231292+00",
|
||||
"acceptingOrders": false,
|
||||
"umaResolutionStatus": null,
|
||||
"outcomePrices": "[\"1\", \"0\"]",
|
||||
"outcomes": "[\"Up\", \"Down\"]",
|
||||
"positionIds": [
|
||||
"708440684409184214698552699176045036593002385654320616860038876849074339840",
|
||||
"708440684409184214698552699176045036593002385654320616860038876849074339841"
|
||||
],
|
||||
"clobTokenIds": "[\"708440684409184214698552699176045036593002385654320616860038876849074339840\", \"708440684409184214698552699176045036593002385654320616860038876849074339841\"]"
|
||||
},
|
||||
"sides": [
|
||||
{
|
||||
"asset": "708440684409184214698552699176045036593002385654320616860038876849074339840",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339840&startTs=1796284828&endTs=1796288428&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:02 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796284968,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285058,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285173,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285310,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285334,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285414,
|
||||
"p": 0.505
|
||||
},
|
||||
{
|
||||
"t": 1796285539,
|
||||
"p": 0.505
|
||||
},
|
||||
{
|
||||
"t": 1796285653,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285778,
|
||||
"p": 0.395
|
||||
},
|
||||
{
|
||||
"t": 1796285888,
|
||||
"p": 0.55
|
||||
},
|
||||
{
|
||||
"t": 1796286036,
|
||||
"p": 0.675
|
||||
},
|
||||
{
|
||||
"t": 1796286153,
|
||||
"p": 0.8
|
||||
},
|
||||
{
|
||||
"t": 1796286251,
|
||||
"p": 0.83
|
||||
},
|
||||
{
|
||||
"t": 1796286382,
|
||||
"p": 0.83
|
||||
},
|
||||
{
|
||||
"t": 1796286494,
|
||||
"p": 0.96
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339840&startTs=1796290228&endTs=1796290528&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:02 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339840&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:02 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"asset": "708440684409184214698552699176045036593002385654320616860038876849074339841",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339841&startTs=1796284828&endTs=1796288428&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:03 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796284969,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285059,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285176,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285310,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285335,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285416,
|
||||
"p": 0.495
|
||||
},
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.495
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285779,
|
||||
"p": 0.605
|
||||
},
|
||||
{
|
||||
"t": 1796285888,
|
||||
"p": 0.455
|
||||
},
|
||||
{
|
||||
"t": 1796286036,
|
||||
"p": 0.335
|
||||
},
|
||||
{
|
||||
"t": 1796286154,
|
||||
"p": 0.205
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.17
|
||||
},
|
||||
{
|
||||
"t": 1796286382,
|
||||
"p": 0.175
|
||||
},
|
||||
{
|
||||
"t": 1796286494,
|
||||
"p": 0.08
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339841&startTs=1796290228&endTs=1796290528&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:03 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339841&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:04 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,10 @@
|
||||
{"markets":[
|
||||
{"catalog":{"id":"7554899","slug":"cs2-bb3-lgc-2026-12-03-game1-round-total-30pt5","version":"v1","conditionId":"0xdf04a0495b0a16dbce386acdc16d9aed19784db9888be53d150354b83b7c18b1","closed":true,"closedTime":"2026-12-03 08:32:03.519799+00","acceptingOrders":false,"umaResolutionStatus":"resolved","outcomePrices":"[\"0\", \"1\"]","outcomes":"[\"Over\", \"Under\"]","positionIds":null,"clobTokenIds":"[\"73979342585906843441145134109923710004884703083095161594360108477170435492453\", \"78188826358032258311424545486331333398838521699262460256542567713692269401385\"]"},"book_responses":[{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:31 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:31 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/book?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:31 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=78188826358032258311424545486331333398838521699262460256542567713692269401385","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:32 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=78188826358032258311424545486331333398838521699262460256542567713692269401385","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:32 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/book?token_id=78188826358032258311424545486331333398838521699262460256542567713692269401385","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:32 GMT","body":{"error":"No orderbook exists for the requested token id"}}],"quotes":[{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:36:26 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:36:26 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/price?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453&side=BUY","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:36:26 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","side":"BUY"},{"token_id":"78188826358032258311424545486331333398838521699262460256542567713692269401385","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:26 GMT","body":[]},{"method":"POST","url":"https://clob.polymarket.com/midpoints","payload":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","side":"BUY"},{"token_id":"78188826358032258311424545486331333398838521699262460256542567713692269401385","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:26 GMT","body":{}},{"method":"POST","url":"https://clob.polymarket.com/spreads","payload":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","side":"BUY"},{"token_id":"78188826358032258311424545486331333398838521699262460256542567713692269401385","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:26 GMT","body":{}},{"method":"POST","url":"https://clob.polymarket.com/prices","payload":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","side":"BUY"},{"token_id":"78188826358032258311424545486331333398838521699262460256542567713692269401385","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:26 GMT","body":{}}]},
|
||||
{"catalog":{"id":"7543472","slug":"setkameua-anat-illia-2026-12-03","version":"v2","conditionId":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","closed":true,"closedTime":"2026-12-03 08:31:00.370625+00","acceptingOrders":false,"umaResolutionStatus":null,"outcomePrices":"[\"1\", \"0\"]","outcomes":"[\"Nikolenko Anatolii\", \"Fokin Illia\"]","positionIds":["759916398134244316868652908232832573045153963965173623897622651599218278400","759916398134244316868652908232832573045153963965173623897622651599218278401"],"clobTokenIds":"[\"759916398134244316868652908232832573045153963965173623897622651599218278400\", \"759916398134244316868652908232832573045153963965173623897622651599218278401\"]"},"book_responses":[{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:32 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Thu, 03 Dec 2026 08:37:32 GMT","body":{"spread":"1"}},{"method":"GET","url":"https://clob.polymarket.com/book?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:32 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=759916398134244316868652908232832573045153963965173623897622651599218278401","payload":null,"status":200,"date":"Thu, 03 Dec 2026 08:37:32 GMT","body":{"mid":"0.5"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=759916398134244316868652908232832573045153963965173623897622651599218278401","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:33 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/book?token_id=759916398134244316868652908232832573045153963965173623897622651599218278401","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:32 GMT","body":{"error":"No orderbook exists for the requested token id"}}],"quotes":[{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:36:27 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Thu, 03 Dec 2026 08:36:27 GMT","body":{"spread":"1"}},{"method":"GET","url":"https://clob.polymarket.com/price?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400&side=BUY","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:36:27 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","side":"BUY"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:27 GMT","body":[]},{"method":"POST","url":"https://clob.polymarket.com/midpoints","payload":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","side":"BUY"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:27 GMT","body":{"759916398134244316868652908232832573045153963965173623897622651599218278401":"0.5"}},{"method":"POST","url":"https://clob.polymarket.com/spreads","payload":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","side":"BUY"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:27 GMT","body":{"759916398134244316868652908232832573045153963965173623897622651599218278400":"1"}},{"method":"POST","url":"https://clob.polymarket.com/prices","payload":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","side":"BUY"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:28 GMT","body":{}}]},
|
||||
{"catalog":{"id":"7528433","slug":"sol-updown-15m-1796285700","version":"v2","conditionId":"0x0190f69570a8ebb0d5608f8f773ffc068b000000000000000000000000000000","closed":true,"closedTime":"2026-12-03 08:30:28.231292+00","acceptingOrders":false,"umaResolutionStatus":null,"outcomePrices":"[\"1\", \"0\"]","outcomes":"[\"Up\", \"Down\"]","positionIds":["708440684409184214698552699176045036593002385654320616860038876849074339840","708440684409184214698552699176045036593002385654320616860038876849074339841"],"clobTokenIds":"[\"708440684409184214698552699176045036593002385654320616860038876849074339840\", \"708440684409184214698552699176045036593002385654320616860038876849074339841\"]"},"book_responses":[{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=708440684409184214698552699176045036593002385654320616860038876849074339840","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:35 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=708440684409184214698552699176045036593002385654320616860038876849074339840","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:33 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/book?token_id=708440684409184214698552699176045036593002385654320616860038876849074339840","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:33 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=708440684409184214698552699176045036593002385654320616860038876849074339841","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:34 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=708440684409184214698552699176045036593002385654320616860038876849074339841","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:33 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/book?token_id=708440684409184214698552699176045036593002385654320616860038876849074339841","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:37:34 GMT","body":{"error":"No orderbook exists for the requested token id"}}],"quotes":[{"method":"GET","url":"https://clob.polymarket.com/midpoint?token_id=708440684409184214698552699176045036593002385654320616860038876849074339840","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:36:28 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/spread?token_id=708440684409184214698552699176045036593002385654320616860038876849074339840","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:36:28 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"GET","url":"https://clob.polymarket.com/price?token_id=708440684409184214698552699176045036593002385654320616860038876849074339840&side=BUY","payload":null,"status":404,"date":"Thu, 03 Dec 2026 08:36:28 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"708440684409184214698552699176045036593002385654320616860038876849074339840","side":"BUY"},{"token_id":"708440684409184214698552699176045036593002385654320616860038876849074339841","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:28 GMT","body":[]},{"method":"POST","url":"https://clob.polymarket.com/midpoints","payload":[{"token_id":"708440684409184214698552699176045036593002385654320616860038876849074339840","side":"BUY"},{"token_id":"708440684409184214698552699176045036593002385654320616860038876849074339841","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:28 GMT","body":{}},{"method":"POST","url":"https://clob.polymarket.com/spreads","payload":[{"token_id":"708440684409184214698552699176045036593002385654320616860038876849074339840","side":"BUY"},{"token_id":"708440684409184214698552699176045036593002385654320616860038876849074339841","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:29 GMT","body":{}},{"method":"POST","url":"https://clob.polymarket.com/prices","payload":[{"token_id":"708440684409184214698552699176045036593002385654320616860038876849074339840","side":"BUY"},{"token_id":"708440684409184214698552699176045036593002385654320616860038876849074339841","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:29 GMT","body":{}}]}
|
||||
],"mixed_batch":[
|
||||
{"method":"POST","url":"https://clob.polymarket.com/books","payload":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","side":"BUY"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:29 GMT","body":[{"market":"0xa5f8a44504de30fa36fff2406b2b27b3d15476ed50448e4fc3ead4861d8a5e3e","asset_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","hash":"a4e1311a77002cac23f8be77c8e355df22551c4f"}]},
|
||||
{"method":"POST","url":"https://clob.polymarket.com/midpoints","payload":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","side":"BUY"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:29 GMT","body":{"35090254409399344650860070211816464534198960801264823587796928404808383727584":"0.0375"}},
|
||||
{"method":"POST","url":"https://clob.polymarket.com/spreads","payload":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","side":"BUY"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:29 GMT","body":{"35090254409399344650860070211816464534198960801264823587796928404808383727584":"0.001"}},
|
||||
{"method":"POST","url":"https://clob.polymarket.com/prices","payload":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","side":"BUY"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"BUY"}],"status":200,"date":"Thu, 03 Dec 2026 08:36:29 GMT","body":{"35090254409399344650860070211816464534198960801264823587796928404808383727584":{"BUY":"0.037"}}}
|
||||
]}
|
||||
@@ -163,8 +163,6 @@ FOK 要求整笔金额成交,无法用完预算时交易回滚。超过最高
|
||||
|
||||
每个统计包含 `all_time` 和 `last_24h`,后者为查询时刻往前 86,400,000 毫秒,两端均含。每笔已撮合的数量计入 `matched_shares` 一次;确认吃单的一侧另记 `taker_shares` 和成交价乘数量的 `taker_notional_cents`。互补成交按吃单方实际交易的 YES 或 NO 定价。本地开盘集合竞价没有吃单方,只计入撮合量;缺失角色的旧成交另标 `unknown_role_shares`,缺失时间的计入累计量并标 `unknown_time_shares`。成交金额、滚动窗口及竞价拆分均为本地字段。当前只支持整数份额、整分成交价,官方份额精度可到小数点后六位。
|
||||
|
||||
HTTP 客户端可先从 Gamma 事件详情取得数字 `id`,再发 `GET /v2/live-volume?event_id=<id>`。`eventId` 和 `id` 也是参数别名。支持逗号分隔的多场赛事,忽略无法解析的项,去重后最多 20 个整数。全部无效或缺少参数返回 400,合法但没有盘口时返回零和空数组。多个赛事共用一个数据库快照,返回 `data.conditions` 和 `data.taker_volume_total`,无需翻页。上面的足球样例分别返回 3、2 和四个 0;第二场赛事若没有成交,合计仍为 5。份额相同时,本地按市场 ID 排序。未命名的互斥预留位暂随本地目录隐藏;成交份额沿用模拟撮合账本的精度。公开生产端点请求连接超时,因此响应规则来自 OpenAPI,截图美元数额及生产同量排序仍待核验。[官方成交量接口](https://docs.polymarket.com/api-reference/markets/get-live-volume-for-an-event)
|
||||
|
||||
## 持仓估值与赎回
|
||||
|
||||
官方 Position 的 current_value 以当前持有份额乘以每份估值计算。账户 value 汇总单市场持仓,另含未终结组合的成本。官方展示价在双边价差不超过 10 美分时取中点,超过时采用最近成交价。Data API 对持仓的 live mark 只给出字段定义,行情页展示价与生产持仓估值是否对每个市场相同仍需实际响应对账。[Data API 的 Position 与 PortfolioValue](https://data-api.polymarket.com/v2/openapi.json) · [订单簿展示价](https://docs.polymarket.com/concepts/prices-orderbook.md)
|
||||
@@ -378,7 +376,7 @@ Polymarket 的单资产最近成交接口规定,无成交时返回价格字符
|
||||
|
||||
旧版 CLOB 客户端用 market 指定结果资产。单侧盘口的生产曲线末点为 0.0005,同批中点为 0.0005、最近成交为 0.001。一个近端成交记录为空的资产也有连续的 0.5 历史点。取早于上市的绝对区间时,有历史的资产仍返回最近可用点;新资产在中点已经可查时也可能返回空曲线。[生产请求和对照样本](examples/public-clob-history.json) · [CLOB OpenAPI](https://docs.polymarket.com/api-reference/markets/get-prices-history)
|
||||
|
||||
本地用已经提交的盘口变更重建历史中点。到每个 UTC 采样边界,取该时刻之前(含该时刻)最近一次盘口;缺买侧用 0,缺卖侧用 1。没有挂单变化时延续上次观测。窗口之外也追加最近一分钟的可用点;若与窗口最后一点重合,可出现重复时间戳。模拟裁决后在裁决时刻以兑付值收尾。已裁决的旧盘若缺少裁决时间,只使用最后有时间记录的报价。升级旧库时从第一条可信报价开始,没有报价记录的资产从迁移时刻开始。生产采集存在秒级抖动,新盘首个采样的延迟、长期历史保留和裁决后取点尚未逐点验证。V2 的成交与兑付历史保留其独立数据源。
|
||||
本地用已经提交的盘口变更重建历史中点。到每个 UTC 采样边界,取该时刻之前(含该时刻)最近一次盘口;缺买侧用 0,缺卖侧用 1。没有挂单变化时延续上次观测。窗口之外也追加最近一分钟的可用点;若与窗口最后一点重合,可出现重复时间戳。封盘后,曲线只返回请求窗口内、封盘之前的采样点。电竞、乒乓球和 SOL 涨跌盘的六个生产结果均符合这一规则。电竞负侧、胜侧的末点分别为 0.0005 和 0.9995,目录最终兑付为 0 和 1。旧库没有封盘记录时,最多采样到最后一笔非空盘口记录。生产采样时钟有秒级偏移,新盘首个采样延迟和长期保留仍待核验。V2 曲线使用成交与兑付数据。[已裁决生产样本](examples/public-closed-chart-history.json)
|
||||
|
||||
fidelity 以分钟为单位;省略或不大于零时按 1 分钟处理。相对窗口 1w 至少需要 5 分钟、1m 至少需要 10 分钟。显式起止时间最多相隔 15 天,多一秒即拒绝。单给 startTs 时读到当前;两个时间相等时仍可返回末点。合法但未上市的本地资产返回空数组。[HTTP 样例](examples/clob-http.http)
|
||||
|
||||
@@ -468,3 +466,12 @@ SDK 使用 `GET /neg-risk?token_id=…`,也可以从已缓存的 CLOB 市场
|
||||
用空数据库重放[原单状态样例](examples/order-status.jsonl)。卖方以 0.60 挂 5 份 post-only 卖单,买方按金额吃掉 2 份。卖方撤回余单后,按原订单号查询,累计成交仍为 2,可成交余量为 0,`order_type` 为 GTC。买方的原单类型为 FAK。按卖方订单号查询 `trades`,这笔执行的份额也是 2。重启和重发相同命令沿用原回执与受理时间。
|
||||
|
||||
`open_orders` 的列表和精确查询均返回 `created_at`(Unix 秒)、`order_type` 和本地扩展 `post_only`。升级已有数据库时,用已受理的命令回执和 GTD 截止记录恢复提交指令;没有原始时钟记录的受理时间为 null。缺少原始回执的历史行仍可查询,未知字段保留为 null。官方当前将累计成交和逐笔对账分别放在订单的 size_matched 和账户成交记录;其单笔订单 HTTP 接口需要账户认证。本地验证使用可信操作员的 JSONL 接口,订单号与账户是模拟环境的标识。生产私有接口尚未实测。[官方订单查询](https://docs.polymarket.com/trading/manage-orders)
|
||||
|
||||
|
||||
### 已裁决市场的公开盘口
|
||||
|
||||
对电竞、乒乓球和 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