Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1aa0549e87 |
No files matched your search
Generated
+49
@@ -2,6 +2,12 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "adler2"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.15"
|
||||
@@ -117,6 +123,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"exchange",
|
||||
"flate2",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -143,6 +150,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd9ae8fcb3ea71b0b26338b4ffb13006bb175de8fd07921089a906ce7e5e6945"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
@@ -231,6 +247,17 @@ version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
"zlib-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.3"
|
||||
@@ -647,6 +674,16 @@ version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "1.2.5"
|
||||
@@ -1058,6 +1095,12 @@ version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "simd-adler32"
|
||||
version = "0.3.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.12"
|
||||
@@ -1692,6 +1735,12 @@ dependencies = [
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zlib-rs"
|
||||
version = "0.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa76918995d776d9dd34d371030be228d021137449771493d56e29f77e4148ac"
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.23"
|
||||
|
||||
@@ -12,3 +12,4 @@ tungstenite = "0.28"
|
||||
tiny_http = "0.12"
|
||||
serde_urlencoded = "0.7"
|
||||
percent-encoding = "2"
|
||||
flate2 = "1.1"
|
||||
+20
-4
@@ -183,8 +183,6 @@ sequenceDiagram
|
||||
|
||||
路径参数使用百分号编码。即使查询从 NO 开始,primary_token_id 仍对应 YES。可重放请求见[行情 HTTP 示例](../../docs/examples/clob-http.http)。
|
||||
|
||||
已裁决资产的公开盘口、买卖报价、中点和价差单查返回 404,批查跳过该资产。
|
||||
|
||||
### 查询盘口价差与中点
|
||||
|
||||
```mermaid
|
||||
@@ -223,7 +221,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
|
||||
```
|
||||
|
||||
@@ -294,6 +292,24 @@ sequenceDiagram
|
||||
E-->>C: 匹配市场数组
|
||||
```
|
||||
|
||||
### 用游标浏览目录
|
||||
|
||||
`GET /markets/keyset` 与 `GET /events/keyset` 分别返回 markets 和 events。把满页返回的 next_cursor 用作下一次请求的 after_cursor,继续使用同一个 order。空页和不足一页的响应省略游标。默认每页 20 条,最多 100 条。事件页可按 title_search 搜索标题,limit 大于 50 时客户端需发送 `Accept-Encoding: gzip`。市场页还可重复传入 question_ids,按已登记的裁决问题筛选。
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant C as 客户端
|
||||
participant H as market_http.rs
|
||||
participant E as exchange/gamma_list/keyset.rs
|
||||
C->>H: GET /events/keyset,limit=2
|
||||
H->>E: 读取第一页及子盘
|
||||
E-->>H: events 和 next_cursor
|
||||
H-->>C: JSON,可协商 gzip
|
||||
C->>H: GET /events/keyset,使用 after_cursor
|
||||
H->>E: 校验游标并按上页末项的排序键继续
|
||||
E-->>C: 下一页,末页省略游标
|
||||
```
|
||||
|
||||
### 查询公开成交
|
||||
|
||||
`GET /v2/trades?user=bob&limit=1` 按成交时间倒序返回 Bob 作为吃单方的成交。查询双方时加 `taker_only=false`。下一页传回 `pagination.next_cursor` 并重送筛选条件。condition 支持本地市场 ID,event_id 接受 Gamma 目录里的数字事件 ID。条件列表以逗号分隔。钱包、市场和资产字段使用本地账户和目录标识。
|
||||
@@ -420,7 +436,7 @@ sequenceDiagram
|
||||
participant C as 客户端
|
||||
participant H as market_http.rs
|
||||
participant E as Exchange
|
||||
C->>H: GET /neg-risk/{token_id} 或 /neg-risk?token_id=…
|
||||
C->>H: GET /neg-risk?token_id=eb%3ANO%3Aa
|
||||
H->>E: 查询市场 a 的成员关系
|
||||
E-->>H: true
|
||||
H-->>C: 200,neg_risk 为真
|
||||
|
||||
+157
-38
@@ -200,17 +200,9 @@ fn token_setting(
|
||||
.token_id
|
||||
.into(),
|
||||
};
|
||||
if token.trim().is_empty() {
|
||||
return Err(invalid);
|
||||
}
|
||||
let missing = if name == "fee-rate" {
|
||||
(404, "fee rate not found for market")
|
||||
} else {
|
||||
(404, "market not found")
|
||||
};
|
||||
let exchange = engine.lock().map_err(|_| (500, "Internal server error"))?;
|
||||
let unavailable = |e| match e {
|
||||
exchange::MarketDataError::Invalid(_) => missing,
|
||||
exchange::MarketDataError::Invalid(_) => invalid,
|
||||
exchange::MarketDataError::Unavailable => (500, "Internal server error"),
|
||||
};
|
||||
match name {
|
||||
@@ -218,21 +210,21 @@ fn token_setting(
|
||||
let flag = exchange
|
||||
.token_neg_risk(&token)
|
||||
.map_err(unavailable)?
|
||||
.ok_or(missing)?;
|
||||
.ok_or((404, "market not found"))?;
|
||||
Ok(json!({"neg_risk":flag}))
|
||||
}
|
||||
"fee-rate" => {
|
||||
let fee = exchange
|
||||
.base_fee_bps(&token)
|
||||
.map_err(unavailable)?
|
||||
.ok_or(missing)?;
|
||||
.ok_or((404, "fee rate not found for market"))?;
|
||||
Ok(json!({"base_fee":fee}))
|
||||
}
|
||||
_ => {
|
||||
let tick = exchange
|
||||
.minimum_tick_size(&token)
|
||||
.map_err(unavailable)?
|
||||
.ok_or(missing)?;
|
||||
.ok_or((404, "market not found"))?;
|
||||
Ok(json!({"minimum_tick_size":tick}))
|
||||
}
|
||||
}
|
||||
@@ -331,8 +323,126 @@ fn clarifications(engine: &Mutex<Exchange>, query: &str) -> Reply {
|
||||
Ok(Value::Array(rows))
|
||||
}
|
||||
|
||||
fn accepts_gzip(req: &Request) -> bool {
|
||||
let mut wildcard = false;
|
||||
for item in req
|
||||
.headers()
|
||||
.iter()
|
||||
.filter(|h| h.field.equiv("Accept-Encoding"))
|
||||
.flat_map(|h| h.value.as_str().split(','))
|
||||
{
|
||||
let (name, params) = item.trim().split_once(';').unwrap_or((item.trim(), ""));
|
||||
let quality = params
|
||||
.split(';')
|
||||
.find_map(|param| param.trim().strip_prefix("q="))
|
||||
.map_or(1.0, |value| value.parse::<f32>().unwrap_or(0.0));
|
||||
let accepted = quality > 0.0 && quality <= 1.0;
|
||||
if name.trim().eq_ignore_ascii_case("gzip") {
|
||||
return accepted;
|
||||
}
|
||||
if name.trim() == "*" {
|
||||
wildcard = accepted;
|
||||
}
|
||||
}
|
||||
wildcard
|
||||
}
|
||||
|
||||
fn directory_keyset(
|
||||
req: Request,
|
||||
engine: &Mutex<Exchange>,
|
||||
resource: exchange::DirectoryResource,
|
||||
query: &str,
|
||||
) -> std::io::Result<()> {
|
||||
use exchange::{DirectoryResource, MarketDataError};
|
||||
use flate2::{write::GzEncoder, Compression};
|
||||
use std::io::Write;
|
||||
|
||||
if req.method() != &Method::Get {
|
||||
return send(req, 405, json!({"error":"Method not allowed"}), Some("GET"));
|
||||
}
|
||||
let fields = match serde_urlencoded::from_str::<Vec<(String, String)>>(query) {
|
||||
Ok(fields) => fields,
|
||||
Err(_) => {
|
||||
return send(
|
||||
req,
|
||||
422,
|
||||
json!({"type":"validation error","error":"invalid query"}),
|
||||
None,
|
||||
)
|
||||
}
|
||||
};
|
||||
let gzip = accepts_gzip(&req);
|
||||
if resource == DirectoryResource::Events
|
||||
&& !gzip
|
||||
&& fields
|
||||
.iter()
|
||||
.find(|(key, _)| key == "limit")
|
||||
.and_then(|(_, raw)| raw.parse::<i64>().ok())
|
||||
.is_some_and(|limit| limit > 50)
|
||||
{
|
||||
let mut response = Response::from_data(json!({
|
||||
"error":"gzip_required",
|
||||
"hint":"send the header Accept-Encoding: gzip. /events and /events/keyset pages with limit above 50 are served compressed only."
|
||||
}).to_string().into_bytes()).with_status_code(406);
|
||||
response.add_header(Header::from_bytes("Content-Type", "application/json").unwrap());
|
||||
response.add_header(Header::from_bytes("Vary", "Accept-Encoding").unwrap());
|
||||
return req.respond(response);
|
||||
}
|
||||
let result = engine
|
||||
.lock()
|
||||
.map_err(|_| MarketDataError::Unavailable)
|
||||
.and_then(|exchange| exchange.gamma_keyset(resource, &fields));
|
||||
let value = match result {
|
||||
Ok(value) => value,
|
||||
Err(MarketDataError::Invalid(error)) => {
|
||||
return send(
|
||||
req,
|
||||
422,
|
||||
json!({"type":"validation error","error":error}),
|
||||
None,
|
||||
)
|
||||
}
|
||||
Err(MarketDataError::Unavailable) => {
|
||||
return send(
|
||||
req,
|
||||
500,
|
||||
json!({"type":"internal error","error":"cannot get the information"}),
|
||||
None,
|
||||
)
|
||||
}
|
||||
};
|
||||
let list = if resource == DirectoryResource::Events {
|
||||
"events"
|
||||
} else {
|
||||
"markets"
|
||||
};
|
||||
let mut bytes = value.to_string().into_bytes();
|
||||
let compress = gzip && value[list].as_array().is_some_and(|rows| !rows.is_empty());
|
||||
if compress {
|
||||
let mut encoder = GzEncoder::new(Vec::new(), Compression::fast());
|
||||
encoder.write_all(&bytes)?;
|
||||
bytes = encoder.finish()?;
|
||||
}
|
||||
let mut response = Response::from_data(bytes);
|
||||
response.add_header(Header::from_bytes("Content-Type", "application/json").unwrap());
|
||||
response.add_header(Header::from_bytes("Vary", "Accept-Encoding").unwrap());
|
||||
if compress {
|
||||
response.add_header(Header::from_bytes("Content-Encoding", "gzip").unwrap());
|
||||
}
|
||||
req.respond(response)
|
||||
}
|
||||
|
||||
fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
let (path, params) = req.url().split_once('?').unwrap_or((req.url(), ""));
|
||||
let resource = match path {
|
||||
"/events/keyset" => Some(exchange::DirectoryResource::Events),
|
||||
"/markets/keyset" => Some(exchange::DirectoryResource::Markets),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(resource) = resource {
|
||||
let query = params.to_owned();
|
||||
return directory_keyset(req, engine, resource, &query);
|
||||
}
|
||||
let mut allow = None;
|
||||
if req.method() == &Method::Get
|
||||
&& matches!(
|
||||
@@ -347,8 +457,9 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
let (name, segment) = route
|
||||
.split_once('/')
|
||||
.map_or((route, None), |(name, id)| (name, Some(id)));
|
||||
let is_setting = matches!(name, "neg-risk" | "tick-size" | "fee-rate")
|
||||
&& !segment.is_some_and(|id| id.contains('/'));
|
||||
let is_setting = path == "/neg-risk"
|
||||
|| (matches!(name, "tick-size" | "fee-rate")
|
||||
&& !segment.is_some_and(|id| id.contains('/')));
|
||||
let lookup = path
|
||||
.strip_prefix('/')
|
||||
.and_then(|p| p.split_once('/'))
|
||||
@@ -624,12 +735,6 @@ mod tests {
|
||||
let lookup_info = json!({"mbf":0,"tbf":30,"fd":{"r":0.05,"e":1,"to":true},"gst":null,"nr":false,"rfqe":false,"ibce":false,"oas":0,"mos":0.01,"mts":0.0025,
|
||||
"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":"list","id":"rp-list","market":"resolved-params","rules":"resolved parameters","tick_size":"0.001","base_fees":{"maker_bps":0,"taker_bps":1000}}),
|
||||
json!({"op":"close","id":"rp-close","market":"resolved-params"}),
|
||||
json!({"op":"finalize","id":"rp-final","market":"resolved-params","winner":"YES"}),
|
||||
json!({"op":"fund","id":"v-fund","account":"unpriced-owner","cents":100}),
|
||||
json!({"op":"list","id":"v-list","market":"unpriced","rules":"valuation fixture"}),
|
||||
json!({"op":"split","id":"v-split","account":"unpriced-owner","market":"unpriced","qty":1}),
|
||||
@@ -730,6 +835,15 @@ mod tests {
|
||||
("GET","/markets?limit=0",String::new(),200,Some(json!([]))),
|
||||
("GET","/events?order=unknown",String::new(),422,None),
|
||||
("POST","/markets",String::new(),405,None),
|
||||
("GET","/markets/keyset?after_cursor=broken",String::new(),422,Some(json!({"type":"validation error","error":"invalid cursor"}))),
|
||||
("GET","/markets/keyset?offset=1",String::new(),422,Some(json!({"type":"validation error","error":"offset is not allowed on keyset endpoints"}))),
|
||||
("GET","/markets/keyset?offset=0&id=-1",String::new(),200,Some(json!({"markets":[]}))),
|
||||
("GET","/events/keyset?limit=51",String::new(),406,None),
|
||||
("GET","/events/keyset?slug=missing",String::new(),200,Some(json!({"events":[]}))),
|
||||
("GET","/events/keyset?title_search=missing",String::new(),200,Some(json!({"events":[]}))),
|
||||
("GET","/markets/keyset?question_ids=missing&closed=any",String::new(),200,Some(json!({"markets":[]}))),
|
||||
("POST","/markets/keyset",String::new(),405,None),
|
||||
|
||||
("GET",event_path.as_str(),String::new(),200,Some(topic.clone())),
|
||||
("GET","/events/slug/nvda-closing-price-2027",String::new(),200,Some(topic)),
|
||||
("GET",market_path.as_str(),String::new(),200,Some(info.clone())),
|
||||
@@ -768,14 +882,6 @@ 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"}))),
|
||||
@@ -800,17 +906,9 @@ mod tests {
|
||||
("GET","/clob-markets/missing",String::new(),400,None),
|
||||
("POST","/clob-markets/map+2%2F1","{}".into(),405,None),
|
||||
("GET",tick_query.as_str(),String::new(),200,Some(json!({"minimum_tick_size":0.01}))),
|
||||
("GET","/neg-risk/eb:NO:map+2%2F1",String::new(),200,Some(json!({"neg_risk":false}))),
|
||||
("GET","/neg-risk/",String::new(),400,Some(json!({"error":"Invalid token id"}))),
|
||||
("GET","/neg-risk/garbage",String::new(),404,Some(json!({"error":"market not found"}))),
|
||||
("GET","/fee-rate?token_id=garbage",String::new(),404,Some(json!({"error":"fee rate not found for market"}))),
|
||||
("GET","/tick-size/garbage",String::new(),404,Some(json!({"error":"market not found"}))),
|
||||
("GET","/neg-risk/eb:NO:resolved-params",String::new(),200,Some(json!({"neg_risk":false}))),
|
||||
("GET","/fee-rate/eb:NO:resolved-params",String::new(),200,Some(json!({"base_fee":1000}))),
|
||||
("GET","/tick-size/eb:NO:resolved-params",String::new(),200,Some(json!({"minimum_tick_size":0.001}))),
|
||||
("GET","/neg-risk?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"neg_risk":false}))),
|
||||
("GET","/neg-risk?token_id=eb%3ANO%3Amissing",String::new(),404,None),
|
||||
("GET","/neg-risk?token_id=bad",String::new(),404,Some(json!({"error":"market not found"}))),
|
||||
("GET","/neg-risk?token_id=bad",String::new(),400,None),
|
||||
("GET","/neg-risk",String::new(),400,None),
|
||||
("POST","/neg-risk",String::new(),405,None),
|
||||
("GET","/fee-rate?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"base_fee":30}))),
|
||||
@@ -882,7 +980,7 @@ mod tests {
|
||||
("GET", "/books", String::new(), 405, None),
|
||||
("POST", "/order", "{}".into(), 404, None),
|
||||
];
|
||||
let count = cases.len();
|
||||
let count = cases.len() + 1;
|
||||
let worker = thread::spawn(move || {
|
||||
let db = Mutex::new(db);
|
||||
for _ in 0..count {
|
||||
@@ -921,6 +1019,27 @@ mod tests {
|
||||
assert!(actual["error"].is_string());
|
||||
}
|
||||
}
|
||||
let mut socket = TcpStream::connect(port).unwrap();
|
||||
socket
|
||||
.set_read_timeout(Some(Duration::from_secs(5)))
|
||||
.unwrap();
|
||||
write!(socket, "GET /events/keyset?limit=51 HTTP/1.0\r\nHost: {port}\r\nAccept-Encoding: gzip\r\nConnection: close\r\n\r\n").unwrap();
|
||||
let mut message = Vec::new();
|
||||
socket.read_to_end(&mut message).unwrap();
|
||||
let split = message
|
||||
.windows(4)
|
||||
.position(|bytes| bytes == b"\r\n\r\n")
|
||||
.unwrap();
|
||||
let headers = std::str::from_utf8(&message[..split])
|
||||
.unwrap()
|
||||
.to_ascii_lowercase();
|
||||
assert_eq!(headers.split_whitespace().nth(1), Some("200"));
|
||||
assert!(headers.contains("content-encoding: gzip"));
|
||||
assert!(headers.contains("vary: accept-encoding"));
|
||||
let decoder = flate2::read::GzDecoder::new(&message[split + 4..]);
|
||||
let page: Value = serde_json::from_reader(decoder).unwrap();
|
||||
assert_eq!(page["events"][0]["markets"].as_array().unwrap().len(), 2);
|
||||
assert!(page.get("next_cursor").is_none());
|
||||
worker.join().unwrap();
|
||||
}
|
||||
}
|
||||
@@ -1107,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 命令继续查询最优对手价。
|
||||
@@ -1133,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"]
|
||||
```
|
||||
@@ -1145,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 为十进制数
|
||||
```
|
||||
@@ -1215,6 +1215,8 @@ sequenceDiagram
|
||||
```mermaid
|
||||
flowchart LR
|
||||
L["lib.rs · Exchange"] --> P["gamma_list.rs · 参数、分页与分组"]
|
||||
K["gamma_list/keyset.rs · 游标验证"] --> P
|
||||
K --> S["schema.sql · 已有游标签名密钥"]
|
||||
P --> M["gamma_market.sql · 可见市场"]
|
||||
P --> E["gamma_events.sql · 事件关闭状态"]
|
||||
P --> W["gamma_directory.rs · 与详情共用输出字段"]
|
||||
@@ -1237,6 +1239,8 @@ sequenceDiagram
|
||||
|
||||
一个本地事件有可见盘口且所有可见盘口均已封盘时,目录将事件标为 closed。空事件和仍有开放子盘的事件保持开放。
|
||||
|
||||
游标请求复用同一组市场和事件查询。每页开启新的读事务,使用上一页末项的排序列和数字 ID 定位。已上架记录在游标之前插入时,后续页仍从游标之后读取。目录状态在翻页期间仍可变化。游标按数据库签名,可跨进程重启继续读取。
|
||||
|
||||
### 从账本查询公开成交
|
||||
|
||||
```mermaid
|
||||
|
||||
@@ -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, false)?
|
||||
find(tx, books, token, outcome, market)?
|
||||
.context("No orderbook exists for the requested token id")
|
||||
}
|
||||
|
||||
@@ -55,14 +55,12 @@ 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 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],
|
||||
FROM book_snapshot_times WHERE market=?1",
|
||||
[market],
|
||||
|r| Ok((r.get(0)?, r.get(1)?)),
|
||||
)
|
||||
.optional()?;
|
||||
@@ -116,7 +114,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, true)? {
|
||||
if let Some(book) = find(tx, books, token, outcome, market)? {
|
||||
result.push(serde_json::to_value(book)?);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
mod keyset;
|
||||
|
||||
use crate::{
|
||||
assets,
|
||||
gamma_directory::{header, market},
|
||||
Exchange, MarketDataError,
|
||||
};
|
||||
use rusqlite::{params, Connection};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
#[derive(Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||
pub enum DirectoryResource {
|
||||
Events,
|
||||
Markets,
|
||||
@@ -19,6 +22,8 @@ struct Filters {
|
||||
slugs: Vec<String>,
|
||||
conditions: Vec<String>,
|
||||
tokens: Vec<String>,
|
||||
questions: Vec<String>,
|
||||
title_search: Option<String>,
|
||||
closed: Option<bool>,
|
||||
active: Option<bool>,
|
||||
order: String,
|
||||
@@ -31,10 +36,79 @@ fn invalid(field: &str) -> MarketDataError {
|
||||
MarketDataError::Invalid(format!("Invalid directory parameter: {field}"))
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct SortColumn {
|
||||
field: &'static str,
|
||||
sql: &'static str,
|
||||
}
|
||||
|
||||
struct Sort {
|
||||
columns: Vec<SortColumn>,
|
||||
ascending: bool,
|
||||
}
|
||||
|
||||
impl Sort {
|
||||
fn ordering(&self) -> String {
|
||||
let dir = if self.ascending { "ASC" } else { "DESC" };
|
||||
self.columns
|
||||
.iter()
|
||||
.map(|col| format!("{} {dir}", col.sql))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
fn seek(&self, parameter: usize, has_cursor: bool) -> String {
|
||||
if !has_cursor {
|
||||
return format!("AND ?{parameter} IS NULL");
|
||||
}
|
||||
let columns = self
|
||||
.columns
|
||||
.iter()
|
||||
.map(|col| col.sql)
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let keys = (0..self.columns.len())
|
||||
.map(|i| format!("json_extract(?{parameter},'$[{i}]')"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let op = if self.ascending { ">" } else { "<" };
|
||||
format!("AND ({columns}) {op} ({keys})")
|
||||
}
|
||||
|
||||
fn anchor(&self, row: &Value) -> Option<Vec<Value>> {
|
||||
self.columns
|
||||
.iter()
|
||||
.map(|col| {
|
||||
let value = row[col.field].as_str()?;
|
||||
if col.field == "id" {
|
||||
value.parse::<i64>().ok().map(Value::from)
|
||||
} else {
|
||||
Some(Value::from(value))
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl Filters {
|
||||
fn parse_keyset(
|
||||
resource: DirectoryResource,
|
||||
fields: &[(String, String)],
|
||||
) -> Result<Self, MarketDataError> {
|
||||
Self::parse(resource, fields, true).map_err(|error| match error {
|
||||
MarketDataError::Invalid(ref message)
|
||||
if message == "Invalid directory parameter: closed" =>
|
||||
{
|
||||
MarketDataError::Invalid("\"closed\" has a wrong value".into())
|
||||
}
|
||||
other => other,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse(
|
||||
resource: DirectoryResource,
|
||||
fields: &[(String, String)],
|
||||
keyset: bool,
|
||||
) -> Result<Self, MarketDataError> {
|
||||
let markets = resource == DirectoryResource::Markets;
|
||||
let mut f = Self {
|
||||
@@ -66,10 +140,12 @@ impl Filters {
|
||||
value
|
||||
.parse::<i64>()
|
||||
.ok()
|
||||
.filter(|n| *n > 0)
|
||||
.filter(|n| keyset || *n > 0)
|
||||
.ok_or_else(|| invalid(key))?,
|
||||
),
|
||||
"slug" if !value.trim().is_empty() => f.slugs.push(value.clone()),
|
||||
"question_ids" if keyset && markets => f.questions.push(value.to_ascii_lowercase()),
|
||||
"title_search" if keyset && !markets => f.title_search = Some(value.clone()),
|
||||
"condition_ids" if markets && !value.trim().is_empty() => {
|
||||
f.conditions.push(value.clone())
|
||||
}
|
||||
@@ -84,6 +160,7 @@ impl Filters {
|
||||
f.slugs.len(),
|
||||
f.conditions.len(),
|
||||
f.tokens.len(),
|
||||
f.questions.len(),
|
||||
];
|
||||
if markets && sizes.iter().any(|n| *n > 100) {
|
||||
return Err(invalid("at most 100 values per identifier filter"));
|
||||
@@ -94,33 +171,35 @@ impl Filters {
|
||||
Ok(f)
|
||||
}
|
||||
|
||||
fn ordering(&self, resource: DirectoryResource) -> Result<String, MarketDataError> {
|
||||
fn sort(&self, resource: DirectoryResource) -> Result<Sort, MarketDataError> {
|
||||
let markets = resource == DirectoryResource::Markets;
|
||||
let id = if markets {
|
||||
"CAST(w.id AS INTEGER)"
|
||||
} else {
|
||||
"e.event_id"
|
||||
};
|
||||
let mut cols = Vec::new();
|
||||
for field in self.order.split(',').map(str::trim) {
|
||||
cols.push(match field {
|
||||
"id" => id,
|
||||
"slug" if markets => "w.slug",
|
||||
"slug" => "e.slug",
|
||||
"question" if markets => "w.question",
|
||||
"title" if !markets => "e.title",
|
||||
let mut columns = Vec::new();
|
||||
for name in self.order.split(',').map(str::trim) {
|
||||
let (field, sql) = match name {
|
||||
"id" => ("id", id),
|
||||
"slug" if markets => ("slug", "w.slug"),
|
||||
"slug" => ("slug", "e.slug"),
|
||||
"question" if markets => ("question", "w.question"),
|
||||
"title" if !markets => ("title", "e.title"),
|
||||
_ => return Err(invalid("order")),
|
||||
};
|
||||
columns.push(SortColumn { field, sql });
|
||||
}
|
||||
if !columns.iter().any(|col| col.field == "id") {
|
||||
columns.push(SortColumn {
|
||||
field: "id",
|
||||
sql: id,
|
||||
});
|
||||
}
|
||||
if !cols.contains(&id) {
|
||||
cols.push(id)
|
||||
}
|
||||
let dir = if self.ascending { "ASC" } else { "DESC" };
|
||||
Ok(cols
|
||||
.iter()
|
||||
.map(|col| format!("{col} {dir}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "))
|
||||
Ok(Sort {
|
||||
columns,
|
||||
ascending: self.ascending,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,13 +209,22 @@ const MARKET_FILTER: &str = "
|
||||
AND (?3='[]' OR w.market IN (SELECT value FROM json_each(?3)))
|
||||
AND (?4 IS NULL OR w.market IN (SELECT value FROM json_each(?4)))
|
||||
AND (?5 IS NULL OR (m.phase NOT IN ('preopen','continuous'))=?5)
|
||||
AND (?8 IS NULL OR COALESCE(v.active,1)=?8)";
|
||||
AND (?8 IS NULL OR COALESCE(v.active,1)=?8)
|
||||
AND (?10='[]' OR w.market IN (
|
||||
SELECT market FROM resolution_questions WHERE question_id IN (SELECT value FROM json_each(?10))
|
||||
))";
|
||||
const EVENT_FILTER: &str = "
|
||||
WHERE (?1='[]' OR e.event_id IN (SELECT value FROM json_each(?1)))
|
||||
AND (?2='[]' OR e.slug IN (SELECT value FROM json_each(?2)))
|
||||
AND (?3 IS NULL OR e.closed=?3)";
|
||||
AND (?3 IS NULL OR e.closed=?3)
|
||||
AND (?7 IS NULL OR instr(lower(e.title),lower(?7))>0)";
|
||||
|
||||
fn markets(db: &Connection, f: &Filters, order: &str) -> rusqlite::Result<Vec<Value>> {
|
||||
fn markets(
|
||||
db: &Connection,
|
||||
f: &Filters,
|
||||
sort: &Sort,
|
||||
anchor: Option<&str>,
|
||||
) -> rusqlite::Result<Vec<Value>> {
|
||||
// A supplied set containing only foreign tokens must match nothing.
|
||||
let token_markets = (!f.tokens.is_empty()).then(|| {
|
||||
let keys: Vec<_> = f
|
||||
@@ -146,8 +234,10 @@ fn markets(db: &Connection, f: &Filters, order: &str) -> rusqlite::Result<Vec<Va
|
||||
.collect();
|
||||
json!(keys).to_string()
|
||||
});
|
||||
let order = sort.ordering();
|
||||
let seek = sort.seek(9, anchor.is_some());
|
||||
let sql = format!(
|
||||
"{}{MARKET_FILTER} ORDER BY {order} LIMIT ?6 OFFSET ?7",
|
||||
"{}{MARKET_FILTER} {seek} ORDER BY {order} LIMIT ?6 OFFSET ?7",
|
||||
include_str!("gamma_market.sql")
|
||||
);
|
||||
let mut stmt = db.prepare_cached(&sql)?;
|
||||
@@ -161,7 +251,9 @@ fn markets(db: &Connection, f: &Filters, order: &str) -> rusqlite::Result<Vec<Va
|
||||
f.closed,
|
||||
f.limit,
|
||||
f.offset,
|
||||
f.active
|
||||
f.active,
|
||||
anchor,
|
||||
json!(f.questions).to_string()
|
||||
],
|
||||
|r| Ok((market(r)?, r.get::<_, Option<String>>("parent")?)),
|
||||
)?
|
||||
@@ -187,9 +279,16 @@ fn markets(db: &Connection, f: &Filters, order: &str) -> rusqlite::Result<Vec<Va
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn events(db: &Connection, f: &Filters, order: &str) -> rusqlite::Result<Vec<Value>> {
|
||||
fn events(
|
||||
db: &Connection,
|
||||
f: &Filters,
|
||||
sort: &Sort,
|
||||
anchor: Option<&str>,
|
||||
) -> rusqlite::Result<Vec<Value>> {
|
||||
let order = sort.ordering();
|
||||
let seek = sort.seek(6, anchor.is_some());
|
||||
let sql = format!(
|
||||
"SELECT * FROM ({}) e {EVENT_FILTER} ORDER BY {order} LIMIT ?4 OFFSET ?5",
|
||||
"SELECT * FROM ({}) e {EVENT_FILTER} {seek} ORDER BY {order} LIMIT ?4 OFFSET ?5",
|
||||
include_str!("gamma_events.sql")
|
||||
);
|
||||
let mut stmt = db.prepare_cached(&sql)?;
|
||||
@@ -200,7 +299,9 @@ fn events(db: &Connection, f: &Filters, order: &str) -> rusqlite::Result<Vec<Val
|
||||
json!(f.slugs).to_string(),
|
||||
f.closed,
|
||||
f.limit,
|
||||
f.offset
|
||||
f.offset,
|
||||
anchor,
|
||||
f.title_search.as_deref()
|
||||
],
|
||||
header,
|
||||
)?
|
||||
@@ -233,18 +334,28 @@ impl Exchange {
|
||||
resource: DirectoryResource,
|
||||
fields: &[(String, String)],
|
||||
) -> Result<Vec<Value>, MarketDataError> {
|
||||
let f = Filters::parse(resource, fields)?;
|
||||
let order = f.ordering(resource)?;
|
||||
// Event publication is independent of each child market.
|
||||
if (resource == DirectoryResource::Events && f.active == Some(false)) || f.limit == 0 {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let f = Filters::parse(resource, fields, false)?;
|
||||
let sort = f.sort(resource)?;
|
||||
let tx = self.db.unchecked_transaction()?;
|
||||
let page = match resource {
|
||||
DirectoryResource::Events => events(&tx, &f, &order)?,
|
||||
DirectoryResource::Markets => markets(&tx, &f, &order)?,
|
||||
};
|
||||
let page = page(&tx, resource, &f, &sort, None)?;
|
||||
tx.commit()?;
|
||||
Ok(page)
|
||||
}
|
||||
}
|
||||
|
||||
fn page(
|
||||
db: &Connection,
|
||||
resource: DirectoryResource,
|
||||
f: &Filters,
|
||||
sort: &Sort,
|
||||
anchor: Option<&str>,
|
||||
) -> rusqlite::Result<Vec<Value>> {
|
||||
// Event publication is independent of each child market.
|
||||
if (resource == DirectoryResource::Events && f.active == Some(false)) || f.limit == 0 {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
match resource {
|
||||
DirectoryResource::Events => events(db, f, sort, anchor),
|
||||
DirectoryResource::Markets => markets(db, f, sort, anchor),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
use super::{page, DirectoryResource, Filters};
|
||||
use crate::{Exchange, MarketDataError};
|
||||
use data_encoding::BASE64URL_NOPAD;
|
||||
use hmac::{Hmac, Mac};
|
||||
use rusqlite::Connection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use sha2::Sha256;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
struct Cursor {
|
||||
resource: DirectoryResource,
|
||||
order: Vec<String>,
|
||||
keys: Vec<Value>,
|
||||
}
|
||||
|
||||
fn invalid(message: &str) -> MarketDataError {
|
||||
MarketDataError::Invalid(message.into())
|
||||
}
|
||||
|
||||
fn cursor_mac(db: &Connection) -> Result<Hmac<Sha256>, MarketDataError> {
|
||||
let secret: Vec<u8> = db.query_row(
|
||||
"SELECT secret FROM trade_cursor_key WHERE singleton=1",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
let mut mac = Hmac::<Sha256>::new_from_slice(&secret).expect("HMAC accepts any key length");
|
||||
mac.update(b"eventbook:gamma:keyset:v1\0");
|
||||
Ok(mac)
|
||||
}
|
||||
|
||||
impl Cursor {
|
||||
fn decode(db: &Connection, raw: &str) -> Result<Self, MarketDataError> {
|
||||
let bytes = BASE64URL_NOPAD
|
||||
.decode(raw.as_bytes())
|
||||
.map_err(|_| invalid("invalid cursor"))?;
|
||||
let split = bytes
|
||||
.len()
|
||||
.checked_sub(32)
|
||||
.ok_or_else(|| invalid("invalid cursor"))?;
|
||||
let (payload, signature) = bytes.split_at(split);
|
||||
let mut mac = cursor_mac(db)?;
|
||||
mac.update(payload);
|
||||
mac.verify_slice(signature)
|
||||
.map_err(|_| invalid("invalid cursor"))?;
|
||||
serde_json::from_slice(payload).map_err(|_| invalid("invalid cursor"))
|
||||
}
|
||||
|
||||
fn encode(&self, db: &Connection) -> Result<String, MarketDataError> {
|
||||
let mut bytes = serde_json::to_vec(self).map_err(|_| MarketDataError::Unavailable)?;
|
||||
let mut mac = cursor_mac(db)?;
|
||||
mac.update(&bytes);
|
||||
bytes.extend_from_slice(&mac.finalize().into_bytes());
|
||||
Ok(BASE64URL_NOPAD.encode(&bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl Exchange {
|
||||
pub fn gamma_keyset(
|
||||
&self,
|
||||
resource: DirectoryResource,
|
||||
fields: &[(String, String)],
|
||||
) -> Result<Value, MarketDataError> {
|
||||
let mut after = None;
|
||||
let mut requested_limit = None;
|
||||
let mut order = None;
|
||||
let mut ascending = None;
|
||||
let mut filters = Vec::new();
|
||||
for (key, value) in fields {
|
||||
match key.as_str() {
|
||||
"after_cursor" => {
|
||||
after.get_or_insert(value.as_str());
|
||||
}
|
||||
"limit" => {
|
||||
requested_limit.get_or_insert(value.as_str());
|
||||
}
|
||||
"order" => {
|
||||
order.get_or_insert(value.as_str());
|
||||
}
|
||||
"ascending" => {
|
||||
ascending.get_or_insert(value.as_str());
|
||||
}
|
||||
"offset" => {
|
||||
if value
|
||||
.parse::<i64>()
|
||||
.map_err(|_| invalid("invalid integer"))?
|
||||
!= 0
|
||||
{
|
||||
return Err(invalid("offset is not allowed on keyset endpoints"));
|
||||
}
|
||||
}
|
||||
"id" => {
|
||||
value
|
||||
.parse::<i64>()
|
||||
.map_err(|_| invalid("invalid integer"))?;
|
||||
filters.push((key.clone(), value.clone()));
|
||||
}
|
||||
"closed" | "active" | "slug" => filters.push((key.clone(), value.clone())),
|
||||
"condition_ids" | "clob_token_ids" | "question_ids"
|
||||
if resource == DirectoryResource::Markets =>
|
||||
{
|
||||
filters.push((key.clone(), value.clone()))
|
||||
}
|
||||
"title_search" if resource == DirectoryResource::Events => {
|
||||
filters.push((key.clone(), value.clone()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let limit = match requested_limit {
|
||||
Some(raw) => raw.parse::<i64>().map_err(|_| invalid("invalid integer"))?,
|
||||
None => 20,
|
||||
};
|
||||
let order = order
|
||||
.unwrap_or_default()
|
||||
.split(',')
|
||||
.map(str::trim)
|
||||
.filter(|field| !field.is_empty())
|
||||
.map(str::to_owned)
|
||||
.collect::<Vec<_>>();
|
||||
let ascending = match ascending {
|
||||
None | Some("1" | "t" | "T" | "true" | "TRUE" | "True") => true,
|
||||
Some("0" | "f" | "F" | "false" | "FALSE" | "False") => false,
|
||||
_ => return Err(invalid("invalid boolean")),
|
||||
};
|
||||
let mut f = Filters::parse_keyset(resource, &filters)?;
|
||||
f.limit = if limit <= 0 { 20 } else { limit.min(100) };
|
||||
f.ascending = order.is_empty() || ascending;
|
||||
if !order.is_empty() {
|
||||
f.order = order.join(",");
|
||||
}
|
||||
let sort = f
|
||||
.sort(resource)
|
||||
.map_err(|_| invalid("order fields are not valid"))?;
|
||||
let tx = self.db.unchecked_transaction()?;
|
||||
let anchor = after
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(|token| {
|
||||
let cursor = Cursor::decode(&tx, token)?;
|
||||
if cursor.resource != resource
|
||||
|| cursor.order != order
|
||||
|| cursor.keys.len() != sort.columns.len()
|
||||
{
|
||||
return Err(invalid("invalid cursor"));
|
||||
}
|
||||
Ok(json!(cursor.keys).to_string())
|
||||
})
|
||||
.transpose()?;
|
||||
let rows = page(&tx, resource, &f, &sort, anchor.as_deref())?;
|
||||
let field = match resource {
|
||||
DirectoryResource::Events => "events",
|
||||
DirectoryResource::Markets => "markets",
|
||||
};
|
||||
let next_cursor = if rows.len() == f.limit as usize {
|
||||
let keys = rows
|
||||
.last()
|
||||
.and_then(|row| sort.anchor(row))
|
||||
.ok_or(MarketDataError::Unavailable)?;
|
||||
Some(
|
||||
Cursor {
|
||||
resource,
|
||||
order,
|
||||
keys,
|
||||
}
|
||||
.encode(&tx)?,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut response = json!({});
|
||||
response[field] = json!(rows);
|
||||
if let Some(next) = next_cursor {
|
||||
response["next_cursor"] = json!(next);
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(response)
|
||||
}
|
||||
}
|
||||
@@ -121,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_closed')",
|
||||
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='trigger' AND name='chart_market_listed')",
|
||||
[], |r| r.get(0),
|
||||
)?;
|
||||
if !history_ready {
|
||||
|
||||
@@ -12,12 +12,4 @@ 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,16 +2,14 @@
|
||||
-- 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 chart_closures WHERE market=?1) AS closed_ms,
|
||||
(SELECT phase IN ('closed','resolved') FROM markets WHERE id=?1) AS closed
|
||||
(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
|
||||
), bounds AS (
|
||||
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
|
||||
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
|
||||
FROM horizon
|
||||
), grid(ms) AS (
|
||||
SELECT ((MAX(?3,first_ms)+?5-1)/?5)*?5 FROM bounds
|
||||
@@ -21,12 +19,14 @@ WITH RECURSIVE horizon AS (
|
||||
), points(ms,tail) AS (
|
||||
SELECT ms,0 FROM grid
|
||||
UNION ALL
|
||||
SELECT last_ms,1 FROM bounds WHERE NOT closed AND first_ms<=last_ms
|
||||
SELECT last_ms,1 FROM bounds WHERE resolved_ms IS NOT NULL OR first_ms<=last_ms
|
||||
)
|
||||
SELECT points.ms/1000,
|
||||
CASE WHEN ?2='YES' THEN (COALESCE(q.yes_bid,0)+COALESCE(q.yes_ask,10000))*50
|
||||
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
|
||||
ELSE 1000000-(COALESCE(q.yes_bid,0)+COALESCE(q.yes_ask,10000))*50 END
|
||||
FROM points
|
||||
FROM points CROSS JOIN bounds b
|
||||
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, false)?
|
||||
quote_rows(db, requests)?
|
||||
.into_iter()
|
||||
.zip(requests)
|
||||
.map(|(quote, request)| {
|
||||
@@ -220,11 +220,7 @@ fn price_rows(db: &Connection, requests: &[PriceRequest]) -> Result<Vec<Option<S
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn quote_rows(
|
||||
db: &Connection,
|
||||
requests: &[PriceRequest],
|
||||
public_only: bool,
|
||||
) -> Result<Vec<Option<Quote>>> {
|
||||
fn quote_rows(db: &Connection, requests: &[PriceRequest]) -> Result<Vec<Option<Quote>>> {
|
||||
if !(1..=500).contains(&requests.len()) {
|
||||
return Err(PriceQueryError::RequestCount.into());
|
||||
}
|
||||
@@ -238,11 +234,11 @@ fn quote_rows(
|
||||
}
|
||||
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 AND (NOT ?2 OR m.phase<>'resolved')
|
||||
FROM json_each(?1) j LEFT JOIN markets m ON m.id=j.value
|
||||
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(params![serde_json::to_string(&markets)?, public_only])?;
|
||||
let mut rows = stmt.query([serde_json::to_string(&markets)?])?;
|
||||
let mut quotes = Vec::with_capacity(requests.len());
|
||||
while let Some(row) = rows.next()? {
|
||||
let index: usize = row.get(5)?;
|
||||
@@ -288,7 +284,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, true)?) {
|
||||
for (request, quote) in requests.iter().zip(quote_rows(&tx, requests)?) {
|
||||
if let Some(quote) = quote {
|
||||
let (bid, ask) = quote.public_sides();
|
||||
let ticks = match request.side {
|
||||
@@ -337,7 +333,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]') AND m.phase<>'resolved'
|
||||
JOIN markets m ON m.id=json_extract(j.value,'$[1]')
|
||||
LEFT JOIN quote_events q ON q.seq=(SELECT MAX(seq) FROM quote_events WHERE market=m.id)"
|
||||
)?;
|
||||
let mut rows = stmt.query([input])?;
|
||||
|
||||
@@ -1553,23 +1553,21 @@ 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, 400.0), before_close);
|
||||
assert!(read(&reopened, "YES", 273.0, 400.0).is_empty());
|
||||
assert!(read(&reopened, "YES", 5.0, 5.0).is_empty());
|
||||
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})]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -4178,3 +4176,67 @@ fn order_submission_terms_survive_fills_cancel_retries_and_legacy_upgrade() {
|
||||
assert_eq!(e.execute(cmd.clone()).unwrap()["orders"][0], expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keyset_directory_resumes_after_reopen_and_new_listing() {
|
||||
use exchange::DirectoryResource::{Events, Markets};
|
||||
let dir = tempdir().unwrap();
|
||||
let database = dir.path().join("directory.sqlite");
|
||||
let mut db = Exchange::open(&database).unwrap();
|
||||
for (slug, title) in [("one", "B"), ("two", "C"), ("three", "C")] {
|
||||
db.execute(
|
||||
json!({"op":"list","id":format!("list-{slug}"),"market":slug,
|
||||
"rules":"test","question":title}),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
let first = [
|
||||
("order".into(), "question".into()),
|
||||
("limit".into(), "2".into()),
|
||||
];
|
||||
let page = db.gamma_keyset(Markets, &first).unwrap();
|
||||
assert_eq!(page["markets"][0]["slug"], "one");
|
||||
assert_eq!(page["markets"][1]["slug"], "two");
|
||||
let cursor = page["next_cursor"].as_str().unwrap().to_owned();
|
||||
drop(db);
|
||||
|
||||
let mut db = Exchange::open(&database).unwrap();
|
||||
db.execute(json!({"op":"list","id":"new","market":"inserted",
|
||||
"rules":"test","question":"A"}))
|
||||
.unwrap();
|
||||
assert!(db
|
||||
.gamma_keyset(Markets, &[("after_cursor".into(), cursor.clone())])
|
||||
.is_err());
|
||||
assert!(db
|
||||
.gamma_keyset(
|
||||
Events,
|
||||
&[
|
||||
("order".into(), "title".into()),
|
||||
("after_cursor".into(), cursor.clone()),
|
||||
]
|
||||
)
|
||||
.is_err());
|
||||
let next = db
|
||||
.gamma_keyset(
|
||||
Markets,
|
||||
&[
|
||||
("order".into(), "question".into()),
|
||||
("limit".into(), "1".into()),
|
||||
("after_cursor".into(), cursor),
|
||||
],
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(next["markets"][0]["slug"], "three");
|
||||
let last = next["next_cursor"].as_str().unwrap().to_owned();
|
||||
assert_eq!(
|
||||
db.gamma_keyset(
|
||||
Markets,
|
||||
&[
|
||||
("order".into(), "question".into()),
|
||||
("after_cursor".into(), last),
|
||||
]
|
||||
)
|
||||
.unwrap(),
|
||||
json!({"markets":[]})
|
||||
);
|
||||
}
|
||||
@@ -1,597 +0,0 @@
|
||||
[
|
||||
{
|
||||
"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": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -1,10 +0,0 @@
|
||||
{"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"}}}
|
||||
]}
|
||||
@@ -1,38 +0,0 @@
|
||||
[
|
||||
{"endpoint":"fee-rate","mode":"query","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:31 GMT","body":{"base_fee":1000}}},
|
||||
{"endpoint":"fee-rate","mode":"query","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:31 GMT","body":{"base_fee":1000}}},
|
||||
{"endpoint":"fee-rate","mode":"query","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:31 GMT","body":{"base_fee":1000}}},
|
||||
{"endpoint":"fee-rate","mode":"query","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:31 GMT","body":{"error":"fee rate not found for market"}}},
|
||||
{"endpoint":"fee-rate","mode":"query","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"fee rate not found for market"}}},
|
||||
{"endpoint":"fee-rate","mode":"query","case":"blank","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate?token_id=","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"Invalid token id"}}},
|
||||
{"endpoint":"fee-rate","mode":"json_path","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"base_fee":1000}}},
|
||||
{"endpoint":"fee-rate","mode":"json_path","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"base_fee":1000}}},
|
||||
{"endpoint":"fee-rate","mode":"json_path","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"base_fee":1000}}},
|
||||
{"endpoint":"fee-rate","mode":"json_path","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"fee rate not found for market"}}},
|
||||
{"endpoint":"fee-rate","mode":"json_path","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate/not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"fee rate not found for market"}}},
|
||||
{"endpoint":"tick-size","mode":"query","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"minimum_tick_size":0.001}}},
|
||||
{"endpoint":"tick-size","mode":"query","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"minimum_tick_size":0.001}}},
|
||||
{"endpoint":"tick-size","mode":"query","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"minimum_tick_size":0.001}}},
|
||||
{"endpoint":"tick-size","mode":"query","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"market not found"}}},
|
||||
{"endpoint":"tick-size","mode":"query","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:32 GMT","body":{"error":"market not found"}}},
|
||||
{"endpoint":"tick-size","mode":"query","case":"blank","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size?token_id=","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"Invalid token id"}}},
|
||||
{"endpoint":"tick-size","mode":"json_path","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"minimum_tick_size":0.001}}},
|
||||
{"endpoint":"tick-size","mode":"json_path","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"minimum_tick_size":0.001}}},
|
||||
{"endpoint":"tick-size","mode":"json_path","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"minimum_tick_size":0.001}}},
|
||||
{"endpoint":"tick-size","mode":"json_path","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"market not found"}}},
|
||||
{"endpoint":"tick-size","mode":"json_path","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size/not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"market not found"}}},
|
||||
{"endpoint":"neg-risk","mode":"query","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"neg_risk":true}}},
|
||||
{"endpoint":"neg-risk","mode":"query","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"neg_risk":false}}},
|
||||
{"endpoint":"neg-risk","mode":"query","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"neg_risk":false}}},
|
||||
{"endpoint":"neg-risk","mode":"query","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:33 GMT","body":{"error":"market not found"}}},
|
||||
{"endpoint":"neg-risk","mode":"query","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"market not found"}}},
|
||||
{"endpoint":"neg-risk","mode":"query","case":"blank","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk?token_id=","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"Invalid token id"}}},
|
||||
{"endpoint":"neg-risk","mode":"json_path","case":"live","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/35090254409399344650860070211816464534198960801264823587796928404808383727584","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"neg_risk":true}}},
|
||||
{"endpoint":"neg-risk","mode":"json_path","case":"resolved_v1","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/73979342585906843441145134109923710004884703083095161594360108477170435492453","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"neg_risk":false}}},
|
||||
{"endpoint":"neg-risk","mode":"json_path","case":"resolved_v2","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/759916398134244316868652908232832573045153963965173623897622651599218278400","payload":null,"status":200,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"neg_risk":false}}},
|
||||
{"endpoint":"neg-risk","mode":"json_path","case":"unknown","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/123","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"market not found"}}},
|
||||
{"endpoint":"neg-risk","mode":"json_path","case":"malformed","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk/not-an-asset","payload":null,"status":404,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"market not found"}}},
|
||||
{"endpoint":"fee-rate","mode":"no_query","case":"missing","response":{"method":"GET","url":"https://clob.polymarket.com/fee-rate","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"Invalid token id"}}},
|
||||
{"endpoint":"tick-size","mode":"no_query","case":"missing","response":{"method":"GET","url":"https://clob.polymarket.com/tick-size","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"Invalid token id"}}},
|
||||
{"endpoint":"neg-risk","mode":"no_query","case":"missing","response":{"method":"GET","url":"https://clob.polymarket.com/neg-risk","payload":null,"status":400,"date":"Fri, 04 Dec 2026 20:37:34 GMT","body":{"error":"Invalid token id"}}}
|
||||
]
|
||||
@@ -376,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。没有挂单变化时延续上次观测。窗口之外也追加最近一分钟的可用点;若与窗口最后一点重合,可出现重复时间戳。封盘后,曲线只返回请求窗口内、封盘之前的采样点。电竞、乒乓球和 SOL 涨跌盘的六个生产结果均符合这一规则。电竞负侧、胜侧的末点分别为 0.0005 和 0.9995,目录最终兑付为 0 和 1。旧库没有封盘记录时,最多采样到最后一笔非空盘口记录。生产采样时钟有秒级偏移,新盘首个采样延迟和长期保留仍待核验。V2 曲线使用成交与兑付数据。[已裁决生产样本](examples/public-closed-chart-history.json)
|
||||
本地用已经提交的盘口变更重建历史中点。到每个 UTC 采样边界,取该时刻之前(含该时刻)最近一次盘口;缺买侧用 0,缺卖侧用 1。没有挂单变化时延续上次观测。窗口之外也追加最近一分钟的可用点;若与窗口最后一点重合,可出现重复时间戳。模拟裁决后在裁决时刻以兑付值收尾。已裁决的旧盘若缺少裁决时间,只使用最后有时间记录的报价。升级旧库时从第一条可信报价开始,没有报价记录的资产从迁移时刻开始。生产采集存在秒级抖动,新盘首个采样的延迟、长期历史保留和裁决后取点尚未逐点验证。V2 的成交与兑付历史保留其独立数据源。
|
||||
|
||||
fidelity 以分钟为单位;省略或不大于零时按 1 分钟处理。相对窗口 1w 至少需要 5 分钟、1m 至少需要 10 分钟。显式起止时间最多相隔 15 天,多一秒即拒绝。单给 startTs 时读到当前;两个时间相等时仍可返回末点。合法但未上市的本地资产返回空数组。[HTTP 样例](examples/clob-http.http)
|
||||
|
||||
@@ -403,7 +403,11 @@ fidelity 以分钟为单位;省略或不大于零时按 1 分钟处理。相
|
||||
|
||||
本地 GET /markets 默认仅返回可接单的市场,GET /events 默认包含开放和已关闭事件。两者均支持 closed=true、false 或大小写不敏感的 any。市场列表中 any 必须与标识一起使用。每种受支持的市场标识最多传 100 个值。无标识使用 any 或无效 closed 值返回 HTTP 422。生产无筛选市场列表已读取;上述默认值和校验来自官方接口文档,组合筛选尚缺生产响应对照。[市场列表](https://docs.polymarket.com/api-reference/markets/list-markets) · [事件列表](https://docs.polymarket.com/api-reference/events/list-events) · [生产目录](https://gamma-api.polymarket.com/markets?limit=1)
|
||||
|
||||
在本地主题样例中只关闭 nvda-300 时,/markets 的结果仍有 nvda-200,/events 中的主题事件仍开放,事件详情中两个门槛盘都可见。关闭第二个门槛盘后,/events?closed=true 才返回这个事件。本地市场上架后默认 active 为 true,封盘仅更新交易状态。运营方可以通过 set_market_visibility 单独修改市场的 active 和 archived。事件仍使用原有的发布状态。封盘的事件聚合规则、默认每页 20 条和默认按数字 ID 降序都是本地约定。支持按 id、slug、市场 question 或事件 title 排序,逗号分隔多个字段;相同排序值用数字 ID 确定先后。每页使用独立读快照,分页之间如有上架或关闭,offset 可能移动。标签、链上标识、按交易量排序及官方游标分页仍待实现。
|
||||
在本地主题样例中只关闭 nvda-300 时,/markets 的结果仍有 nvda-200,/events 中的主题事件仍开放,事件详情中两个门槛盘都可见。关闭第二个门槛盘后,/events?closed=true 才返回这个事件。本地市场上架后默认 active 为 true,封盘仅更新交易状态。运营方可以通过 set_market_visibility 单独修改市场的 active 和 archived。事件仍使用原有的发布状态。封盘的事件聚合规则、默认每页 20 条和默认按数字 ID 降序都是本地约定。支持按 id、slug、市场 question 或事件 title 排序,逗号分隔多个字段;相同排序值用数字 ID 确定先后。每页使用独立读快照,分页之间如有上架或关闭,offset 可能移动。标签、链上标识和按交易量排序仍待实现。
|
||||
|
||||
#### Gamma 游标分页
|
||||
|
||||
2026-12-05 的生产样本中,市场列表前两页的 ID 为 559651、559652 和 559653、559654,事件列表为 2890、2891 和 2892、2893。筛选恰好返回一页时仍带游标,续页为空且省略 next_cursor。limit=0 使用 20,市场的 limit=101 截到 100。offset=0 可用,offset=1 返回 422。事件的 limit=51 无 gzip 返回 406,带 gzip 则取到 51 项。本地对齐这些边界,使用数据库签名游标并校验资源与显式排序字段。支持本地目录已有的 ID、slug、事件 title 和市场 question 排序,继续支持原有目录筛选条件,还可查询已登记的裁决问题及事件标题。生产接口的标签、交易量和流动性条件尚未接入。生产事件接口的无筛选 order=title 样本返回 500,本地按已保存标题排序。[市场接口](https://docs.polymarket.com/api-reference/markets/list-markets-keyset-pagination) · [事件接口](https://docs.polymarket.com/api-reference/events/list-events-keyset-pagination)
|
||||
|
||||
### 公开成交的 Data API 入口
|
||||
|
||||
@@ -466,12 +470,3 @@ 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)
|
||||
|
||||
### 已裁决资产的交易参数
|
||||
|
||||
生产样本中,活跃资产和两个已裁决资产都可通过路径或查询参数读取 tick-size、fee-rate 和 neg-risk。已裁决样本的基础费字段为 1000,步长为 0.001,这些值来自样本的市场配置。缺少 ID 或传空值时返回 400,非空但无法识别的 ID 返回 404,基础费接口使用自己的错误文案。本地路径接受百分号编码的结果标识。[生产响应](examples/public-token-settings.json) · [官方报价步长接口](https://docs.polymarket.com/api-reference/market-data/get-tick-size) · [官方基础费接口](https://docs.polymarket.com/api-reference/market-data/get-fee-rate)
|
||||
Reference in new issue
Block a user