Skip to main content

predict_fun_sdk/
lib.rs

1//! # predict-fun-sdk
2//!
3//! Rust SDK for the [Predict.fun](https://predict.fun) prediction market API on BNB Chain.
4//!
5//! ## Features
6//!
7//! - **Full REST API coverage**: all 30 endpoints from the [OpenAPI spec](https://api.predict.fun/docs)
8//! - **Real-time WebSocket feeds**: orderbook snapshots, oracle prices, cross-venue data
9//! - **EIP-712 order signing** using [alloy](https://github.com/alloy-rs/alloy) (native Rust, no ethers)
10//! - **Execution pipeline**: auth → sign → submit with dry-run safety guard
11//! - **All 8 exchange contracts**: mainnet + testnet × normal/negRisk/yield/yieldNegRisk
12//!
13//! ## Quick Start
14//!
15//! ```rust,no_run
16//! use predict_fun_sdk::{PredictApiClient, PredictExecutionClient, PredictExecConfig};
17//! use predict_fun_sdk::order::BNB_MAINNET_CHAIN_ID;
18//!
19//! # async fn example() -> anyhow::Result<()> {
20//! // Public data (no auth needed)
21//! let client = PredictApiClient::new_mainnet("your-api-key")?;
22//! let markets = client.list_markets(&[("limit", "10".to_string())]).await?;
23//! let orderbook = client.get_market_orderbook(12345).await?;
24//!
25//! // Real-time WebSocket feeds
26//! use predict_fun_sdk::ws::{PredictWsClient, PredictWsMessage, Topic};
27//! let (ws, mut rx) = PredictWsClient::connect_mainnet().await?;
28//! ws.subscribe(Topic::Orderbook { market_id: 12345 }).await?;
29//! ws.subscribe(Topic::AssetPrice { feed_id: 1 }).await?; // BTC
30//!
31//! // Authenticated execution
32//! let config = PredictExecConfig {
33//!     api_key: "your-api-key".into(),
34//!     private_key: "0x...".into(),
35//!     chain_id: BNB_MAINNET_CHAIN_ID,
36//!     live_execution: false, // dry-run by default
37//!     fill_or_kill: true,
38//! };
39//! let exec = PredictExecutionClient::new(config).await?;
40//! # Ok(())
41//! # }
42//! ```
43//!
44//! ## Modules
45//!
46//! - [`api`] — REST client with typed methods for all 30 endpoints
47//! - [`ws`] — WebSocket client for real-time orderbook, price, and cross-venue feeds
48//! - [`order`] — EIP-712 order structs, signing, and amount calculation
49//! - [`execution`] — High-level auth → sign → submit pipeline
50
51pub mod api;
52pub mod execution;
53pub mod order;
54pub mod ws;
55
56// Re-export primary types at crate root for convenience
57pub use api::{
58    PredictApiClient, RawApiResponse, PREDICT_ENDPOINTS, PREDICT_MAINNET_BASE,
59    PREDICT_TESTNET_BASE,
60};
61pub use execution::{
62    PredictExecConfig, PredictExecutionClient, PredictLimitOrderRequest, PredictSubmitResult,
63};
64pub use order::{
65    predict_exchange_address, predict_limit_order_amounts, PredictOrder, PredictOrderSigner,
66    PredictOutcome, PredictSide, PredictStrategy, SignedPredictOrder, BNB_MAINNET_CHAIN_ID,
67    BNB_TESTNET_CHAIN_ID,
68};
69pub use ws::{
70    AssetPriceUpdate, OrderbookSnapshot, PredictWsClient, PredictWsConfig, PredictWsMessage, Topic,
71    PREDICT_WS_MAINNET, PREDICT_WS_TESTNET,
72};