Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c537944241 |
@@ -418,10 +418,8 @@ sequenceDiagram
|
|||||||
participant C as 客户端
|
participant C as 客户端
|
||||||
participant H as market_http.rs
|
participant H as market_http.rs
|
||||||
participant E as Exchange
|
participant E as Exchange
|
||||||
C->>H: GET /neg-risk?token_id=eb%3ANO%3Aa
|
C->>H: GET /neg-risk/{token_id} 或 /neg-risk?token_id=…
|
||||||
H->>E: 查询市场 a 的成员关系
|
H->>E: 查询市场 a 的成员关系
|
||||||
E-->>H: true
|
E-->>H: true
|
||||||
H-->>C: 200,neg_risk 为真
|
H-->>C: 200,neg_risk 为真
|
||||||
```
|
```
|
||||||
|
|
||||||
GET /v2/tokens 支持逗号分隔的资产 ID 或条件及互斥组 ID。两个选择器择一,回执按资产关联市场、事件和裁决结果。
|
|
||||||
|
|||||||
@@ -200,9 +200,17 @@ fn token_setting(
|
|||||||
.token_id
|
.token_id
|
||||||
.into(),
|
.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 exchange = engine.lock().map_err(|_| (500, "Internal server error"))?;
|
||||||
let unavailable = |e| match e {
|
let unavailable = |e| match e {
|
||||||
exchange::MarketDataError::Invalid(_) => invalid,
|
exchange::MarketDataError::Invalid(_) => missing,
|
||||||
exchange::MarketDataError::Unavailable => (500, "Internal server error"),
|
exchange::MarketDataError::Unavailable => (500, "Internal server error"),
|
||||||
};
|
};
|
||||||
match name {
|
match name {
|
||||||
@@ -210,21 +218,21 @@ fn token_setting(
|
|||||||
let flag = exchange
|
let flag = exchange
|
||||||
.token_neg_risk(&token)
|
.token_neg_risk(&token)
|
||||||
.map_err(unavailable)?
|
.map_err(unavailable)?
|
||||||
.ok_or((404, "market not found"))?;
|
.ok_or(missing)?;
|
||||||
Ok(json!({"neg_risk":flag}))
|
Ok(json!({"neg_risk":flag}))
|
||||||
}
|
}
|
||||||
"fee-rate" => {
|
"fee-rate" => {
|
||||||
let fee = exchange
|
let fee = exchange
|
||||||
.base_fee_bps(&token)
|
.base_fee_bps(&token)
|
||||||
.map_err(unavailable)?
|
.map_err(unavailable)?
|
||||||
.ok_or((404, "fee rate not found for market"))?;
|
.ok_or(missing)?;
|
||||||
Ok(json!({"base_fee":fee}))
|
Ok(json!({"base_fee":fee}))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let tick = exchange
|
let tick = exchange
|
||||||
.minimum_tick_size(&token)
|
.minimum_tick_size(&token)
|
||||||
.map_err(unavailable)?
|
.map_err(unavailable)?
|
||||||
.ok_or((404, "market not found"))?;
|
.ok_or(missing)?;
|
||||||
Ok(json!({"minimum_tick_size":tick}))
|
Ok(json!({"minimum_tick_size":tick}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,12 +337,7 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
|||||||
if req.method() == &Method::Get
|
if req.method() == &Method::Get
|
||||||
&& matches!(
|
&& matches!(
|
||||||
path,
|
path,
|
||||||
"/v2/tokens"
|
"/v2/prices-history" | "/v2/trades" | "/v2/resolutions" | "/v2/value" | "/v2/oi"
|
||||||
| "/v2/prices-history"
|
|
||||||
| "/v2/trades"
|
|
||||||
| "/v2/resolutions"
|
|
||||||
| "/v2/value"
|
|
||||||
| "/v2/oi"
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
let (status, body) = data_page(path, params, engine);
|
let (status, body) = data_page(path, params, engine);
|
||||||
@@ -344,9 +347,8 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
|||||||
let (name, segment) = route
|
let (name, segment) = route
|
||||||
.split_once('/')
|
.split_once('/')
|
||||||
.map_or((route, None), |(name, id)| (name, Some(id)));
|
.map_or((route, None), |(name, id)| (name, Some(id)));
|
||||||
let is_setting = path == "/neg-risk"
|
let is_setting = matches!(name, "neg-risk" | "tick-size" | "fee-rate")
|
||||||
|| (matches!(name, "tick-size" | "fee-rate")
|
&& !segment.is_some_and(|id| id.contains('/'));
|
||||||
&& !segment.is_some_and(|id| id.contains('/')));
|
|
||||||
let lookup = path
|
let lookup = path
|
||||||
.strip_prefix('/')
|
.strip_prefix('/')
|
||||||
.and_then(|p| p.split_once('/'))
|
.and_then(|p| p.split_once('/'))
|
||||||
@@ -478,7 +480,6 @@ fn respond(mut req: Request, engine: &Mutex<Exchange>) -> std::io::Result<()> {
|
|||||||
| "/market-clarifications"
|
| "/market-clarifications"
|
||||||
| "/v2/oi"
|
| "/v2/oi"
|
||||||
| "/v2/value"
|
| "/v2/value"
|
||||||
| "/v2/tokens"
|
|
||||||
| "/v2/trades"
|
| "/v2/trades"
|
||||||
| "/v2/resolutions"
|
| "/v2/resolutions"
|
||||||
| "/v2/prices-history",
|
| "/v2/prices-history",
|
||||||
@@ -519,7 +520,6 @@ fn read_page<Q: serde::de::DeserializeOwned>(
|
|||||||
|
|
||||||
fn data_page(path: &str, params: &str, engine: &Mutex<Exchange>) -> (u16, Value) {
|
fn data_page(path: &str, params: &str, engine: &Mutex<Exchange>) -> (u16, Value) {
|
||||||
let page = match path {
|
let page = match path {
|
||||||
"/v2/tokens" => read_page(params, engine, Exchange::public_tokens),
|
|
||||||
"/v2/oi" => read_page(params, engine, Exchange::public_open_interest),
|
"/v2/oi" => read_page(params, engine, Exchange::public_open_interest),
|
||||||
"/v2/value" => read_page(params, engine, Exchange::public_portfolio_value),
|
"/v2/value" => read_page(params, engine, Exchange::public_portfolio_value),
|
||||||
"/v2/trades" => read_page(params, engine, Exchange::public_trade_feed),
|
"/v2/trades" => read_page(params, engine, Exchange::public_trade_feed),
|
||||||
@@ -532,10 +532,6 @@ fn data_page(path: &str, params: &str, engine: &Mutex<Exchange>) -> (u16, Value)
|
|||||||
400,
|
400,
|
||||||
json!({"code":"invalid_request","error":message,"retryable":false}),
|
json!({"code":"invalid_request","error":message,"retryable":false}),
|
||||||
),
|
),
|
||||||
Err(HistoryError::Unavailable) if path == "/v2/tokens" => (
|
|
||||||
503,
|
|
||||||
json!({"code":"unavailable","error":"token directory unavailable","retryable":true}),
|
|
||||||
),
|
|
||||||
Err(HistoryError::Unavailable) if path == "/v2/oi" => (
|
Err(HistoryError::Unavailable) if path == "/v2/oi" => (
|
||||||
503,
|
503,
|
||||||
json!({"code":"unavailable","error":"open interest unavailable","retryable":true}),
|
json!({"code":"unavailable","error":"open interest unavailable","retryable":true}),
|
||||||
@@ -628,6 +624,9 @@ mod tests {
|
|||||||
let lookup_info = json!({"mbf":0,"tbf":30,"fd":{"r":0.05,"e":1,"to":true},"gst":null,"nr":false,"rfqe":false,"ibce":false,"oas":0,"mos":0.01,"mts":0.0025,
|
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"}]});
|
"t":[{"o":"YES","t":"eb:YES:map+2/1"},{"o":"NO","t":"eb:NO:map+2/1"}]});
|
||||||
for command in [
|
for command in [
|
||||||
|
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":"fund","id":"v-fund","account":"unpriced-owner","cents":100}),
|
||||||
json!({"op":"list","id":"v-list","market":"unpriced","rules":"valuation fixture"}),
|
json!({"op":"list","id":"v-list","market":"unpriced","rules":"valuation fixture"}),
|
||||||
json!({"op":"split","id":"v-split","account":"unpriced-owner","market":"unpriced","qty":1}),
|
json!({"op":"split","id":"v-split","account":"unpriced-owner","market":"unpriced","qty":1}),
|
||||||
@@ -700,10 +699,6 @@ mod tests {
|
|||||||
assert_eq!(quoted["outcomePrices"], r#"["0.4","0.6"]"#);
|
assert_eq!(quoted["outcomePrices"], r#"["0.4","0.6"]"#);
|
||||||
let empty_trades = json!({"data":[],"pagination":{"limit":100,"offset":0,"has_more":false,"next_cursor":null}});
|
let empty_trades = json!({"data":[],"pagination":{"limit":100,"offset":0,"has_more":false,"next_cursor":null}});
|
||||||
let cases = [
|
let cases = [
|
||||||
("GET","/v2/tokens?token_ids=eb:NO:s,00123,eb:NO:s,eb:YES:s",String::new(),200,Some(db.public_tokens(serde_json::from_value(json!({"token_id":"eb:NO:s,123,eb:YES:s"})).unwrap()).unwrap())),
|
|
||||||
("GET","/v2/tokens?condition=s&token_id=eb:YES:s",String::new(),400,None),
|
|
||||||
("GET","/v2/tokens?token_id=00123,123",String::new(),200,Some(json!({"data":[]}))),
|
|
||||||
("POST","/v2/tokens",String::new(),405,None),
|
|
||||||
("GET","/v2/oi?conditionId=s,s",String::new(),200,Some(json!({"data":[{"condition_id":"s","value":0}]}))),
|
("GET","/v2/oi?conditionId=s,s",String::new(),200,Some(json!({"data":[{"condition_id":"s","value":0}]}))),
|
||||||
("GET","/v2/oi?condition_id=0x0000000000000000000000000000000000000000000000000000000000000001",String::new(),200,Some(json!({"data":[]}))),
|
("GET","/v2/oi?condition_id=0x0000000000000000000000000000000000000000000000000000000000000001",String::new(),200,Some(json!({"data":[]}))),
|
||||||
("GET","/v2/oi?condition=bad-hash",String::new(),400,Some(json!({"code":"invalid_request","error":"invalid condition: bad-hash","retryable":false}))),
|
("GET","/v2/oi?condition=bad-hash",String::new(),400,Some(json!({"code":"invalid_request","error":"invalid condition: bad-hash","retryable":false}))),
|
||||||
@@ -794,9 +789,17 @@ mod tests {
|
|||||||
("GET","/clob-markets/missing",String::new(),400,None),
|
("GET","/clob-markets/missing",String::new(),400,None),
|
||||||
("POST","/clob-markets/map+2%2F1","{}".into(),405,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",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%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=eb%3ANO%3Amissing",String::new(),404,None),
|
||||||
("GET","/neg-risk?token_id=bad",String::new(),400,None),
|
("GET","/neg-risk?token_id=bad",String::new(),404,Some(json!({"error":"market not found"}))),
|
||||||
("GET","/neg-risk",String::new(),400,None),
|
("GET","/neg-risk",String::new(),400,None),
|
||||||
("POST","/neg-risk",String::new(),405,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}))),
|
("GET","/fee-rate?token_id=eb%3AYES%3Amap%2B2%2F1",String::new(),200,Some(json!({"base_fee":30}))),
|
||||||
|
|||||||
@@ -1434,30 +1434,3 @@ sequenceDiagram
|
|||||||
E-->>C: 返回本次两侧销毁量和实付金额
|
E-->>C: 返回本次两侧销毁量和实付金额
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Data API 资产目录
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
flowchart LR
|
|
||||||
http["cli/market_http.rs"] --> directory["token_directory.rs"]
|
|
||||||
directory --> ids["assets.rs"]
|
|
||||||
directory --> sql["token_directory.sql"]
|
|
||||||
sql --> catalog["市场、事件目录和互斥组"]
|
|
||||||
```
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
sequenceDiagram
|
|
||||||
participant H as HTTP
|
|
||||||
participant E as public_tokens
|
|
||||||
participant D as SQLite
|
|
||||||
H->>E: 结果资产、市场条件或互斥组
|
|
||||||
E->>E: 校验选择器、合并重复值
|
|
||||||
E->>D: 同一快照读取目录、结果及裁决
|
|
||||||
D-->>E: 结果标签、互补资产、事件及兑付
|
|
||||||
E-->>H: 按请求顺序返回 data
|
|
||||||
```
|
|
||||||
|
|
||||||
`bind_polymarket_assets` 将完整协议配对绑定到已创建的本地市场。操作员用 zero_outcome 声明外场结果索引 0 对应本地 YES 或 NO。绑定和请求回执在同一事务提交。数字资产、外场条件和已绑定的结构条件可通过 GET /v2/tokens 反查;响应附带 local_asset_id。成交流程继续通过本地资产提交委托。
|
|
||||||
|
|
||||||
同一配对可携带 observed_at_ms 刷新外场状态。旧快照不会覆盖新状态,最终兑付冲突会回滚。
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ pub(crate) enum Command {
|
|||||||
micros: Option<i64>,
|
micros: Option<i64>,
|
||||||
},
|
},
|
||||||
Event(crate::catalog::Event),
|
Event(crate::catalog::Event),
|
||||||
#[serde(rename = "bind_polymarket_assets")]
|
|
||||||
BindPolymarketAssets(crate::token_aliases::Bind),
|
|
||||||
#[serde(rename = "reschedule_sports")]
|
#[serde(rename = "reschedule_sports")]
|
||||||
RescheduleSports {
|
RescheduleSports {
|
||||||
event: String,
|
event: String,
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ mod resident;
|
|||||||
mod resolution;
|
mod resolution;
|
||||||
mod tick_changes;
|
mod tick_changes;
|
||||||
mod tick_size;
|
mod tick_size;
|
||||||
mod token_aliases;
|
|
||||||
mod token_directory;
|
|
||||||
use resident::Books;
|
use resident::Books;
|
||||||
|
|
||||||
use anyhow::{ensure, Context, Result};
|
use anyhow::{ensure, Context, Result};
|
||||||
@@ -61,7 +59,6 @@ pub use prices_history::legacy::ClobHistoryQuery;
|
|||||||
pub use public_trades::http::TradeQuery;
|
pub use public_trades::http::TradeQuery;
|
||||||
pub use quotes::{PriceQueryError, PriceRequest, PriceSide};
|
pub use quotes::{PriceQueryError, PriceRequest, PriceSide};
|
||||||
pub use resolution::http::ResolutionQuery;
|
pub use resolution::http::ResolutionQuery;
|
||||||
pub use token_directory::TokenDirectoryQuery;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum MarketDataError {
|
pub enum MarketDataError {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ pub(crate) fn apply(
|
|||||||
request_id: &str,
|
request_id: &str,
|
||||||
) -> Result<Value> {
|
) -> Result<Value> {
|
||||||
match command {
|
match command {
|
||||||
Command::BindPolymarketAssets(binding) => binding.register(tx),
|
|
||||||
Command::Fund {
|
Command::Fund {
|
||||||
account,
|
account,
|
||||||
cents,
|
cents,
|
||||||
|
|||||||
@@ -327,29 +327,3 @@ CREATE TABLE IF NOT EXISTS trade_cursor_key (
|
|||||||
);
|
);
|
||||||
INSERT INTO trade_cursor_key(singleton,secret)
|
INSERT INTO trade_cursor_key(singleton,secret)
|
||||||
SELECT 1,randomblob(32) WHERE NOT EXISTS(SELECT 1 FROM trade_cursor_key);
|
SELECT 1,randomblob(32) WHERE NOT EXISTS(SELECT 1 FROM trade_cursor_key);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS polymarket_market_aliases (
|
|
||||||
condition_id TEXT PRIMARY KEY,
|
|
||||||
market TEXT NOT NULL UNIQUE REFERENCES markets(id),
|
|
||||||
zero_outcome TEXT NOT NULL CHECK(zero_outcome IN ('YES','NO'))
|
|
||||||
);
|
|
||||||
CREATE TABLE IF NOT EXISTS polymarket_token_aliases (
|
|
||||||
token_id TEXT PRIMARY KEY,
|
|
||||||
condition_id TEXT NOT NULL REFERENCES polymarket_market_aliases(condition_id),
|
|
||||||
module TEXT NOT NULL, structure TEXT, group_id TEXT, question INTEGER,
|
|
||||||
slot INTEGER NOT NULL CHECK(slot IN (0,1)),
|
|
||||||
observation TEXT NOT NULL CHECK(json_valid(observation)),
|
|
||||||
UNIQUE(condition_id,module,slot)
|
|
||||||
);
|
|
||||||
CREATE INDEX IF NOT EXISTS pm_alias_structures ON polymarket_token_aliases(structure);
|
|
||||||
CREATE INDEX IF NOT EXISTS pm_alias_groups ON polymarket_token_aliases(group_id,question);
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS pm_alias_structure_slots
|
|
||||||
ON polymarket_token_aliases(structure,slot) WHERE structure IS NOT NULL;
|
|
||||||
CREATE UNIQUE INDEX IF NOT EXISTS pm_alias_question_slots
|
|
||||||
ON polymarket_token_aliases(group_id,question,module,slot) WHERE group_id IS NOT NULL;
|
|
||||||
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS polymarket_token_observation_times (
|
|
||||||
token_id TEXT PRIMARY KEY REFERENCES polymarket_token_aliases(token_id),
|
|
||||||
observed_at_ms INTEGER NOT NULL CHECK(observed_at_ms>0)
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -1,373 +0,0 @@
|
|||||||
use crate::{
|
|
||||||
assets,
|
|
||||||
token_directory::{condition_hex, decimal_token},
|
|
||||||
validation::identifier,
|
|
||||||
};
|
|
||||||
use anyhow::{ensure, Context, Result};
|
|
||||||
use rusqlite::{params, OptionalExtension, Transaction};
|
|
||||||
use serde::Deserialize;
|
|
||||||
use serde_json::{json, Value};
|
|
||||||
use std::collections::BTreeMap;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub(crate) struct Bind {
|
|
||||||
market: String,
|
|
||||||
external_condition: String,
|
|
||||||
zero_outcome: String,
|
|
||||||
observed_at_ms: Option<i64>,
|
|
||||||
data: Vec<Value>,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Row<'a> {
|
|
||||||
token: &'a str,
|
|
||||||
opposite: &'a str,
|
|
||||||
module: &'a str,
|
|
||||||
structure: Option<&'a str>,
|
|
||||||
group: Option<&'a str>,
|
|
||||||
slot: usize,
|
|
||||||
question: Option<i64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn full_condition(id: &str) -> bool {
|
|
||||||
id.len() == 66 && condition_hex(id).as_deref() == Some(id)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn position_id(raw: &str) -> [u8; 32] {
|
|
||||||
// The decimal string has already been checked against uint256::MAX.
|
|
||||||
let mut bytes = [0u8; 32];
|
|
||||||
for digit in raw.bytes() {
|
|
||||||
let mut carry = u16::from(digit - b'0');
|
|
||||||
for byte in bytes.iter_mut().rev() {
|
|
||||||
let next = u16::from(*byte) * 10 + carry;
|
|
||||||
*byte = next as u8;
|
|
||||||
carry = next >> 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bytes
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Row<'a> {
|
|
||||||
fn read(row: &'a Value, condition: &str) -> Result<Self> {
|
|
||||||
let token = row["token_id"].as_str().context("token_id is required")?;
|
|
||||||
let opposite = row["opposite_token_id"]
|
|
||||||
.as_str()
|
|
||||||
.context("opposite_token_id is required")?;
|
|
||||||
ensure!(
|
|
||||||
decimal_token(token) == Some(token)
|
|
||||||
&& decimal_token(opposite) == Some(opposite)
|
|
||||||
&& token != opposite,
|
|
||||||
"invalid external outcome identifiers"
|
|
||||||
);
|
|
||||||
ensure!(
|
|
||||||
row["condition_id"] == condition,
|
|
||||||
"external condition mismatch"
|
|
||||||
);
|
|
||||||
let module = row["module"].as_str().context("module is required")?;
|
|
||||||
let slot = row["outcome_index"]
|
|
||||||
.as_u64()
|
|
||||||
.filter(|i| *i < 2)
|
|
||||||
.context("invalid outcome index")? as usize;
|
|
||||||
let structure = row["structural_condition_id"].as_str();
|
|
||||||
let group = row["neg_risk_market_id"].as_str();
|
|
||||||
let question = row["question_index"].as_i64();
|
|
||||||
ensure!(
|
|
||||||
group.is_some() == question.is_some()
|
|
||||||
&& group.is_none_or(full_condition)
|
|
||||||
&& question.is_none_or(|q| q >= 0),
|
|
||||||
"invalid negative-risk question reference"
|
|
||||||
);
|
|
||||||
match module {
|
|
||||||
"v1_ctf" => ensure!(
|
|
||||||
row["structural_condition_id"].is_null(),
|
|
||||||
"CTF has no structure ID"
|
|
||||||
),
|
|
||||||
"binary" | "neg_risk" => {
|
|
||||||
ensure!(
|
|
||||||
(module == "neg_risk") == group.is_some(),
|
|
||||||
"V2 module mismatch"
|
|
||||||
);
|
|
||||||
let bytes = position_id(token);
|
|
||||||
let other = position_id(opposite);
|
|
||||||
let mut expected = String::from("0x");
|
|
||||||
use std::fmt::Write;
|
|
||||||
for byte in &bytes[..31] {
|
|
||||||
write!(expected, "{byte:02x}")?;
|
|
||||||
}
|
|
||||||
expected.push_str("00");
|
|
||||||
ensure!(
|
|
||||||
structure == Some(expected.as_str())
|
|
||||||
&& usize::from(bytes[31]) == slot
|
|
||||||
&& bytes[..31] == other[..31]
|
|
||||||
&& usize::from(other[31]) == 1 - slot,
|
|
||||||
"V2 token does not encode the supplied condition and outcome"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
_ => anyhow::bail!("unsupported external token module"),
|
|
||||||
}
|
|
||||||
Ok(Self {
|
|
||||||
token,
|
|
||||||
opposite,
|
|
||||||
module,
|
|
||||||
structure,
|
|
||||||
group,
|
|
||||||
slot,
|
|
||||||
question,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Bind {
|
|
||||||
pub(crate) fn register(self, tx: &Transaction<'_>) -> Result<Value> {
|
|
||||||
identifier(&self.market)?;
|
|
||||||
ensure!(
|
|
||||||
self.observed_at_ms.is_none_or(|ms| ms > 0),
|
|
||||||
"invalid observation time"
|
|
||||||
);
|
|
||||||
ensure!(
|
|
||||||
matches!(self.zero_outcome.as_str(), "YES" | "NO"),
|
|
||||||
"zero_outcome must be YES or NO"
|
|
||||||
);
|
|
||||||
ensure!(
|
|
||||||
full_condition(&self.external_condition),
|
|
||||||
"expected a canonical external market condition"
|
|
||||||
);
|
|
||||||
ensure!(
|
|
||||||
(2..=4).contains(&self.data.len()),
|
|
||||||
"provide a complete outcome pair for each protocol"
|
|
||||||
);
|
|
||||||
let mut families = BTreeMap::new();
|
|
||||||
for value in &self.data {
|
|
||||||
let token = Row::read(value, &self.external_condition)?;
|
|
||||||
let slot = token.slot;
|
|
||||||
let pair = families.entry(token.module).or_insert_with(|| [None, None]);
|
|
||||||
ensure!(
|
|
||||||
pair[slot].replace(token).is_none(),
|
|
||||||
"repeated protocol outcome"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if self.observed_at_ms.is_some() {
|
|
||||||
let mut states = BTreeMap::new();
|
|
||||||
for value in &self.data {
|
|
||||||
let row = Row::read(value, &self.external_condition)?;
|
|
||||||
let state = SnapshotState::read(value)?;
|
|
||||||
let pair = states.entry(row.module).or_insert_with(|| [None, None]);
|
|
||||||
pair[row.slot] = Some(state);
|
|
||||||
}
|
|
||||||
for pair in states.values() {
|
|
||||||
let [Some(a), Some(b)] = pair else {
|
|
||||||
anyhow::bail!("incomplete protocol pair");
|
|
||||||
};
|
|
||||||
ensure!(
|
|
||||||
a.closed == b.closed && a.resolved == b.resolved,
|
|
||||||
"protocol pair has inconsistent lifecycle"
|
|
||||||
);
|
|
||||||
if let (Some(a), Some(b)) = (a.price, b.price) {
|
|
||||||
ensure!((a + b - 1.0).abs() <= 1e-9, "final payouts must sum to one");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let v2_count = families.keys().filter(|m| **m != "v1_ctf").count();
|
|
||||||
ensure!(v2_count <= 1, "multiple V2 protocols for the same market");
|
|
||||||
let mut group_ref = None;
|
|
||||||
for pair in families.values() {
|
|
||||||
let [Some(a), Some(b)] = pair else {
|
|
||||||
anyhow::bail!("incomplete protocol pair");
|
|
||||||
};
|
|
||||||
ensure!(
|
|
||||||
a.opposite == b.token
|
|
||||||
&& b.opposite == a.token
|
|
||||||
&& a.structure == b.structure
|
|
||||||
&& a.group == b.group
|
|
||||||
&& a.question == b.question,
|
|
||||||
"outcomes do not form one pair"
|
|
||||||
);
|
|
||||||
if let Some((group, question)) = group_ref {
|
|
||||||
ensure!(
|
|
||||||
(a.group, a.question) == (group, question),
|
|
||||||
"protocols identify different questions"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
group_ref = Some((a.group, a.question));
|
|
||||||
}
|
|
||||||
let listed: bool = tx.query_row(
|
|
||||||
"SELECT EXISTS(SELECT 1 FROM markets WHERE id=?1)",
|
|
||||||
[&self.market],
|
|
||||||
|r| r.get(0),
|
|
||||||
)?;
|
|
||||||
ensure!(listed, "unknown local market");
|
|
||||||
tx.execute("INSERT INTO polymarket_market_aliases VALUES(?1,?2,?3) ON CONFLICT(condition_id) DO NOTHING",
|
|
||||||
params![self.external_condition,self.market,self.zero_outcome])?;
|
|
||||||
let bound: (String, String) = tx.query_row(
|
|
||||||
"SELECT market,zero_outcome FROM polymarket_market_aliases WHERE condition_id=?1",
|
|
||||||
[&self.external_condition],
|
|
||||||
|r| Ok((r.get(0)?, r.get(1)?)),
|
|
||||||
)?;
|
|
||||||
ensure!(
|
|
||||||
bound == (self.market.clone(), self.zero_outcome.clone()),
|
|
||||||
"market condition already bound with different identity"
|
|
||||||
);
|
|
||||||
let current_group: Option<(Option<String>, Option<i64>)> = tx.query_row(
|
|
||||||
"SELECT group_id,question FROM polymarket_token_aliases WHERE condition_id=?1 LIMIT 1",
|
|
||||||
[&self.external_condition], |row| Ok((row.get(0)?,row.get(1)?)),
|
|
||||||
).optional()?;
|
|
||||||
if let (Some((stored_group, stored_question)), Some((group, question))) =
|
|
||||||
(current_group, group_ref)
|
|
||||||
{
|
|
||||||
ensure!(
|
|
||||||
(stored_group.as_deref(), stored_question) == (group, question),
|
|
||||||
"market already bound to a different question"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for value in &self.data {
|
|
||||||
let row = Row::read(value, &self.external_condition)?;
|
|
||||||
// Only retain fields exposed by the external directory.
|
|
||||||
let observation: serde_json::Map<_, _> = [
|
|
||||||
"token_id",
|
|
||||||
"condition_id",
|
|
||||||
"structural_condition_id",
|
|
||||||
"module",
|
|
||||||
"outcome_index",
|
|
||||||
"clob_index",
|
|
||||||
"outcome",
|
|
||||||
"opposite_token_id",
|
|
||||||
"resolved",
|
|
||||||
"final_price",
|
|
||||||
"title",
|
|
||||||
"market_slug",
|
|
||||||
"closed",
|
|
||||||
"neg_risk",
|
|
||||||
"neg_risk_market_id",
|
|
||||||
"question_index",
|
|
||||||
"event_id",
|
|
||||||
"event_slug",
|
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
.map(|key| (key.to_owned(), value[key].clone()))
|
|
||||||
.collect();
|
|
||||||
let observation = Value::Object(observation);
|
|
||||||
tx.execute(
|
|
||||||
"INSERT INTO polymarket_token_aliases VALUES(?1,?2,?3,?4,?5,?6,?7,?8)
|
|
||||||
ON CONFLICT(token_id) DO NOTHING",
|
|
||||||
params![
|
|
||||||
row.token,
|
|
||||||
self.external_condition,
|
|
||||||
row.module,
|
|
||||||
row.structure,
|
|
||||||
row.group,
|
|
||||||
row.question,
|
|
||||||
row.slot as i64,
|
|
||||||
observation.to_string()
|
|
||||||
],
|
|
||||||
)?;
|
|
||||||
let observed: Option<String> = tx
|
|
||||||
.query_row(
|
|
||||||
"SELECT observation FROM polymarket_token_aliases WHERE token_id=?1",
|
|
||||||
[row.token],
|
|
||||||
|r| r.get(0),
|
|
||||||
)
|
|
||||||
.optional()?;
|
|
||||||
let prior: Value = serde_json::from_str(&observed.context("missing stored token")?)?;
|
|
||||||
let prior_identity = Row::read(&prior, &self.external_condition)?;
|
|
||||||
ensure!(
|
|
||||||
prior_identity.module == row.module
|
|
||||||
&& prior_identity.structure == row.structure
|
|
||||||
&& prior_identity.slot == row.slot
|
|
||||||
&& prior_identity.group == row.group
|
|
||||||
&& prior_identity.question == row.question
|
|
||||||
&& prior_identity.opposite == row.opposite,
|
|
||||||
"token already bound with different identity"
|
|
||||||
);
|
|
||||||
if let Some(observed_at_ms) = self.observed_at_ms {
|
|
||||||
refresh(tx, row.token, prior, &observation, observed_at_ms)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(
|
|
||||||
json!({"market":self.market,"external_condition":self.external_condition,
|
|
||||||
"zero_asset_id":assets::id(&self.market,&self.zero_outcome),"tokens":self.data.len()}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct SnapshotState {
|
|
||||||
closed: bool,
|
|
||||||
resolved: bool,
|
|
||||||
price: Option<f64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SnapshotState {
|
|
||||||
fn read(data: &Value) -> Result<Self> {
|
|
||||||
let closed = data["closed"]
|
|
||||||
.as_bool()
|
|
||||||
.context("closed must be a boolean")?;
|
|
||||||
let resolved = data["resolved"]
|
|
||||||
.as_bool()
|
|
||||||
.context("resolved must be a boolean")?;
|
|
||||||
let price = data["final_price"].as_f64();
|
|
||||||
if resolved {
|
|
||||||
ensure!(
|
|
||||||
closed && price.is_some_and(|p| (0.0..=1.0).contains(&p)),
|
|
||||||
"invalid final payout"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
ensure!(
|
|
||||||
data["final_price"].is_null(),
|
|
||||||
"unresolved asset has a final payout"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Ok(Self {
|
|
||||||
closed,
|
|
||||||
resolved,
|
|
||||||
price,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const LIVE_FIELDS: &[&str] = &["closed", "resolved", "final_price", "outcome"];
|
|
||||||
|
|
||||||
fn refresh(
|
|
||||||
tx: &Transaction<'_>,
|
|
||||||
token: &str,
|
|
||||||
mut prior: Value,
|
|
||||||
incoming: &Value,
|
|
||||||
observed_at_ms: i64,
|
|
||||||
) -> Result<()> {
|
|
||||||
let last: Option<i64> = tx
|
|
||||||
.query_row(
|
|
||||||
"SELECT observed_at_ms FROM polymarket_token_observation_times WHERE token_id=?1",
|
|
||||||
[token],
|
|
||||||
|r| r.get(0),
|
|
||||||
)
|
|
||||||
.optional()?;
|
|
||||||
if let Some(last) = last {
|
|
||||||
if observed_at_ms < last {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
if observed_at_ms == last {
|
|
||||||
ensure!(
|
|
||||||
LIVE_FIELDS.iter().all(|&key| prior[key] == incoming[key]),
|
|
||||||
"conflicting observations at the same time"
|
|
||||||
);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if prior["resolved"] == true {
|
|
||||||
ensure!(
|
|
||||||
incoming["resolved"] == true
|
|
||||||
&& prior["final_price"].as_f64() == incoming["final_price"].as_f64(),
|
|
||||||
"observation contradicts a recorded final payout"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
for &key in LIVE_FIELDS {
|
|
||||||
prior[key] = incoming[key].clone();
|
|
||||||
}
|
|
||||||
tx.execute(
|
|
||||||
"UPDATE polymarket_token_aliases SET observation=?1 WHERE token_id=?2",
|
|
||||||
params![prior.to_string(), token],
|
|
||||||
)?;
|
|
||||||
tx.execute(
|
|
||||||
"INSERT INTO polymarket_token_observation_times VALUES(?1,?2)
|
|
||||||
ON CONFLICT(token_id) DO UPDATE SET observed_at_ms=excluded.observed_at_ms",
|
|
||||||
params![token, observed_at_ms],
|
|
||||||
)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
WITH selectors AS (
|
|
||||||
SELECT key AS ordinal, json_extract(value,'$[0]') AS id,
|
|
||||||
json_extract(value,'$[2]') AS kind
|
|
||||||
FROM json_each(?1)
|
|
||||||
)
|
|
||||||
SELECT s.ordinal,t.observation,m.market,
|
|
||||||
CASE WHEN t.slot=0 THEN m.zero_outcome
|
|
||||||
WHEN m.zero_outcome='YES' THEN 'NO' ELSE 'YES' END AS outcome,o.observed_at_ms
|
|
||||||
FROM selectors s
|
|
||||||
JOIN polymarket_token_aliases t ON
|
|
||||||
(s.kind='external_token' AND t.token_id=s.id)
|
|
||||||
OR (s.kind='condition' AND
|
|
||||||
(t.condition_id=s.id OR t.group_id=s.id OR t.structure=s.id OR t.structure=s.id||'00'))
|
|
||||||
JOIN polymarket_market_aliases m ON m.condition_id=t.condition_id
|
|
||||||
LEFT JOIN polymarket_token_observation_times o ON o.token_id=t.token_id
|
|
||||||
ORDER BY s.ordinal,t.question,t.condition_id,(t.module<>'v1_ctf'),t.slot
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
use crate::{assets, inventory::decimal, Exchange, MarketDataError};
|
|
||||||
use serde::Deserialize;
|
|
||||||
use serde_json::{json, Value};
|
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
const MAX_TOKEN: &str =
|
|
||||||
"115792089237316195423570985008687907853269984665640564039457584007913129639935";
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct TokenDirectoryQuery {
|
|
||||||
#[serde(alias = "token_ids")]
|
|
||||||
token_id: Option<String>,
|
|
||||||
#[serde(alias = "condition_id", alias = "conditionId")]
|
|
||||||
condition: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn invalid(message: impl Into<String>) -> MarketDataError {
|
|
||||||
MarketDataError::Invalid(message.into())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn condition_hex(value: &str) -> Option<String> {
|
|
||||||
let hex = value
|
|
||||||
.strip_prefix("0x")
|
|
||||||
.or_else(|| value.strip_prefix("0X"))?;
|
|
||||||
if !matches!(hex.len(), 62 | 64) || !hex.bytes().all(|b| b.is_ascii_hexdigit()) {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(format!("0x{}", hex.to_ascii_lowercase()))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn decimal_token(value: &str) -> Option<&str> {
|
|
||||||
let digits = value.trim_start_matches('0');
|
|
||||||
if value.is_empty()
|
|
||||||
|| !value.bytes().all(|b| b.is_ascii_digit())
|
|
||||||
|| digits.len() > MAX_TOKEN.len()
|
|
||||||
|| (digits.len() == MAX_TOKEN.len() && digits > MAX_TOKEN)
|
|
||||||
{
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(if digits.is_empty() { "0" } else { digits })
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Exchange {
|
|
||||||
pub fn public_tokens(&self, query: TokenDirectoryQuery) -> Result<Value, MarketDataError> {
|
|
||||||
let token = query.token_id.as_deref().filter(|s| !s.trim().is_empty());
|
|
||||||
let condition = query.condition.as_deref().filter(|s| !s.trim().is_empty());
|
|
||||||
let (raw, is_token, limit, selector) = match (token, condition) {
|
|
||||||
(Some(raw), None) => (raw, true, 50, "token_id"),
|
|
||||||
(None, Some(raw)) => (raw, false, 10, "condition"),
|
|
||||||
_ => return Err(invalid("provide exactly one of 'token_id' or 'condition'")),
|
|
||||||
};
|
|
||||||
let tx = self.db.unchecked_transaction()?;
|
|
||||||
let mut seen = HashSet::new();
|
|
||||||
let mut keys = Vec::new();
|
|
||||||
for value in raw.split(',').map(str::trim) {
|
|
||||||
let (key, outcome, kind) = if is_token {
|
|
||||||
if let Ok((outcome, market)) = assets::parse_id(value) {
|
|
||||||
(market.to_owned(), Some(outcome), "local_token")
|
|
||||||
} else {
|
|
||||||
let token = decimal_token(value)
|
|
||||||
.ok_or_else(|| invalid(format!("invalid token id: {value}")))?;
|
|
||||||
(token.to_owned(), None, "external_token")
|
|
||||||
}
|
|
||||||
} else if let Some(hex) = condition_hex(value) {
|
|
||||||
(hex, None, "condition")
|
|
||||||
} else {
|
|
||||||
let listed: bool = tx.query_row(
|
|
||||||
"SELECT EXISTS(SELECT 1 FROM markets WHERE id=?1)
|
|
||||||
OR EXISTS(SELECT 1 FROM neg_risk_groups WHERE id=?1)",
|
|
||||||
[value],
|
|
||||||
|row| row.get(0),
|
|
||||||
)?;
|
|
||||||
if !listed {
|
|
||||||
return Err(invalid(format!("invalid condition id: {value}")));
|
|
||||||
}
|
|
||||||
(value.to_owned(), None, "condition")
|
|
||||||
};
|
|
||||||
if seen.insert((key.clone(), outcome)) {
|
|
||||||
if seen.len() > limit {
|
|
||||||
return Err(invalid(format!(
|
|
||||||
"'{selector}' accepts at most {limit} distinct values"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
keys.push((key, outcome, kind));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let input = serde_json::to_string(&keys).map_err(|_| MarketDataError::Unavailable)?;
|
|
||||||
let mut data = {
|
|
||||||
let mut stmt = tx.prepare_cached(include_str!("token_directory.sql"))?;
|
|
||||||
let rows = stmt.query_map([&input], |r| {
|
|
||||||
let market: String = r.get(0)?;
|
|
||||||
let phase: String = r.get(5)?;
|
|
||||||
let winner: Option<String> = r.get(6)?;
|
|
||||||
let index: i64 = r.get(7)?;
|
|
||||||
let (outcome, other) = if index == 0 { ("YES", "NO") } else { ("NO", "YES") };
|
|
||||||
let group: Option<String> = r.get(8)?;
|
|
||||||
let price = winner.as_deref().filter(|_| phase=="resolved").map(|winner| {
|
|
||||||
if winner == "VOID" { decimal(5,10) } else { decimal(i128::from(winner == outcome),1) }
|
|
||||||
});
|
|
||||||
Ok((r.get::<_, i64>(12)?, json!({
|
|
||||||
"token_id":assets::id(&market,outcome),"condition_id":market,
|
|
||||||
"structural_condition_id":null,"module":if group.is_some() { "local_neg_risk" } else { "local_binary" },
|
|
||||||
"outcome_index":index,"clob_index":null,"outcome":r.get::<_,String>(if index==0 {3} else {4})?,
|
|
||||||
"opposite_token_id":assets::id(&market,other),
|
|
||||||
"resolved":phase=="resolved","closed":matches!(phase.as_str(),"closed"|"resolved"),
|
|
||||||
"final_price":price,"title":r.get::<_,String>(1)?,"market_slug":r.get::<_,String>(2)?,
|
|
||||||
"neg_risk":group.is_some(),"neg_risk_market_id":group,"question_index":r.get::<_,Option<i64>>(9)?,
|
|
||||||
"event_id":r.get::<_,Option<i64>>(10)?,"event_slug":r.get::<_,Option<String>>(11)?
|
|
||||||
})))
|
|
||||||
})?;
|
|
||||||
rows.collect::<rusqlite::Result<Vec<_>>>()?
|
|
||||||
};
|
|
||||||
let externals = {
|
|
||||||
let mut stmt = tx.prepare_cached(include_str!("token_aliases.sql"))?;
|
|
||||||
let rows = stmt.query_map([&input], |r| {
|
|
||||||
Ok((
|
|
||||||
r.get::<_, i64>(0)?,
|
|
||||||
r.get::<_, String>(1)?,
|
|
||||||
r.get::<_, String>(2)?,
|
|
||||||
r.get::<_, String>(3)?,
|
|
||||||
r.get::<_, Option<i64>>(4)?,
|
|
||||||
))
|
|
||||||
})?;
|
|
||||||
rows.collect::<rusqlite::Result<Vec<_>>>()?
|
|
||||||
};
|
|
||||||
let external_ordinals: HashSet<_> = externals.iter().map(|r| r.0).collect();
|
|
||||||
data.retain(|(ordinal, _)| !external_ordinals.contains(ordinal));
|
|
||||||
for (ordinal, raw, market, outcome, observed_at_ms) in externals {
|
|
||||||
let mut row: Value =
|
|
||||||
serde_json::from_str(&raw).map_err(|_| MarketDataError::Unavailable)?;
|
|
||||||
row["local_condition_id"] = json!(market);
|
|
||||||
row["local_asset_id"] = json!(assets::id(&market, &outcome));
|
|
||||||
row["observed_at_ms"] = json!(observed_at_ms);
|
|
||||||
data.push((ordinal, row));
|
|
||||||
}
|
|
||||||
data.sort_by_key(|row| row.0);
|
|
||||||
let data: Vec<_> = data.into_iter().map(|(_, row)| row).collect();
|
|
||||||
tx.commit()?;
|
|
||||||
Ok(json!({"data":data}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
WITH selectors AS (
|
|
||||||
SELECT key AS ordinal, json_extract(value,'$[0]') AS market,
|
|
||||||
json_extract(value,'$[1]') AS outcome, json_extract(value,'$[2]') AS kind
|
|
||||||
FROM json_each(?1)
|
|
||||||
), markets_selected AS (
|
|
||||||
SELECT s.ordinal,m.id AS market,s.outcome
|
|
||||||
FROM selectors s JOIN markets m ON m.id=s.market
|
|
||||||
WHERE s.kind<>'external_token'
|
|
||||||
UNION ALL
|
|
||||||
SELECT s.ordinal,n.market,NULL
|
|
||||||
FROM selectors s JOIN neg_risk_members n ON n.group_id=s.market
|
|
||||||
WHERE s.kind='condition' AND s.outcome IS NULL AND NOT EXISTS (SELECT 1 FROM markets m WHERE m.id=s.market)
|
|
||||||
), slots(outcome, outcome_index) AS (VALUES ('YES',0),('NO',1))
|
|
||||||
SELECT m.id,w.question,w.slug,w.yes_label,w.no_label,m.phase,m.winner,s.outcome_index,
|
|
||||||
n.group_id,n.ordinal,e.event_id,e.slug,x.ordinal
|
|
||||||
FROM markets_selected x JOIN markets m ON m.id=x.market
|
|
||||||
JOIN market_wire_metadata w ON w.market=x.market
|
|
||||||
JOIN slots s ON x.outcome IS NULL OR s.outcome=x.outcome
|
|
||||||
LEFT JOIN neg_risk_members n ON n.market=x.market
|
|
||||||
LEFT JOIN listed_markets l ON l.market=x.market
|
|
||||||
LEFT JOIN numbered_events e ON e.id=l.event
|
|
||||||
ORDER BY x.ordinal,n.ordinal,m.id,s.outcome_index
|
|
||||||
@@ -4176,141 +4176,3 @@ fn order_submission_terms_survive_fills_cancel_retries_and_legacy_upgrade() {
|
|||||||
assert_eq!(e.execute(cmd.clone()).unwrap()["orders"][0], expected);
|
assert_eq!(e.execute(cmd.clone()).unwrap()["orders"][0], expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn public_token_directory_routes_results_and_expands_negative_risk_groups() {
|
|
||||||
let mut exchange = Exchange::open(":memory:").unwrap();
|
|
||||||
for line in include_str!("../../../docs/examples/neg-risk.jsonl")
|
|
||||||
.lines()
|
|
||||||
.take(5)
|
|
||||||
{
|
|
||||||
exchange
|
|
||||||
.execute(serde_json::from_str(line).unwrap())
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
let read = |e: &Exchange, value| {
|
|
||||||
e.public_tokens(serde_json::from_value(value).unwrap())
|
|
||||||
.unwrap()["data"]
|
|
||||||
.clone()
|
|
||||||
};
|
|
||||||
let group = read(&exchange, json!({"condition":"winner"}));
|
|
||||||
assert_eq!(group.as_array().unwrap().len(), 6);
|
|
||||||
assert_eq!(group[0]["condition_id"], "a");
|
|
||||||
assert_eq!(group[0]["question_index"], 0);
|
|
||||||
assert_eq!(group[1]["opposite_token_id"], group[0]["token_id"]);
|
|
||||||
assert_eq!(group[4]["condition_id"], "other");
|
|
||||||
assert!(group[0]["event_id"].is_number());
|
|
||||||
let rows = read(
|
|
||||||
&exchange,
|
|
||||||
json!({"token_ids":"eb:NO:a,123,eb:YES:a,eb:NO:a"}),
|
|
||||||
);
|
|
||||||
assert_eq!(rows, json!([group[1], group[0]]));
|
|
||||||
assert_eq!(rows[0]["final_price"], Value::Null);
|
|
||||||
setup(&mut exchange);
|
|
||||||
exchange
|
|
||||||
.execute(json!({"op":"close","id":"close-e","market":"e"}))
|
|
||||||
.unwrap();
|
|
||||||
exchange
|
|
||||||
.execute(json!({"op":"finalize","id":"void-e","market":"e","winner":"VOID"}))
|
|
||||||
.unwrap();
|
|
||||||
let voided = read(&exchange, json!({"conditionId":"e"}));
|
|
||||||
assert_eq!(voided[0]["closed"], true);
|
|
||||||
assert_eq!(voided[1]["resolved"], true);
|
|
||||||
assert_eq!(voided[0]["final_price"], 0.5);
|
|
||||||
assert_eq!(voided[1]["final_price"], 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn polymarket_asset_bindings_preserve_protocols_and_explicit_outcome_direction() {
|
|
||||||
let dir = tempdir().unwrap();
|
|
||||||
let path = dir.path().join("venue-ids.db");
|
|
||||||
let mut e = Exchange::open(&path).unwrap();
|
|
||||||
setup(&mut e);
|
|
||||||
let fixture: Value = serde_json::from_str(include_str!(
|
|
||||||
"../../../docs/examples/polymarket-asset-binding.json"
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
let mut command = json!({"op":"bind_polymarket_assets","id":"bind","market":"e","zero_outcome":"NO",
|
|
||||||
"external_condition":fixture["external_condition"], "data":fixture["data"]});
|
|
||||||
let receipt = e.execute(command.clone()).unwrap();
|
|
||||||
assert_eq!(receipt["tokens"], 4);
|
|
||||||
assert_eq!(e.execute(command.clone()).unwrap(), receipt);
|
|
||||||
command["id"] = json!("flipped");
|
|
||||||
command["zero_outcome"] = json!("YES");
|
|
||||||
assert!(e.execute(command).is_err());
|
|
||||||
drop(e);
|
|
||||||
let e = Exchange::open(path).unwrap();
|
|
||||||
let lookup = |query| {
|
|
||||||
e.public_tokens(serde_json::from_value(query).unwrap())
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
let condition = lookup(json!({"condition":fixture["external_condition"]}));
|
|
||||||
let rows = condition["data"].as_array().unwrap();
|
|
||||||
assert_eq!(rows.len(), 4);
|
|
||||||
assert_eq!(rows[0]["module"], "v1_ctf");
|
|
||||||
assert_eq!(rows[2]["module"], "neg_risk");
|
|
||||||
assert_eq!(rows[2]["local_asset_id"], "eb:NO:e");
|
|
||||||
assert_eq!(rows[3]["local_asset_id"], "eb:YES:e");
|
|
||||||
let structural = rows[2]["structural_condition_id"].as_str().unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
lookup(json!({"condition":&structural[..64]}))["data"],
|
|
||||||
json!([rows[2], rows[3]])
|
|
||||||
);
|
|
||||||
let token = rows[3]["token_id"].as_str().unwrap();
|
|
||||||
assert_eq!(
|
|
||||||
lookup(json!({"token_id":format!("00{token},00123,eb:NO:e")}))["data"][0],
|
|
||||||
rows[3]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn polymarket_observations_refresh_without_reverting_a_final_payout() {
|
|
||||||
let dir = tempdir().unwrap();
|
|
||||||
let path = dir.path().join("refresh.db");
|
|
||||||
let mut engine = Exchange::open(&path).unwrap();
|
|
||||||
setup(&mut engine);
|
|
||||||
let fixture: Value = serde_json::from_str(include_str!(
|
|
||||||
"../../../docs/examples/polymarket-asset-refresh.json"
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
let resolved = fixture["directory"]["body"]["data"].clone();
|
|
||||||
let mut open = resolved.clone();
|
|
||||||
for item in open.as_array_mut().unwrap() {
|
|
||||||
item["closed"] = json!(false);
|
|
||||||
item["resolved"] = json!(false);
|
|
||||||
item["final_price"] = Value::Null;
|
|
||||||
}
|
|
||||||
let late = fixture["directory"]["observed_at_ms"].as_i64().unwrap();
|
|
||||||
let early = fixture["prior_book"]["observed_at_ms"].as_i64().unwrap();
|
|
||||||
let condition = &resolved[0]["condition_id"];
|
|
||||||
let obs = |id, stamp, rows: &Value| {
|
|
||||||
json!({
|
|
||||||
"op":"bind_polymarket_assets", "id":id,"market":"e","zero_outcome":"YES",
|
|
||||||
"external_condition":condition,"observed_at_ms":stamp,"data":rows
|
|
||||||
})
|
|
||||||
};
|
|
||||||
engine.execute(obs("before", early, &open)).unwrap();
|
|
||||||
engine.execute(obs("final", late, &resolved)).unwrap();
|
|
||||||
engine.execute(obs("old", early, &open)).unwrap();
|
|
||||||
assert!(engine
|
|
||||||
.execute(obs("same-time-conflict", late, &open))
|
|
||||||
.is_err());
|
|
||||||
assert!(engine
|
|
||||||
.execute(obs("new-conflict", late + 1, &open))
|
|
||||||
.is_err());
|
|
||||||
drop(engine);
|
|
||||||
let engine = Exchange::open(path).unwrap();
|
|
||||||
let lookup = engine
|
|
||||||
.public_tokens(serde_json::from_value(json!({"condition":condition})).unwrap())
|
|
||||||
.unwrap();
|
|
||||||
let rows = lookup["data"].as_array().unwrap();
|
|
||||||
assert_eq!(rows.len(), 4);
|
|
||||||
for row in rows {
|
|
||||||
assert_eq!(row["resolved"], true);
|
|
||||||
assert_eq!(row["observed_at_ms"], late);
|
|
||||||
}
|
|
||||||
let local = engine
|
|
||||||
.public_tokens(serde_json::from_value(json!({"condition":"e"})).unwrap())
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(local["data"][0]["resolved"], false);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
{
|
|
||||||
"source": "https://data-api.polymarket.com/v2/tokens?condition=0xdfb674d9eb1ca2f4b1c38d36562b725d6dca8364b3b1eea2dafc773608959c80",
|
|
||||||
"date": "Fri, 04 Dec 2026 21:03:26 GMT",
|
|
||||||
"external_condition": "0xdfb674d9eb1ca2f4b1c38d36562b725d6dca8364b3b1eea2dafc773608959c80",
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"token_id": "56766704504589537417119461476407464198158915644205212964421261364010493123785",
|
|
||||||
"condition_id": "0xdfb674d9eb1ca2f4b1c38d36562b725d6dca8364b3b1eea2dafc773608959c80",
|
|
||||||
"structural_condition_id": null,
|
|
||||||
"module": "v1_ctf",
|
|
||||||
"outcome_index": 0,
|
|
||||||
"clob_index": 0,
|
|
||||||
"outcome": "Yes",
|
|
||||||
"opposite_token_id": "33748178601941852783056114873418965902944929138778460252404676407918318867810",
|
|
||||||
"resolved": false,
|
|
||||||
"final_price": null,
|
|
||||||
"title": "Will Paris Saint-Germain FC win on 2026-12-04?",
|
|
||||||
"market_slug": "fl1-tou-psg-2026-12-04-psg",
|
|
||||||
"closed": false,
|
|
||||||
"neg_risk": true,
|
|
||||||
"neg_risk_market_id": "0xbac6a2a3e5faf30fdabab133b0258ed9bf5052dd0f75c60464fe2f290bc93000",
|
|
||||||
"question_index": 2,
|
|
||||||
"event_id": 1465085,
|
|
||||||
"event_slug": "fl1-tou-psg-2026-12-04"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"token_id": "33748178601941852783056114873418965902944929138778460252404676407918318867810",
|
|
||||||
"condition_id": "0xdfb674d9eb1ca2f4b1c38d36562b725d6dca8364b3b1eea2dafc773608959c80",
|
|
||||||
"structural_condition_id": null,
|
|
||||||
"module": "v1_ctf",
|
|
||||||
"outcome_index": 1,
|
|
||||||
"clob_index": 1,
|
|
||||||
"outcome": "No",
|
|
||||||
"opposite_token_id": "56766704504589537417119461476407464198158915644205212964421261364010493123785",
|
|
||||||
"resolved": false,
|
|
||||||
"final_price": null,
|
|
||||||
"title": "Will Paris Saint-Germain FC win on 2026-12-04?",
|
|
||||||
"market_slug": "fl1-tou-psg-2026-12-04-psg",
|
|
||||||
"closed": false,
|
|
||||||
"neg_risk": true,
|
|
||||||
"neg_risk_market_id": "0xbac6a2a3e5faf30fdabab133b0258ed9bf5052dd0f75c60464fe2f290bc93000",
|
|
||||||
"question_index": 2,
|
|
||||||
"event_id": 1465085,
|
|
||||||
"event_slug": "fl1-tou-psg-2026-12-04"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"token_id": "1242647860242950490718683690862688823036949349322148957738072940768458179072",
|
|
||||||
"condition_id": "0xdfb674d9eb1ca2f4b1c38d36562b725d6dca8364b3b1eea2dafc773608959c80",
|
|
||||||
"structural_condition_id": "0x02bf5052dd0f75c60464fe2f290bc93000000300000000000000000000000200",
|
|
||||||
"module": "neg_risk",
|
|
||||||
"outcome_index": 0,
|
|
||||||
"clob_index": null,
|
|
||||||
"outcome": "Yes",
|
|
||||||
"opposite_token_id": "1242647860242950490718683690862688823036949349322148957738072940768458179073",
|
|
||||||
"resolved": false,
|
|
||||||
"final_price": null,
|
|
||||||
"title": "Will Paris Saint-Germain FC win on 2026-12-04?",
|
|
||||||
"market_slug": "fl1-tou-psg-2026-12-04-psg",
|
|
||||||
"closed": false,
|
|
||||||
"neg_risk": true,
|
|
||||||
"neg_risk_market_id": "0xbac6a2a3e5faf30fdabab133b0258ed9bf5052dd0f75c60464fe2f290bc93000",
|
|
||||||
"question_index": 2,
|
|
||||||
"event_id": 1465085,
|
|
||||||
"event_slug": "fl1-tou-psg-2026-12-04"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"token_id": "1242647860242950490718683690862688823036949349322148957738072940768458179073",
|
|
||||||
"condition_id": "0xdfb674d9eb1ca2f4b1c38d36562b725d6dca8364b3b1eea2dafc773608959c80",
|
|
||||||
"structural_condition_id": "0x02bf5052dd0f75c60464fe2f290bc93000000300000000000000000000000200",
|
|
||||||
"module": "neg_risk",
|
|
||||||
"outcome_index": 1,
|
|
||||||
"clob_index": null,
|
|
||||||
"outcome": "No",
|
|
||||||
"opposite_token_id": "1242647860242950490718683690862688823036949349322148957738072940768458179072",
|
|
||||||
"resolved": false,
|
|
||||||
"final_price": null,
|
|
||||||
"title": "Will Paris Saint-Germain FC win on 2026-12-04?",
|
|
||||||
"market_slug": "fl1-tou-psg-2026-12-04-psg",
|
|
||||||
"closed": false,
|
|
||||||
"neg_risk": true,
|
|
||||||
"neg_risk_market_id": "0xbac6a2a3e5faf30fdabab133b0258ed9bf5052dd0f75c60464fe2f290bc93000",
|
|
||||||
"question_index": 2,
|
|
||||||
"event_id": 1465085,
|
|
||||||
"event_slug": "fl1-tou-psg-2026-12-04"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
{
|
|
||||||
"prior_book": {
|
|
||||||
"url": "https://clob.polymarket.com/book?token_id=64069535502365350520464017439278800338614209934309608490621606944970108681676",
|
|
||||||
"date": "Thu, 03 Dec 2026 07:55:53 GMT",
|
|
||||||
"status": 200,
|
|
||||||
"body": {
|
|
||||||
"market": "0xe5febd2f236a15ef7c1cc70a481e081bb64223d3e67aa3870677cccd72530853",
|
|
||||||
"asset_id": "64069535502365350520464017439278800338614209934309608490621606944970108681676",
|
|
||||||
"timestamp": "1796284481649",
|
|
||||||
"hash": "575e315a02461b9280427591ba1fe7e48b3b70ce",
|
|
||||||
"bids": [],
|
|
||||||
"asks": [],
|
|
||||||
"min_order_size": "5",
|
|
||||||
"tick_size": "0.01",
|
|
||||||
"neg_risk": false,
|
|
||||||
"last_trade_price": ""
|
|
||||||
},
|
|
||||||
"observed_at_ms": 1796284553000
|
|
||||||
},
|
|
||||||
"directory": {
|
|
||||||
"url": "https://data-api.polymarket.com/v2/tokens?condition=0xe5febd2f236a15ef7c1cc70a481e081bb64223d3e67aa3870677cccd72530853",
|
|
||||||
"status": 200,
|
|
||||||
"date": "Fri, 04 Dec 2026 21:11:06 GMT",
|
|
||||||
"body": {
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"token_id": "64069535502365350520464017439278800338614209934309608490621606944970108681676",
|
|
||||||
"condition_id": "0xe5febd2f236a15ef7c1cc70a481e081bb64223d3e67aa3870677cccd72530853",
|
|
||||||
"structural_condition_id": null,
|
|
||||||
"module": "v1_ctf",
|
|
||||||
"outcome_index": 0,
|
|
||||||
"clob_index": 0,
|
|
||||||
"outcome": "Over",
|
|
||||||
"opposite_token_id": "24637903833591077899504141654082654473942967248855682279041797174393952421575",
|
|
||||||
"resolved": true,
|
|
||||||
"final_price": 0.0,
|
|
||||||
"title": "Map 1 Total Rounds: Over/Under 27.5",
|
|
||||||
"market_slug": "cs2-bb3-lgc-2026-12-03-game1-round-total-27pt5",
|
|
||||||
"closed": true,
|
|
||||||
"neg_risk": false,
|
|
||||||
"neg_risk_market_id": null,
|
|
||||||
"question_index": null,
|
|
||||||
"event_id": 1495714,
|
|
||||||
"event_slug": "cs2-bb3-lgc-2026-12-03"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"token_id": "24637903833591077899504141654082654473942967248855682279041797174393952421575",
|
|
||||||
"condition_id": "0xe5febd2f236a15ef7c1cc70a481e081bb64223d3e67aa3870677cccd72530853",
|
|
||||||
"structural_condition_id": null,
|
|
||||||
"module": "v1_ctf",
|
|
||||||
"outcome_index": 1,
|
|
||||||
"clob_index": 1,
|
|
||||||
"outcome": "Under",
|
|
||||||
"opposite_token_id": "64069535502365350520464017439278800338614209934309608490621606944970108681676",
|
|
||||||
"resolved": true,
|
|
||||||
"final_price": 1.0,
|
|
||||||
"title": "Map 1 Total Rounds: Over/Under 27.5",
|
|
||||||
"market_slug": "cs2-bb3-lgc-2026-12-03-game1-round-total-27pt5",
|
|
||||||
"closed": true,
|
|
||||||
"neg_risk": false,
|
|
||||||
"neg_risk_market_id": null,
|
|
||||||
"question_index": null,
|
|
||||||
"event_id": 1495714,
|
|
||||||
"event_slug": "cs2-bb3-lgc-2026-12-03"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"token_id": "774335495545660990871175894688282765790269993344601020630233166497523433472",
|
|
||||||
"condition_id": "0xe5febd2f236a15ef7c1cc70a481e081bb64223d3e67aa3870677cccd72530853",
|
|
||||||
"structural_condition_id": "0x01b64223d3e67aa3870677cccd72530853000000000000000000000000000000",
|
|
||||||
"module": "binary",
|
|
||||||
"outcome_index": 0,
|
|
||||||
"clob_index": null,
|
|
||||||
"outcome": "Over",
|
|
||||||
"opposite_token_id": "774335495545660990871175894688282765790269993344601020630233166497523433473",
|
|
||||||
"resolved": true,
|
|
||||||
"final_price": 0.0,
|
|
||||||
"title": "Map 1 Total Rounds: Over/Under 27.5",
|
|
||||||
"market_slug": "cs2-bb3-lgc-2026-12-03-game1-round-total-27pt5",
|
|
||||||
"closed": true,
|
|
||||||
"neg_risk": false,
|
|
||||||
"neg_risk_market_id": null,
|
|
||||||
"question_index": null,
|
|
||||||
"event_id": 1495714,
|
|
||||||
"event_slug": "cs2-bb3-lgc-2026-12-03"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"token_id": "774335495545660990871175894688282765790269993344601020630233166497523433473",
|
|
||||||
"condition_id": "0xe5febd2f236a15ef7c1cc70a481e081bb64223d3e67aa3870677cccd72530853",
|
|
||||||
"structural_condition_id": "0x01b64223d3e67aa3870677cccd72530853000000000000000000000000000000",
|
|
||||||
"module": "binary",
|
|
||||||
"outcome_index": 1,
|
|
||||||
"clob_index": null,
|
|
||||||
"outcome": "Under",
|
|
||||||
"opposite_token_id": "774335495545660990871175894688282765790269993344601020630233166497523433472",
|
|
||||||
"resolved": true,
|
|
||||||
"final_price": 1.0,
|
|
||||||
"title": "Map 1 Total Rounds: Over/Under 27.5",
|
|
||||||
"market_slug": "cs2-bb3-lgc-2026-12-03-game1-round-total-27pt5",
|
|
||||||
"closed": true,
|
|
||||||
"neg_risk": false,
|
|
||||||
"neg_risk_market_id": null,
|
|
||||||
"question_index": null,
|
|
||||||
"event_id": 1495714,
|
|
||||||
"event_slug": "cs2-bb3-lgc-2026-12-03"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"observed_at_ms": 1796418666000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"one": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400","status":200,"date":"Fri, 04 Dec 2026 20:59:33 GMT","body":{"data":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":0,"clob_index":null,"outcome":"Nikolenko Anatolii","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","resolved":true,"final_price":1.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"}]}},
|
|
||||||
"alias": {"url":"https://data-api.polymarket.com/v2/tokens?tokenId=759916398134244316868652908232832573045153963965173623897622651599218278400","status":400,"date":"Fri, 04 Dec 2026 20:59:33 GMT","body":{"error":"provide exactly one of 'token_id' or 'condition'","code":"invalid_request","retryable":false}},
|
|
||||||
"pair": {"url":"https://data-api.polymarket.com/v2/tokens?condition=0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","status":200,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"data":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":0,"clob_index":null,"outcome":"Nikolenko Anatolii","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","resolved":true,"final_price":1.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":1,"clob_index":null,"outcome":"Fokin Illia","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","resolved":true,"final_price":0.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"}]}},
|
|
||||||
"pair_alias": {"url":"https://data-api.polymarket.com/v2/tokens?conditionId=0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","status":200,"date":"Fri, 04 Dec 2026 20:59:33 GMT","body":{"data":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":0,"clob_index":null,"outcome":"Nikolenko Anatolii","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","resolved":true,"final_price":1.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":1,"clob_index":null,"outcome":"Fokin Illia","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","resolved":true,"final_price":0.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"}]}},
|
|
||||||
"v1": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=73979342585906843441145134109923710004884703083095161594360108477170435492453","status":200,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"data":[{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","condition_id":"0xdf04a0495b0a16dbce386acdc16d9aed19784db9888be53d150354b83b7c18b1","structural_condition_id":null,"module":"v1_ctf","outcome_index":0,"clob_index":0,"outcome":"Over","opposite_token_id":"78188826358032258311424545486331333398838521699262460256542567713692269401385","resolved":true,"final_price":0.0,"title":"Map 1 Total Rounds: Over/Under 30.5","market_slug":"cs2-bb3-lgc-2026-12-03-game1-round-total-30pt5","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1495714,"event_slug":"cs2-bb3-lgc-2026-12-03"}]}},
|
|
||||||
"multi": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=759916398134244316868652908232832573045153963965173623897622651599218278401%2C123%2C759916398134244316868652908232832573045153963965173623897622651599218278400%2C759916398134244316868652908232832573045153963965173623897622651599218278401","status":200,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"data":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":1,"clob_index":null,"outcome":"Fokin Illia","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","resolved":true,"final_price":0.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":0,"clob_index":null,"outcome":"Nikolenko Anatolii","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","resolved":true,"final_price":1.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"}]}},
|
|
||||||
"both": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=759916398134244316868652908232832573045153963965173623897622651599218278400&condition=0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","status":400,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"error":"provide exactly one of 'token_id' or 'condition'","code":"invalid_request","retryable":false}},
|
|
||||||
"none": {"url":"https://data-api.polymarket.com/v2/tokens?","status":400,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"error":"provide exactly one of 'token_id' or 'condition'","code":"invalid_request","retryable":false}},
|
|
||||||
"missing": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=123","status":200,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"data":[]}},
|
|
||||||
"malformed": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=abc","status":400,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"error":"invalid token id: abc","code":"invalid_request","parameter":"token_id","retryable":false}},
|
|
||||||
"bad_condition": {"url":"https://data-api.polymarket.com/v2/tokens?condition=invalid","status":400,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"error":"invalid condition id: invalid","code":"invalid_request","parameter":"condition","retryable":false}},
|
|
||||||
"unknown_condition": {"url":"https://data-api.polymarket.com/v2/tokens?condition=0x0000000000000000000000000000000000000000000000000000000000000000","status":200,"date":"Fri, 04 Dec 2026 20:59:34 GMT","body":{"data":[]}},
|
|
||||||
"multi_condition": {"url":"https://data-api.polymarket.com/v2/tokens?condition=0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000%2C0xdf04a0495b0a16dbce386acdc16d9aed19784db9888be53d150354b83b7c18b1","status":200,"date":"Fri, 04 Dec 2026 20:59:35 GMT","body":{"data":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":0,"clob_index":null,"outcome":"Nikolenko Anatolii","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","resolved":true,"final_price":1.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":1,"clob_index":null,"outcome":"Fokin Illia","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","resolved":true,"final_price":0.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"},{"token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","condition_id":"0xdf04a0495b0a16dbce386acdc16d9aed19784db9888be53d150354b83b7c18b1","structural_condition_id":null,"module":"v1_ctf","outcome_index":0,"clob_index":0,"outcome":"Over","opposite_token_id":"78188826358032258311424545486331333398838521699262460256542567713692269401385","resolved":true,"final_price":0.0,"title":"Map 1 Total Rounds: Over/Under 30.5","market_slug":"cs2-bb3-lgc-2026-12-03-game1-round-total-30pt5","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1495714,"event_slug":"cs2-bb3-lgc-2026-12-03"},{"token_id":"78188826358032258311424545486331333398838521699262460256542567713692269401385","condition_id":"0xdf04a0495b0a16dbce386acdc16d9aed19784db9888be53d150354b83b7c18b1","structural_condition_id":null,"module":"v1_ctf","outcome_index":1,"clob_index":1,"outcome":"Under","opposite_token_id":"73979342585906843441145134109923710004884703083095161594360108477170435492453","resolved":true,"final_price":1.0,"title":"Map 1 Total Rounds: Over/Under 30.5","market_slug":"cs2-bb3-lgc-2026-12-03-game1-round-total-30pt5","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1495714,"event_slug":"cs2-bb3-lgc-2026-12-03"}]}},
|
|
||||||
"plural": {"url":"https://data-api.polymarket.com/v2/tokens?token_ids=759916398134244316868652908232832573045153963965173623897622651599218278400","status":200,"date":"Fri, 04 Dec 2026 21:00:05 GMT","body":{"data":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":0,"clob_index":null,"outcome":"Nikolenko Anatolii","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","resolved":true,"final_price":1.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"}]}},
|
|
||||||
"zero_prefix": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=000759916398134244316868652908232832573045153963965173623897622651599218278400","status":200,"date":"Fri, 04 Dec 2026 21:00:05 GMT","body":{"data":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":0,"clob_index":null,"outcome":"Nikolenko Anatolii","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","resolved":true,"final_price":1.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"}]}},
|
|
||||||
"empty_token": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=","status":400,"date":"Fri, 04 Dec 2026 21:00:05 GMT","body":{"error":"provide exactly one of 'token_id' or 'condition'","code":"invalid_request","retryable":false}},
|
|
||||||
"huge": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999","status":400,"date":"Fri, 04 Dec 2026 21:00:05 GMT","body":{"error":"invalid token id: 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999","code":"invalid_request","parameter":"token_id","retryable":false}},
|
|
||||||
"short_condition": {"url":"https://data-api.polymarket.com/v2/tokens?condition=0x01ae18f1c798f53d0efe0903889e57483c0000000000000000000000000000","status":200,"date":"Fri, 04 Dec 2026 21:00:05 GMT","body":{"data":[{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":0,"clob_index":null,"outcome":"Nikolenko Anatolii","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","resolved":true,"final_price":1.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"},{"token_id":"759916398134244316868652908232832573045153963965173623897622651599218278401","condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","structural_condition_id":"0x01ae18f1c798f53d0efe0903889e57483c000000000000000000000000000000","module":"binary","outcome_index":1,"clob_index":null,"outcome":"Fokin Illia","opposite_token_id":"759916398134244316868652908232832573045153963965173623897622651599218278400","resolved":true,"final_price":0.0,"title":"Nikolenko Anatolii vs. Fokin Illia","market_slug":"setkameua-anat-illia-2026-12-03","closed":true,"neg_risk":false,"neg_risk_market_id":null,"question_index":null,"event_id":1496938,"event_slug":"setkameua-anat-illia-2026-12-03"}]}},
|
|
||||||
"cap_tokens": {"url":"https://data-api.polymarket.com/v2/tokens?token_id=0%2C1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12%2C13%2C14%2C15%2C16%2C17%2C18%2C19%2C20%2C21%2C22%2C23%2C24%2C25%2C26%2C27%2C28%2C29%2C30%2C31%2C32%2C33%2C34%2C35%2C36%2C37%2C38%2C39%2C40%2C41%2C42%2C43%2C44%2C45%2C46%2C47%2C48%2C49%2C50","status":400,"date":"Fri, 04 Dec 2026 21:00:05 GMT","body":{"error":"'token_id' accepts at most 50 distinct values","code":"invalid_request","parameter":"token_id","retryable":false}}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
[
|
||||||
|
{"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"}}}
|
||||||
|
]
|
||||||
@@ -468,13 +468,6 @@ SDK 使用 `GET /neg-risk?token_id=…`,也可以从已缓存的 CLOB 市场
|
|||||||
`open_orders` 的列表和精确查询均返回 `created_at`(Unix 秒)、`order_type` 和本地扩展 `post_only`。升级已有数据库时,用已受理的命令回执和 GTD 截止记录恢复提交指令;没有原始时钟记录的受理时间为 null。缺少原始回执的历史行仍可查询,未知字段保留为 null。官方当前将累计成交和逐笔对账分别放在订单的 size_matched 和账户成交记录;其单笔订单 HTTP 接口需要账户认证。本地验证使用可信操作员的 JSONL 接口,订单号与账户是模拟环境的标识。生产私有接口尚未实测。[官方订单查询](https://docs.polymarket.com/trading/manage-orders)
|
`open_orders` 的列表和精确查询均返回 `created_at`(Unix 秒)、`order_type` 和本地扩展 `post_only`。升级已有数据库时,用已受理的命令回执和 GTD 截止记录恢复提交指令;没有原始时钟记录的受理时间为 null。缺少原始回执的历史行仍可查询,未知字段保留为 null。官方当前将累计成交和逐笔对账分别放在订单的 size_matched 和账户成交记录;其单笔订单 HTTP 接口需要账户认证。本地验证使用可信操作员的 JSONL 接口,订单号与账户是模拟环境的标识。生产私有接口尚未实测。[官方订单查询](https://docs.polymarket.com/trading/manage-orders)
|
||||||
|
|
||||||
|
|
||||||
### Data API 资产反查
|
### 已裁决资产的交易参数
|
||||||
|
|
||||||
GET /v2/tokens 接受 token_id / token_ids 或 condition / condition_id / conditionId,二选一。生产样本中,资产查询保持请求顺序并合并重复项,数字标识的前导零会被归一。合法的未知资产返回空数组。用本地市场 ID 返回 YES、NO 两侧,用本地互斥组 ID 按题目序号展开成员。已裁决市场可返回最终兑付值,VOID 有两项 0.5。回执保留稳定的本地 eb 标识并自描述本地模块。对照样本覆盖原生 V2、CTF 和短条件 ID,外场同一市场的多协议资产映射仍待接入本地目录。[生产请求和响应](examples/public-token-directory.json) · [官方 OpenAPI](https://data-api.polymarket.com/v2/openapi.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)
|
||||||
|
|
||||||
### 本地登记 Polymarket 资产对照
|
|
||||||
|
|
||||||
可信 JSONL 命令 bind_polymarket_assets 接受本地市场、external_condition、zero_outcome 及官方 data 数组。每种协议必须提供互补一对。登记时核对 V2 编码、互斥组与题目归属,禁止冲突重绑。登记后用外场数字资产或条件查询 /v2/tokens 可得到原协议观察字段及 local_asset_id。互斥组查询仅返回已登记成员。外场状态与兑付值由观测快照提供。[生产登记样本](examples/polymarket-asset-binding.json)
|
|
||||||
|
|
||||||
|
|
||||||
对同一绑定重复提交带 observed_at_ms 的配对可刷新状态及结果标签。旧观测不会覆盖更新状态,同毫秒互相矛盾的快照和推翻最终兑付的请求会拒绝,整笔事务回滚。反查回执带观测时间。一个此前能公开读取盘口的电竞盘,后续 CTF 与 V2 目录均返回裁决输赢。回归使用它的真实裁决响应,并用同一资产生成开放快照来覆盖乱序。刷新由可信操作者提供观测,生产接口的传播时延和自动拉取仍待接入。[生产盘口及裁决快照](examples/polymarket-asset-refresh.json)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user