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//! ## Modules
6//!
7//! - [`api`] — REST client for all 30 endpoints (BNB Chain mainnet + testnet)
8//! - [`ws`] — WebSocket client for real-time orderbook, price, and cross-venue feeds
9//! - [`order`] — EIP-712 order structs, signing, and amount calculation
10//! - [`execution`] — Auth → sign → submit pipeline with market metadata cache
11//!
12//! ## Quick Start
13//!
14//! ```rust,no_run
15//! use predict_fun_sdk::{PredictApiClient, PredictExecutionClient, PredictExecConfig};
16//! use predict_fun_sdk::ws::{PredictWsClient, PredictWsMessage, Topic};
17//! use predict_fun_sdk::order::BNB_MAINNET_CHAIN_ID;
18//!
19//! # async fn example() -> anyhow::Result<()> {
20//! // REST
21//! let client = PredictApiClient::new_mainnet("your-api-key")?;
22//! let markets = client.list_markets(&[("limit", "10".to_string())]).await?;
23//!
24//! // WebSocket
25//! let (ws, mut rx) = PredictWsClient::connect_mainnet().await?;
26//! ws.subscribe(Topic::Orderbook { market_id: 12345 }).await?;
27//!
28//! // Execution (with market metadata cache)
29//! let exec = PredictExecutionClient::new(PredictExecConfig {
30//!     api_key: "key".into(),
31//!     private_key: "0x...".into(),
32//!     chain_id: BNB_MAINNET_CHAIN_ID,
33//!     live_execution: false,
34//!     fill_or_kill: true,
35//! }).await?;
36//!
37//! // Pre-warm cache for markets you'll trade
38//! exec.preload_markets(&[12345, 67890]).await?;
39//! # Ok(())
40//! # }
41//! ```
42
43pub mod api;
44pub mod execution;
45pub mod order;
46pub mod ws;
47
48pub use api::{PredictApiClient, RawApiResponse, PREDICT_MAINNET_BASE, PREDICT_TESTNET_BASE};
49pub use execution::{
50    MarketMeta, PredictExecConfig, PredictExecutionClient, PredictLimitOrderRequest,
51    PredictSubmitResult,
52};
53pub use order::{
54    predict_exchange_address, predict_limit_order_amounts, PredictOrder, PredictOrderSigner,
55    PredictOutcome, PredictSide, PredictStrategy, SignedPredictOrder, BNB_MAINNET_CHAIN_ID,
56    BNB_TESTNET_CHAIN_ID,
57};
58pub use ws::{
59    AssetPriceUpdate, OrderbookSnapshot, PredictWsClient, PredictWsConfig, PredictWsMessage,
60    Topic, PREDICT_WS_MAINNET, PREDICT_WS_TESTNET,
61};