Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa24ae75f9 | |||
| e6a914b381 | |||
| 31af9ad9cf |
+16
-1
@@ -221,10 +221,25 @@ 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
|
||||
```
|
||||
|
||||
### 批量读取 CLOB 历史曲线
|
||||
|
||||
`POST /batch-prices-history` 的请求体使用 markets、start_ts、end_ts、interval 和 fidelity。markets 中填结果资产 ID,去重后最多 20 个。绝对时间窗使用整数 Unix 秒。回执的 history 对象以资产 ID 为键,缺少观测的资产省略。
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant C as 图表客户端
|
||||
participant H as market_http.rs
|
||||
participant E as prices_history/legacy.rs
|
||||
C->>H: POST /batch-prices-history,选择多个结果资产
|
||||
H->>E: 校验请求体后提交批量查询
|
||||
E->>E: 从同一 SQLite 快照与时钟采样各条曲线
|
||||
E-->>C: history 对象,每个资产一条非空曲线
|
||||
```
|
||||
|
||||
### 发布后的裁决说明
|
||||
|
||||
```mermaid
|
||||
|
||||
@@ -144,9 +144,9 @@ fn book_prices(engine: &Mutex<Exchange>, rows: Vec<WirePrice>, single: bool) ->
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn batch_params<T: serde::de::DeserializeOwned>(
|
||||
fn json_body<T: serde::de::DeserializeOwned>(
|
||||
req: &mut Request,
|
||||
) -> std::result::Result<Vec<T>, (u16, &'static str)> {
|
||||
) -> std::result::Result<T, (u16, &'static str)> {
|
||||
if req.body_length().is_some_and(|n| n as u64 > MAX_BODY) {
|
||||
return Err((413, "Request body too large"));
|
||||
}
|
||||
@@ -387,6 +387,25 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
}
|
||||
}
|
||||
(&Method::Get, "/market-clarifications") => clarifications(engine, params),
|
||||
(&Method::Post, "/batch-prices-history") => {
|
||||
match json_body::<exchange::BatchClobHistoryQuery>(&mut req) {
|
||||
Ok(query) => {
|
||||
let result = engine
|
||||
.lock()
|
||||
.map_err(|_| HistoryError::Unavailable)
|
||||
.and_then(|exchange| exchange.batch_clob_price_history(query));
|
||||
match result {
|
||||
Ok(history) => Ok(history),
|
||||
Err(HistoryError::Invalid(message)) => {
|
||||
return send(req, 400, json!({"error":message}), None)
|
||||
}
|
||||
Err(HistoryError::Unavailable) => Err((500, "Internal server error")),
|
||||
}
|
||||
}
|
||||
Err((400, _)) => Err((400, "invalid request body")),
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
}
|
||||
(&Method::Get, "/prices-history") => {
|
||||
let result = serde_urlencoded::from_str::<exchange::ClobHistoryQuery>(params)
|
||||
.map_err(|_| HistoryError::Invalid("invalid query parameters".into()))
|
||||
@@ -408,7 +427,7 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
.map_err(|_| (400, "Invalid token id"))
|
||||
.and_then(|p| book_prices(engine, vec![p], true)),
|
||||
(&Method::Post, "/prices") => {
|
||||
batch_params::<WirePrice>(&mut req).and_then(|rows| book_prices(engine, rows, false))
|
||||
json_body::<Vec<WirePrice>>(&mut req).and_then(|rows| book_prices(engine, rows, false))
|
||||
}
|
||||
(&Method::Get, "/prices") => Err((400, "Invalid payload")),
|
||||
(&Method::Get, "/spread" | "/midpoint") => {
|
||||
@@ -427,7 +446,7 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
} else {
|
||||
QuoteField::Midpoint
|
||||
};
|
||||
batch_params::<BookParam>(&mut req).and_then(|p| {
|
||||
json_body::<Vec<BookParam>>(&mut req).and_then(|p| {
|
||||
quote_response(
|
||||
engine,
|
||||
p.into_iter().map(|b| b.token_id).collect(),
|
||||
@@ -441,14 +460,14 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
.map_err(|_| (400, "Invalid token id"))
|
||||
.and_then(|p| query(engine, vec![p], true)),
|
||||
(&Method::Post, "/books") => {
|
||||
batch_params::<BookParam>(&mut req).and_then(|p| query(engine, p, false))
|
||||
json_body::<Vec<BookParam>>(&mut req).and_then(|p| query(engine, p, false))
|
||||
}
|
||||
(&Method::Get, "/last-trade-price") => serde_urlencoded::from_str::<BookParam>(params)
|
||||
.map_err(|_| (400, "Invalid token id"))
|
||||
.and_then(|p| last_prices(engine, vec![p.token_id], true)),
|
||||
(&Method::Get, "/last-trades-prices") => Err((400, "Invalid payload")),
|
||||
(&Method::Post, "/last-trades-prices") => {
|
||||
batch_params::<BookParam>(&mut req).and_then(|p| {
|
||||
json_body::<Vec<BookParam>>(&mut req).and_then(|p| {
|
||||
last_prices(
|
||||
engine,
|
||||
p.into_iter().map(|item| item.token_id).collect(),
|
||||
@@ -480,7 +499,7 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
||||
allow = Some("GET");
|
||||
Err((405, "Method not allowed"))
|
||||
}
|
||||
(_, "/books" | "/spreads") => {
|
||||
(_, "/books" | "/spreads" | "/batch-prices-history") => {
|
||||
allow = Some("POST");
|
||||
Err((405, "Method not allowed"))
|
||||
}
|
||||
@@ -741,6 +760,12 @@ mod tests {
|
||||
("GET","/prices-history?market=eb:YES:s&interval=1w&fidelity=4",String::new(),400,Some(json!({"error":"invalid filters: minimum 'fidelity' for '1w' range is 5"}))),
|
||||
("GET","/prices-history?market=eb:YES:s&startTs=100&endTs=1296101",String::new(),400,Some(json!({"error":"invalid filters: 'startTs' and 'endTs' interval is too long"}))),
|
||||
("POST","/prices-history","{}".into(),405,None),
|
||||
("POST","/batch-prices-history",json!({"markets":["eb:YES:missing","123"],"start_ts":100,"end_ts":200}).to_string(),200,Some(json!({"history":{}}))),
|
||||
("POST","/batch-prices-history",json!({"markets":vec!["123";21],"interval":"1h"}).to_string(),200,Some(json!({"history":{}}))),
|
||||
("POST","/batch-prices-history",json!({"markets":(0..21).map(|i|i.to_string()).collect::<Vec<_>>(),"interval":"1h"}).to_string(),400,Some(json!({"error":"invalid filters: 'markets' exceeds maximum of 20"}))),
|
||||
("POST","/batch-prices-history",json!({"markets":[],"interval":"1h"}).to_string(),400,Some(json!({"error":"invalid filters: 'markets' is mandatory and must not be empty"}))),
|
||||
("POST","/batch-prices-history",json!({"markets":["123"],"start_ts":1.5,"end_ts":200}).to_string(),400,Some(json!({"error":"invalid request body"}))),
|
||||
("GET","/batch-prices-history",String::new(),405,None),
|
||||
("GET","/price?token_id=eb:YES:mid-example&side=BUY",String::new(),200,Some(json!({"price":"0.08"}))),
|
||||
("GET","/price?token_id=eb:YES:mid-example&side=SELL",String::new(),200,Some(json!({"price":"0.09"}))),
|
||||
("GET","/price?token_id=eb:YES:one&side=SELL",String::new(),200,Some(json!({"price":"1"}))),
|
||||
|
||||
@@ -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,11 +1145,13 @@ 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 为十进制数
|
||||
```
|
||||
|
||||
单资产与批量 CLOB 查询都通过 `prices_history/legacy.rs` 选择时间窗,复用 `legacy.sql`。同一批次只取一次数据库时钟,所有资产在同一个读事务内采样。封盘曲线沿用单查的截止时间,空曲线从批量响应中省略。
|
||||
|
||||
### 裁决规则的补充公告
|
||||
|
||||
```mermaid
|
||||
|
||||
@@ -55,7 +55,7 @@ pub use gamma_list::DirectoryResource;
|
||||
pub use open_interest::InterestQuery;
|
||||
pub use portfolio::http::ValueQuery;
|
||||
pub use prices_history::http::HistoryQuery;
|
||||
pub use prices_history::legacy::ClobHistoryQuery;
|
||||
pub use prices_history::legacy::{BatchClobHistoryQuery, ClobHistoryQuery};
|
||||
pub use public_trades::http::TradeQuery;
|
||||
pub use quotes::{PriceQueryError, PriceRequest, PriceSide};
|
||||
pub use resolution::http::ResolutionQuery;
|
||||
@@ -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_listed')",
|
||||
"SELECT EXISTS(SELECT 1 FROM sqlite_schema WHERE type='trigger' AND name='chart_market_closed')",
|
||||
[], |r| r.get(0),
|
||||
)?;
|
||||
if !history_ready {
|
||||
|
||||
@@ -12,4 +12,12 @@ END;
|
||||
INSERT OR IGNORE INTO chart_origins
|
||||
SELECT id,COALESCE((SELECT MIN(at_ms) FROM quote_events WHERE market=m.id),
|
||||
CAST(unixepoch('subsec')*1000 AS INTEGER)) FROM markets m;
|
||||
CREATE TABLE IF NOT EXISTS chart_closures (
|
||||
market TEXT PRIMARY KEY REFERENCES markets,
|
||||
at_ms INTEGER NOT NULL
|
||||
);
|
||||
CREATE TRIGGER IF NOT EXISTS chart_market_closed AFTER UPDATE OF phase ON markets
|
||||
WHEN NEW.phase='closed' AND OLD.phase<>'closed' BEGIN
|
||||
INSERT INTO chart_closures VALUES(NEW.id,CAST(unixepoch('subsec')*1000 AS INTEGER));
|
||||
END;
|
||||
COMMIT;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::{assets, inventory, Exchange, HistoryError};
|
||||
use rusqlite::params;
|
||||
use rusqlite::{params, Connection, Statement, TransactionBehavior};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{json, Map, Value};
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ClobHistoryQuery {
|
||||
@@ -14,36 +15,61 @@ pub struct ClobHistoryQuery {
|
||||
fidelity: Option<i64>,
|
||||
}
|
||||
|
||||
impl ClobHistoryQuery {
|
||||
fn window(&self, now: i64) -> Result<(i64, i64, i64), HistoryError> {
|
||||
let invalid = |reason: &str| HistoryError::Invalid(format!("invalid filters: {reason}"));
|
||||
for n in [self.start, self.end].into_iter().flatten() {
|
||||
if !n.is_finite() || !(0.0..=f64::from(u32::MAX)).contains(&n) {
|
||||
return Err(invalid("invalid timestamp"));
|
||||
}
|
||||
}
|
||||
let start = self.start.unwrap_or(0.0);
|
||||
let end = self.end.unwrap_or(0.0);
|
||||
if end > 0.0 {
|
||||
if start > end {
|
||||
return Err(invalid(
|
||||
"invalid time component, 'startTs' can't be older than 'endTs'",
|
||||
));
|
||||
}
|
||||
if end - start > (15 * super::DAY) as f64 {
|
||||
return Err(invalid("'startTs' and 'endTs' interval is too long"));
|
||||
}
|
||||
}
|
||||
let minutes = self.fidelity.unwrap_or(1).max(1);
|
||||
#[derive(Deserialize)]
|
||||
pub struct BatchClobHistoryQuery {
|
||||
markets: Option<Vec<String>>,
|
||||
start_ts: Option<i64>,
|
||||
end_ts: Option<i64>,
|
||||
interval: Option<String>,
|
||||
fidelity: Option<i64>,
|
||||
}
|
||||
|
||||
struct Window {
|
||||
start: i64,
|
||||
end: i64,
|
||||
width: i64,
|
||||
}
|
||||
|
||||
fn invalid(reason: &str) -> HistoryError {
|
||||
HistoryError::Invalid(format!("invalid filters: {reason}"))
|
||||
}
|
||||
|
||||
fn validate_absolute(reversed: bool, too_long: bool) -> Result<(), HistoryError> {
|
||||
if reversed {
|
||||
return Err(invalid(
|
||||
"invalid time component, 'startTs' can't be older than 'endTs'",
|
||||
));
|
||||
}
|
||||
if too_long {
|
||||
return Err(invalid("'startTs' and 'endTs' interval is too long"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl Window {
|
||||
fn new(
|
||||
start: Option<i64>,
|
||||
end: Option<i64>,
|
||||
interval: Option<&str>,
|
||||
fidelity: Option<i64>,
|
||||
now: i64,
|
||||
) -> Result<Self, HistoryError> {
|
||||
let minutes = fidelity.unwrap_or(1).max(1);
|
||||
let width = minutes.min(i64::from(u32::MAX)) * 60_000;
|
||||
if let Some(interval) = self.interval.as_deref() {
|
||||
if let Some(interval) = interval {
|
||||
let (span, minimum) = match interval {
|
||||
"1h" => (3600, 1),
|
||||
"6h" => (21600, 1),
|
||||
"1d" => (super::DAY, 1),
|
||||
"1w" => (7 * super::DAY, 5),
|
||||
"1m" => (30 * super::DAY, 10),
|
||||
"max" | "all" => return Ok((0, now, width)),
|
||||
"max" | "all" => {
|
||||
return Ok(Self {
|
||||
start: 0,
|
||||
end: now,
|
||||
width,
|
||||
})
|
||||
}
|
||||
_ => return Err(invalid(
|
||||
"the 'interval' value is unknown. Known values: '1m', '1w', '1d', '6h', '1h'",
|
||||
)),
|
||||
@@ -53,22 +79,82 @@ impl ClobHistoryQuery {
|
||||
"minimum 'fidelity' for '{interval}' range is {minimum}"
|
||||
)));
|
||||
}
|
||||
return Ok(((now - span * 1000).max(0), now, width));
|
||||
return Ok(Self {
|
||||
start: (now - span * 1000).max(0),
|
||||
end: now,
|
||||
width,
|
||||
});
|
||||
}
|
||||
if start == 0.0 && end == 0.0 {
|
||||
if start.is_none() && end.is_none() {
|
||||
return Err(invalid(
|
||||
"the time component is mandatory, please use 'startTs' and 'endTs' or 'interval'",
|
||||
));
|
||||
}
|
||||
Ok((
|
||||
boundary_ms(start, f64::ceil),
|
||||
if end == 0.0 {
|
||||
now
|
||||
} else {
|
||||
boundary_ms(end, f64::floor)
|
||||
},
|
||||
Ok(Self {
|
||||
start: start.unwrap_or(0),
|
||||
end: end.unwrap_or(now),
|
||||
width,
|
||||
))
|
||||
})
|
||||
}
|
||||
|
||||
fn read(
|
||||
&self,
|
||||
stmt: &mut Statement<'_>,
|
||||
market: &str,
|
||||
outcome: &str,
|
||||
now: i64,
|
||||
) -> rusqlite::Result<Vec<Value>> {
|
||||
stmt.query_map(
|
||||
params![market, outcome, self.start, self.end, self.width, now],
|
||||
|r| {
|
||||
let timestamp: i64 = r.get(0)?;
|
||||
let micros: i64 = r.get(1)?;
|
||||
Ok(json!({"t":timestamp,"p":inventory::decimal(micros.into(), inventory::UNIT)}))
|
||||
},
|
||||
)?
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl ClobHistoryQuery {
|
||||
fn window(&self, now: i64) -> Result<Window, HistoryError> {
|
||||
for n in [self.start, self.end].into_iter().flatten() {
|
||||
if !n.is_finite() || !(0.0..=f64::from(u32::MAX)).contains(&n) {
|
||||
return Err(invalid("invalid timestamp"));
|
||||
}
|
||||
}
|
||||
let start = self.start.unwrap_or(0.0);
|
||||
let end = self.end.unwrap_or(0.0);
|
||||
if end > 0.0 {
|
||||
validate_absolute(start > end, end - start > (15 * super::DAY) as f64)?;
|
||||
}
|
||||
Window::new(
|
||||
(start != 0.0).then(|| boundary_ms(start, f64::ceil)),
|
||||
(end != 0.0).then(|| boundary_ms(end, f64::floor)),
|
||||
self.interval.as_deref(),
|
||||
self.fidelity,
|
||||
now,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl BatchClobHistoryQuery {
|
||||
fn window(&self, now: i64) -> Result<Window, HistoryError> {
|
||||
let start = self.start_ts.unwrap_or(0);
|
||||
let end = self.end_ts.unwrap_or(0);
|
||||
if end > 0 {
|
||||
validate_absolute(
|
||||
start > end,
|
||||
i128::from(end) - i128::from(start) > i128::from(15 * super::DAY),
|
||||
)?;
|
||||
}
|
||||
Window::new(
|
||||
(start != 0).then(|| start.saturating_mul(1000)),
|
||||
(end != 0).then(|| end.saturating_mul(1000)),
|
||||
self.interval.as_deref(),
|
||||
self.fidelity,
|
||||
now,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,28 +170,64 @@ fn boundary_ms(seconds: f64, round: fn(f64) -> f64) -> i64 {
|
||||
}
|
||||
}
|
||||
|
||||
fn snapshot_time(db: &Connection) -> rusqlite::Result<i64> {
|
||||
db.query_row(
|
||||
"SELECT CAST(unixepoch('subsec') * 1000 AS INTEGER)",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)
|
||||
}
|
||||
|
||||
impl Exchange {
|
||||
pub fn clob_price_history(&self, query: ClobHistoryQuery) -> Result<Value, HistoryError> {
|
||||
let (outcome, market) = assets::parse_id(&query.market)
|
||||
.map_err(|_| HistoryError::Invalid("invalid market asset id".into()))?;
|
||||
let tx = crate::expiry::transaction(&self.db, rusqlite::TransactionBehavior::Deferred)
|
||||
let tx = crate::expiry::transaction(&self.db, TransactionBehavior::Deferred)
|
||||
.map_err(|_| HistoryError::Unavailable)?;
|
||||
let now: i64 = tx.query_row(
|
||||
"SELECT CAST(unixepoch('subsec') * 1000 AS INTEGER)",
|
||||
[],
|
||||
|r| r.get(0),
|
||||
)?;
|
||||
let (start, end, width) = query.window(now)?;
|
||||
let now = snapshot_time(&tx)?;
|
||||
let window = query.window(now)?;
|
||||
let points = {
|
||||
let mut stmt = tx.prepare_cached(include_str!("legacy.sql"))?;
|
||||
let rows = stmt.query_map(params![market, outcome, start, end, width, now], |r| {
|
||||
let timestamp: i64 = r.get(0)?;
|
||||
let micros: i64 = r.get(1)?;
|
||||
Ok(json!({"t":timestamp,"p":inventory::decimal(micros.into(), inventory::UNIT)}))
|
||||
})?;
|
||||
rows.collect::<rusqlite::Result<Vec<_>>>()?
|
||||
window.read(&mut stmt, market, outcome, now)?
|
||||
};
|
||||
tx.commit()?;
|
||||
Ok(json!({"history":points}))
|
||||
}
|
||||
|
||||
pub fn batch_clob_price_history(
|
||||
&self,
|
||||
query: BatchClobHistoryQuery,
|
||||
) -> Result<Value, HistoryError> {
|
||||
let tokens: BTreeSet<_> = query
|
||||
.markets
|
||||
.iter()
|
||||
.flatten()
|
||||
.filter(|token| !token.is_empty())
|
||||
.collect();
|
||||
if tokens.is_empty() {
|
||||
return Err(invalid("'markets' is mandatory and must not be empty"));
|
||||
}
|
||||
if tokens.len() > 20 {
|
||||
return Err(invalid("'markets' exceeds maximum of 20"));
|
||||
}
|
||||
let tx = crate::expiry::transaction(&self.db, TransactionBehavior::Deferred)
|
||||
.map_err(|_| HistoryError::Unavailable)?;
|
||||
let now = snapshot_time(&tx)?;
|
||||
let window = query.window(now)?;
|
||||
let mut history = Map::new();
|
||||
{
|
||||
let mut stmt = tx.prepare_cached(include_str!("legacy.sql"))?;
|
||||
for token in tokens {
|
||||
let Ok((outcome, market)) = assets::parse_id(token) else {
|
||||
continue;
|
||||
};
|
||||
let points = window.read(&mut stmt, market, outcome, now)?;
|
||||
if !points.is_empty() {
|
||||
history.insert(token.to_string(), Value::Array(points));
|
||||
}
|
||||
}
|
||||
}
|
||||
tx.commit()?;
|
||||
Ok(json!({"history":history}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
-- The local sampler uses a UTC minute grid. The venue's collector has clock jitter.
|
||||
WITH RECURSIVE horizon AS (
|
||||
SELECT (SELECT at_ms FROM chart_origins WHERE market=?1) AS first_ms,
|
||||
(SELECT at_ms FROM price_settlements WHERE market=?1) AS resolved_ms,
|
||||
(SELECT winner FROM price_settlements WHERE market=?1) AS winner,
|
||||
(SELECT phase FROM markets WHERE id=?1) AS phase
|
||||
(SELECT at_ms FROM chart_closures WHERE market=?1) AS closed_ms,
|
||||
(SELECT phase IN ('closed','resolved') FROM markets WHERE id=?1) AS closed
|
||||
), bounds AS (
|
||||
SELECT first_ms, resolved_ms, winner,
|
||||
CASE WHEN phase='resolved' THEN COALESCE(resolved_ms,
|
||||
(SELECT MAX(at_ms) FROM quote_events WHERE market=?1))
|
||||
ELSE ?6/60000*60000 END AS last_ms
|
||||
SELECT first_ms, closed,
|
||||
CASE WHEN NOT closed THEN ?6/60000*60000
|
||||
WHEN closed_ms IS NOT NULL THEN closed_ms-1
|
||||
-- Old closed markets lack the close time. Use the last
|
||||
-- recorded nonempty quote and exclude the closing clear.
|
||||
ELSE (SELECT MAX(at_ms) FROM quote_events WHERE market=?1
|
||||
AND (yes_bid IS NOT NULL OR yes_ask IS NOT NULL)) END AS last_ms
|
||||
FROM horizon
|
||||
), grid(ms) AS (
|
||||
SELECT ((MAX(?3,first_ms)+?5-1)/?5)*?5 FROM bounds
|
||||
@@ -19,14 +21,12 @@ WITH RECURSIVE horizon AS (
|
||||
), points(ms,tail) AS (
|
||||
SELECT ms,0 FROM grid
|
||||
UNION ALL
|
||||
SELECT last_ms,1 FROM bounds WHERE resolved_ms IS NOT NULL OR first_ms<=last_ms
|
||||
SELECT last_ms,1 FROM bounds WHERE NOT closed AND first_ms<=last_ms
|
||||
)
|
||||
SELECT points.ms/1000,
|
||||
CASE WHEN points.ms=b.resolved_ms THEN
|
||||
CASE WHEN b.winner='VOID' THEN 500000 WHEN b.winner=?2 THEN 1000000 ELSE 0 END
|
||||
WHEN ?2='YES' THEN (COALESCE(q.yes_bid,0)+COALESCE(q.yes_ask,10000))*50
|
||||
CASE WHEN ?2='YES' THEN (COALESCE(q.yes_bid,0)+COALESCE(q.yes_ask,10000))*50
|
||||
ELSE 1000000-(COALESCE(q.yes_bid,0)+COALESCE(q.yes_ask,10000))*50 END
|
||||
FROM points CROSS JOIN bounds b
|
||||
FROM points
|
||||
LEFT JOIN quote_events q ON q.seq=(
|
||||
SELECT seq FROM quote_events WHERE market=?1 AND at_ms<=points.ms
|
||||
ORDER BY at_ms DESC,seq DESC LIMIT 1
|
||||
|
||||
@@ -1550,23 +1550,45 @@ fn legacy_history_samples_the_book_without_fills_and_appends_the_latest_mark() {
|
||||
);
|
||||
assert_eq!(points[3]["p"], 0.085);
|
||||
assert!(points[3]["t"].as_i64().unwrap() > 240);
|
||||
let batch = |e: &Exchange, start, end| {
|
||||
e.batch_clob_price_history(serde_json::from_value(json!({
|
||||
"markets":["eb:YES:mid-example","eb:NO:mid-example","123","eb:YES:missing","eb:YES:mid-example"],
|
||||
"start_ts":start, "end_ts":end, "fidelity":1
|
||||
})).unwrap()).unwrap()
|
||||
};
|
||||
let open = batch(&exchange, 120, 240);
|
||||
let yes = open["history"]["eb:YES:mid-example"].as_array().unwrap();
|
||||
let no = open["history"]["eb:NO:mid-example"].as_array().unwrap();
|
||||
assert_eq!(&yes[..3], &points[..3]);
|
||||
assert_eq!(yes[3]["t"], no[3]["t"]);
|
||||
assert_eq!(no[3]["p"], 0.915);
|
||||
assert_eq!(open["history"].as_object().unwrap().len(), 2);
|
||||
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!(batch(&reopened, 273, 400), json!({"history":{}}));
|
||||
let closed = batch(&reopened, 181, 400);
|
||||
assert_eq!(closed["history"]["eb:NO:mid-example"], json!(before_close));
|
||||
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})]
|
||||
closed["history"]["eb:YES:mid-example"],
|
||||
json!([{"t":240,"p":0.085}])
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
{
|
||||
"mixed_window": {
|
||||
"method": "POST",
|
||||
"url": "https://clob.polymarket.com/batch-prices-history",
|
||||
"request": {
|
||||
"markets": [
|
||||
"35090254409399344650860070211816464534198960801264823587796928404808383727584",
|
||||
"715035038973852440637533813088906197843594055254726475255007478722039119872",
|
||||
"35090254409399344650860070211816464534198960801264823587796928404808383727584",
|
||||
"123"
|
||||
],
|
||||
"start_ts": 1796285515,
|
||||
"end_ts": 1796285695
|
||||
},
|
||||
"date": "Sat, 05 Dec 2026 09:33:26 GMT",
|
||||
"status": 200,
|
||||
"body": {
|
||||
"history": {
|
||||
"35090254409399344650860070211816464534198960801264823587796928404808383727584": [
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.0375
|
||||
},
|
||||
{
|
||||
"t": 1796285600,
|
||||
"p": 0.0375
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.0375
|
||||
},
|
||||
{
|
||||
"t": 1796463190,
|
||||
"p": 0.0125
|
||||
}
|
||||
],
|
||||
"715035038973852440637533813088906197843594055254726475255007478722039119872": [
|
||||
{
|
||||
"t": 1796285539,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285599,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285653,
|
||||
"p": 0.5
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"before_listing": {
|
||||
"method": "POST",
|
||||
"url": "https://clob.polymarket.com/batch-prices-history",
|
||||
"request": {
|
||||
"markets": [
|
||||
"35090254409399344650860070211816464534198960801264823587796928404808383727584",
|
||||
"715035038973852440637533813088906197843594055254726475255007478722039119872",
|
||||
"123"
|
||||
],
|
||||
"start_ts": 100,
|
||||
"end_ts": 250
|
||||
},
|
||||
"date": "Sat, 05 Dec 2026 09:33:26 GMT",
|
||||
"status": 200,
|
||||
"body": {
|
||||
"history": {
|
||||
"35090254409399344650860070211816464534198960801264823587796928404808383727584": [
|
||||
{
|
||||
"t": 1796463190,
|
||||
"p": 0.0125
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"distinct_over_limit": {
|
||||
"method": "POST",
|
||||
"url": "https://clob.polymarket.com/batch-prices-history",
|
||||
"request": {
|
||||
"markets": [
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5",
|
||||
"6",
|
||||
"7",
|
||||
"8",
|
||||
"9",
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13",
|
||||
"14",
|
||||
"15",
|
||||
"16",
|
||||
"17",
|
||||
"18",
|
||||
"19",
|
||||
"20"
|
||||
],
|
||||
"interval": "1h"
|
||||
},
|
||||
"date": "Sat, 05 Dec 2026 09:33:26 GMT",
|
||||
"status": 400,
|
||||
"body": {
|
||||
"error": "invalid filters: 'markets' exceeds maximum of 20"
|
||||
}
|
||||
},
|
||||
"fractional_time": {
|
||||
"method": "POST",
|
||||
"url": "https://clob.polymarket.com/batch-prices-history",
|
||||
"request": {
|
||||
"markets": [
|
||||
"35090254409399344650860070211816464534198960801264823587796928404808383727584"
|
||||
],
|
||||
"start_ts": 1796285515.5,
|
||||
"end_ts": 1796285695
|
||||
},
|
||||
"date": "Sat, 05 Dec 2026 09:33:26 GMT",
|
||||
"status": 400,
|
||||
"body": {
|
||||
"error": "invalid request body"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,597 @@
|
||||
[
|
||||
{
|
||||
"catalog_url": "https://gamma-api.polymarket.com/markets?closed=true&limit=100&order=closedTime&ascending=false",
|
||||
"catalog": {
|
||||
"id": "7554899",
|
||||
"slug": "cs2-bb3-lgc-2026-12-03-game1-round-total-30pt5",
|
||||
"version": "v1",
|
||||
"conditionId": "0xdf04a0495b0a16dbce386acdc16d9aed19784db9888be53d150354b83b7c18b1",
|
||||
"closed": true,
|
||||
"closedTime": "2026-12-03 08:32:03.519799+00",
|
||||
"acceptingOrders": false,
|
||||
"umaResolutionStatus": "resolved",
|
||||
"outcomePrices": "[\"0\", \"1\"]",
|
||||
"outcomes": "[\"Over\", \"Under\"]",
|
||||
"positionIds": null,
|
||||
"clobTokenIds": "[\"73979342585906843441145134109923710004884703083095161594360108477170435492453\", \"78188826358032258311424545486331333398838521699262460256542567713692269401385\"]"
|
||||
},
|
||||
"sides": [
|
||||
{
|
||||
"asset": "73979342585906843441145134109923710004884703083095161594360108477170435492453",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=73979342585906843441145134109923710004884703083095161594360108477170435492453&startTs=1796284923&endTs=1796288523&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:56 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796285541,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796285655,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796285780,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796285889,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796286038,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796286155,
|
||||
"p": 0.1
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.005
|
||||
},
|
||||
{
|
||||
"t": 1796286383,
|
||||
"p": 0.0005
|
||||
},
|
||||
{
|
||||
"t": 1796286495,
|
||||
"p": 0.0005
|
||||
},
|
||||
{
|
||||
"t": 1796286646,
|
||||
"p": 0.0005
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=73979342585906843441145134109923710004884703083095161594360108477170435492453&startTs=1796290323&endTs=1796290623&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:56 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=73979342585906843441145134109923710004884703083095161594360108477170435492453&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:56 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"asset": "78188826358032258311424545486331333398838521699262460256542567713692269401385",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=78188826358032258311424545486331333398838521699262460256542567713692269401385&startTs=1796284923&endTs=1796288523&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:58 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796285780,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796285889,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796286037,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796286155,
|
||||
"p": 0.9
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.995
|
||||
},
|
||||
{
|
||||
"t": 1796286383,
|
||||
"p": 0.9995
|
||||
},
|
||||
{
|
||||
"t": 1796286495,
|
||||
"p": 0.9995
|
||||
},
|
||||
{
|
||||
"t": 1796286646,
|
||||
"p": 0.9995
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=78188826358032258311424545486331333398838521699262460256542567713692269401385&startTs=1796290323&endTs=1796290623&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:58 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=78188826358032258311424545486331333398838521699262460256542567713692269401385&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:58 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"catalog_url": "https://gamma-api.polymarket.com/markets?closed=true&limit=100&order=closedTime&ascending=false",
|
||||
"catalog": {
|
||||
"id": "7543472",
|
||||
"slug": "setkameua-anat-illia-2026-12-03",
|
||||
"version": "v2",
|
||||
"conditionId": "0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000",
|
||||
"closed": true,
|
||||
"closedTime": "2026-12-03 08:31:00.370625+00",
|
||||
"acceptingOrders": false,
|
||||
"umaResolutionStatus": null,
|
||||
"outcomePrices": "[\"1\", \"0\"]",
|
||||
"outcomes": "[\"Nikolenko Anatolii\", \"Fokin Illia\"]",
|
||||
"positionIds": [
|
||||
"759916398134244316868652908232832573045153963965173623897622651599218278400",
|
||||
"759916398134244316868652908232832573045153963965173623897622651599218278401"
|
||||
],
|
||||
"clobTokenIds": "[\"759916398134244316868652908232832573045153963965173623897622651599218278400\", \"759916398134244316868652908232832573045153963965173623897622651599218278401\"]"
|
||||
},
|
||||
"sides": [
|
||||
{
|
||||
"asset": "759916398134244316868652908232832573045153963965173623897622651599218278400",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278400&startTs=1796284860&endTs=1796288460&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:59 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796284969,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285059,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285176,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285310,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285335,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285416,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285779,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796285889,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286037,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286154,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286382,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286494,
|
||||
"p": 0.999
|
||||
},
|
||||
{
|
||||
"t": 1796286645,
|
||||
"p": 0.999
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278400&startTs=1796290260&endTs=1796290560&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:59 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278400&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:34:59 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"asset": "759916398134244316868652908232832573045153963965173623897622651599218278401",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278401&startTs=1796284860&endTs=1796288460&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:00 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796284969,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285059,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285176,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285310,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285335,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285416,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285779,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796285889,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286037,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286154,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286382,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286494,
|
||||
"p": 0.001
|
||||
},
|
||||
{
|
||||
"t": 1796286645,
|
||||
"p": 0.001
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278401&startTs=1796290260&endTs=1796290560&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:00 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=759916398134244316868652908232832573045153963965173623897622651599218278401&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:01 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"catalog_url": "https://gamma-api.polymarket.com/markets?closed=true&limit=100&order=closedTime&ascending=false",
|
||||
"catalog": {
|
||||
"id": "7528433",
|
||||
"slug": "sol-updown-15m-1796285700",
|
||||
"version": "v2",
|
||||
"conditionId": "0x0190f69570a8ebb0d5608f8f773ffc068b000000000000000000000000000000",
|
||||
"closed": true,
|
||||
"closedTime": "2026-12-03 08:30:28.231292+00",
|
||||
"acceptingOrders": false,
|
||||
"umaResolutionStatus": null,
|
||||
"outcomePrices": "[\"1\", \"0\"]",
|
||||
"outcomes": "[\"Up\", \"Down\"]",
|
||||
"positionIds": [
|
||||
"708440684409184214698552699176045036593002385654320616860038876849074339840",
|
||||
"708440684409184214698552699176045036593002385654320616860038876849074339841"
|
||||
],
|
||||
"clobTokenIds": "[\"708440684409184214698552699176045036593002385654320616860038876849074339840\", \"708440684409184214698552699176045036593002385654320616860038876849074339841\"]"
|
||||
},
|
||||
"sides": [
|
||||
{
|
||||
"asset": "708440684409184214698552699176045036593002385654320616860038876849074339840",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339840&startTs=1796284828&endTs=1796288428&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:02 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796284968,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285058,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285173,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285310,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285334,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285414,
|
||||
"p": 0.505
|
||||
},
|
||||
{
|
||||
"t": 1796285539,
|
||||
"p": 0.505
|
||||
},
|
||||
{
|
||||
"t": 1796285653,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285778,
|
||||
"p": 0.395
|
||||
},
|
||||
{
|
||||
"t": 1796285888,
|
||||
"p": 0.55
|
||||
},
|
||||
{
|
||||
"t": 1796286036,
|
||||
"p": 0.675
|
||||
},
|
||||
{
|
||||
"t": 1796286153,
|
||||
"p": 0.8
|
||||
},
|
||||
{
|
||||
"t": 1796286251,
|
||||
"p": 0.83
|
||||
},
|
||||
{
|
||||
"t": 1796286382,
|
||||
"p": 0.83
|
||||
},
|
||||
{
|
||||
"t": 1796286494,
|
||||
"p": 0.96
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339840&startTs=1796290228&endTs=1796290528&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:02 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339840&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:02 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"asset": "708440684409184214698552699176045036593002385654320616860038876849074339841",
|
||||
"around": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339841&startTs=1796284828&endTs=1796288428&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:03 GMT",
|
||||
"body": {
|
||||
"history": [
|
||||
{
|
||||
"t": 1796284969,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285059,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285176,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285310,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285335,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285416,
|
||||
"p": 0.495
|
||||
},
|
||||
{
|
||||
"t": 1796285540,
|
||||
"p": 0.495
|
||||
},
|
||||
{
|
||||
"t": 1796285654,
|
||||
"p": 0.5
|
||||
},
|
||||
{
|
||||
"t": 1796285779,
|
||||
"p": 0.605
|
||||
},
|
||||
{
|
||||
"t": 1796285888,
|
||||
"p": 0.455
|
||||
},
|
||||
{
|
||||
"t": 1796286036,
|
||||
"p": 0.335
|
||||
},
|
||||
{
|
||||
"t": 1796286154,
|
||||
"p": 0.205
|
||||
},
|
||||
{
|
||||
"t": 1796286252,
|
||||
"p": 0.17
|
||||
},
|
||||
{
|
||||
"t": 1796286382,
|
||||
"p": 0.175
|
||||
},
|
||||
{
|
||||
"t": 1796286494,
|
||||
"p": 0.08
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339841&startTs=1796290228&endTs=1796290528&fidelity=2",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:03 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
},
|
||||
"ancient": {
|
||||
"method": "GET",
|
||||
"url": "https://clob.polymarket.com/prices-history?market=708440684409184214698552699176045036593002385654320616860038876849074339841&startTs=120&endTs=245",
|
||||
"payload": null,
|
||||
"status": 200,
|
||||
"date": "Thu, 03 Dec 2026 08:35:04 GMT",
|
||||
"body": {
|
||||
"history": []
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
@@ -376,12 +376,16 @@ Polymarket 的单资产最近成交接口规定,无成交时返回价格字符
|
||||
|
||||
旧版 CLOB 客户端用 market 指定结果资产。单侧盘口的生产曲线末点为 0.0005,同批中点为 0.0005、最近成交为 0.001。一个近端成交记录为空的资产也有连续的 0.5 历史点。取早于上市的绝对区间时,有历史的资产仍返回最近可用点;新资产在中点已经可查时也可能返回空曲线。[生产请求和对照样本](examples/public-clob-history.json) · [CLOB OpenAPI](https://docs.polymarket.com/api-reference/markets/get-prices-history)
|
||||
|
||||
本地用已经提交的盘口变更重建历史中点。到每个 UTC 采样边界,取该时刻之前(含该时刻)最近一次盘口;缺买侧用 0,缺卖侧用 1。没有挂单变化时延续上次观测。窗口之外也追加最近一分钟的可用点;若与窗口最后一点重合,可出现重复时间戳。模拟裁决后在裁决时刻以兑付值收尾。已裁决的旧盘若缺少裁决时间,只使用最后有时间记录的报价。升级旧库时从第一条可信报价开始,没有报价记录的资产从迁移时刻开始。生产采集存在秒级抖动,新盘首个采样的延迟、长期历史保留和裁决后取点尚未逐点验证。V2 的成交与兑付历史保留其独立数据源。
|
||||
本地用已经提交的盘口变更重建历史中点。到每个 UTC 采样边界,取该时刻之前(含该时刻)最近一次盘口;缺买侧用 0,缺卖侧用 1。没有挂单变化时延续上次观测。窗口之外也追加最近一分钟的可用点;若与窗口最后一点重合,可出现重复时间戳。封盘后,曲线只返回请求窗口内、封盘之前的采样点。电竞、乒乓球和 SOL 涨跌盘的六个生产结果均符合这一规则。电竞负侧、胜侧的末点分别为 0.0005 和 0.9995,目录最终兑付为 0 和 1。旧库没有封盘记录时,最多采样到最后一笔非空盘口记录。生产采样时钟有秒级偏移,新盘首个采样延迟和长期保留仍待核验。V2 曲线使用成交与兑付数据。[已裁决生产样本](examples/public-closed-chart-history.json)
|
||||
|
||||
fidelity 以分钟为单位;省略或不大于零时按 1 分钟处理。相对窗口 1w 至少需要 5 分钟、1m 至少需要 10 分钟。显式起止时间最多相隔 15 天,多一秒即拒绝。单给 startTs 时读到当前;两个时间相等时仍可返回末点。合法但未上市的本地资产返回空数组。[HTTP 样例](examples/clob-http.http)
|
||||
|
||||
官方 SDK 仓库有用户在同一已裁决资产上记录了两种结果:max 窗口按 60 分钟查询返回空,按 720 分钟查询有历史;后来该用户用显式起止时间取得更细数据。本地可返回已保存的全部历史。这项生产覆盖差异仍然存在。[原报告及后续复查](https://github.com/Polymarket/py-clob-client/issues/216)
|
||||
|
||||
#### CLOB 批量曲线
|
||||
|
||||
生产 `POST /batch-prices-history` 返回 history 映射。2026-12-05 样本中,重复资产合并,超过 20 个不同资产返回 400,未知资产省略。请求体的绝对时间使用 start_ts 和 end_ts,传小数得到 400。开放资产在历史窗口之外仍可附上最新点,封盘资产仅返回窗口截止前已有曲线。批量接口和单查复用本地采样 SQL,并在同一读事务内使用一个时钟。输入使用本地 Eventbook 资产 ID。生产采样抖动、保留期限及本地与外场资产映射仍需分别核对。[生产请求样本](examples/public-batch-clob-history.json) · [官方接口](https://docs.polymarket.com/api-reference/markets/get-batch-prices-history)
|
||||
|
||||
### 裁决规则补充公告与兑付权重
|
||||
|
||||
[本地样例](examples/clarifications.jsonl)先挂出 0.40 的 YES 买单。第一条说明保留挂单,第二条要求清盘,账户收回预留的 0.40。两条说明都按发布时间保留,初始规则仍可查看。模拟操作员可在盘前、连续交易或封盘待裁决期间发布公告。重复的请求 ID 返回原回执;之后新挂的订单不会因重放旧公告被撤。[官方规则澄清说明](https://docs.polymarket.com/concepts/resolution#clarifications)
|
||||
|
||||
Reference in New Issue
Block a user