Probe public market discovery and order books at both venues
This commit is contained in:
Generated
+1029
-5
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["crates/matching", "crates/exchange", "crates/eventbook-cli"]
|
members = ["crates/matching", "crates/exchange", "crates/eventbook-cli", "crates/venue-probe"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "venue-probe"
|
||||||
|
version.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow.workspace = true
|
||||||
|
serde_json.workspace = true
|
||||||
|
reqwest = { version = "0.12", default-features = false, features = ["blocking", "rustls-tls", "json"] }
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# venue-probe
|
||||||
|
|
||||||
|
匿名读取两个场所的生产市场目录,以返回的真实标的查询盘口。Polymarket 检查返回的 asset_id 与请求一致;Kalshi 检查固定小数 YES、NO 买盘数组。无挂单的空数组是有效盘口。错误保留请求阶段和错误链,任一场所失败会以非零状态退出。探针只覆盖公共 REST 数据,实盘授权、WebSocket 和订单执行另行验证。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo run --locked -p venue-probe
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
flowchart LR
|
||||||
|
main["src/main.rs"] -->|依次调用两个只读探针| impls["src/probes.rs"]
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant P as venue-probe
|
||||||
|
participant G as Polymarket Gamma
|
||||||
|
participant C as Polymarket CLOB
|
||||||
|
participant K as Kalshi
|
||||||
|
P->>G: 查询开放市场
|
||||||
|
G-->>P: 返回可交易结果标识
|
||||||
|
P->>C: 按 token 查询盘口
|
||||||
|
C-->>P: 标识与买卖盘
|
||||||
|
P->>K: 查询开放市场
|
||||||
|
K-->>P: 返回 ticker
|
||||||
|
P->>K: 按 ticker 查询订单簿
|
||||||
|
K-->>P: YES 和 NO 买盘
|
||||||
|
```
|
||||||
|
|
||||||
|
本次工作站用 curl 向官方端点执行匿名 GET。Polymarket Gamma 目录与 CLOB 时钟端点均在取得 HTTP 状态前连接重置;Kalshi 生产目录、备用生产状态端点与 Demo 状态端点均超时。此次没有取得实时盘口,Rust 探针按项目约定暂未编译运行。接口依据见 [Polymarket 市场目录](https://docs.polymarket.com/api-reference/markets/list-markets) 与 [Kalshi 盘口文档](https://docs.kalshi.com/getting_started/orderbook_responses)。
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
mod probes;
|
||||||
|
use anyhow::{ensure, Result};
|
||||||
|
use reqwest::blocking::Client;
|
||||||
|
use std::time::Duration;
|
||||||
|
fn main() -> Result<()> {
|
||||||
|
let client = Client::builder()
|
||||||
|
.connect_timeout(Duration::from_secs(5))
|
||||||
|
.timeout(Duration::from_secs(15))
|
||||||
|
.user_agent("eventbook-readonly-probe/0.1")
|
||||||
|
.build()?;
|
||||||
|
let mut ok = true;
|
||||||
|
for (name, result) in [
|
||||||
|
("polymarket", probes::polymarket(&client)),
|
||||||
|
("kalshi", probes::kalshi(&client)),
|
||||||
|
] {
|
||||||
|
match result {
|
||||||
|
Ok(id) => println!("{name}: public catalog and orderbook OK ({id})"),
|
||||||
|
Err(e) => {
|
||||||
|
ok = false;
|
||||||
|
eprintln!("{name}: {e:#}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ensure!(ok, "one or more venues failed");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
use anyhow::{anyhow, ensure, Context, Result};
|
||||||
|
use reqwest::{blocking::Client, Url};
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
fn read(client: &Client, url: Url) -> Result<Value> {
|
||||||
|
client
|
||||||
|
.get(url.clone())
|
||||||
|
.send()
|
||||||
|
.with_context(|| format!("GET {url}"))?
|
||||||
|
.error_for_status()?
|
||||||
|
.json()
|
||||||
|
.context("invalid JSON")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn polymarket(client: &Client) -> Result<String> {
|
||||||
|
let markets = read(
|
||||||
|
client,
|
||||||
|
Url::parse("https://gamma-api.polymarket.com/markets?active=true&closed=false&limit=50")?,
|
||||||
|
)?;
|
||||||
|
let token = markets
|
||||||
|
.as_array()
|
||||||
|
.context("expected market array")?
|
||||||
|
.iter()
|
||||||
|
.filter(|m| m["enableOrderBook"] == true && m["acceptingOrders"] == true)
|
||||||
|
.find_map(|m| {
|
||||||
|
let ids = match &m["clobTokenIds"] {
|
||||||
|
Value::String(raw) => serde_json::from_str(raw).ok()?,
|
||||||
|
v => v.clone(),
|
||||||
|
};
|
||||||
|
ids.get(0)?.as_str().map(str::to_owned)
|
||||||
|
})
|
||||||
|
.context("no active CLOB token in sample")?;
|
||||||
|
let url = Url::parse_with_params("https://clob.polymarket.com/book", &[("token_id", &token)])?;
|
||||||
|
let book = read(client, url)?;
|
||||||
|
ensure!(
|
||||||
|
book["asset_id"].as_str() == Some(token.as_str())
|
||||||
|
&& book["bids"].is_array()
|
||||||
|
&& book["asks"].is_array(),
|
||||||
|
"invalid book or mismatched token"
|
||||||
|
);
|
||||||
|
Ok(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn kalshi(client: &Client) -> Result<String> {
|
||||||
|
let root = "https://external-api.kalshi.com/trade-api/v2/markets";
|
||||||
|
let markets = read(
|
||||||
|
client,
|
||||||
|
Url::parse_with_params(root, &[("status", "open"), ("limit", "1")])?,
|
||||||
|
)?;
|
||||||
|
let ticker = markets["markets"]
|
||||||
|
.get(0)
|
||||||
|
.and_then(|m| m["ticker"].as_str())
|
||||||
|
.context("no open market ticker")?;
|
||||||
|
let mut url = Url::parse(root)?;
|
||||||
|
url.path_segments_mut()
|
||||||
|
.map_err(|_| anyhow!("invalid market URL"))?
|
||||||
|
.extend([ticker, "orderbook"]);
|
||||||
|
let book = read(client, url)?;
|
||||||
|
let depth = &book["orderbook_fp"];
|
||||||
|
ensure!(
|
||||||
|
depth["yes_dollars"].is_array() && depth["no_dollars"].is_array(),
|
||||||
|
"invalid Kalshi depth"
|
||||||
|
);
|
||||||
|
Ok(ticker.to_owned())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user