predict-fun-sdk
Rust SDK for the Predict.fun prediction market API on BNB Chain.
Features
- Full REST API coverage — all 30 endpoints from the OpenAPI spec
- Real-time WebSocket feeds — orderbook snapshots, oracle prices, cross-venue data via
wss://ws.predict.fun/ws - EIP-712 order signing — native Rust via alloy, no ethers dependency
- Execution pipeline — auth → market lookup → sign → submit, with dry-run safety guard
- All 8 exchange contracts — mainnet + testnet × CTF/NegRisk/Yield/YieldNegRisk
- Amount math —
predict_limit_order_amountsmatches the official TypeScript SDK'sgetLimitOrderAmounts
Quick Start
use ;
use ;
use BNB_MAINNET_CHAIN_ID;
async
Environment Variables
| Variable | Required | Description |
|---|---|---|
PREDICT_API_KEY |
Yes | API key (request via Predict Discord) |
PREDICT_PRIVATE_KEY |
Yes | Hex private key for EIP-712 signing |
PREDICT_LIVE_EXECUTION |
No | Set to 1 to actually submit orders (default: 0 = dry-run) |
PREDICT_CHAIN_ID |
No | 56 (mainnet, default) or 97 (testnet) |
PREDICT_FILL_OR_KILL |
No | 1 (default) or 0 |
API Coverage
All 30 endpoints from the OpenAPI spec are covered:
Public — Markets, Orderbook, Timeseries, Categories, Tags, Search, Positions by address, Order matches
JWT-gated — Orders (create/list/cancel/get), Account, Activity, Positions, Yield pending
OAuth — Finalize, Orders (list/create/cancel), Positions
WebSocket Topics
| Topic | Auth | Update Rate | Data |
|---|---|---|---|
predictOrderbook/{marketId} |
None | On every change | Full orderbook snapshot (bids/asks, version, lastOrderSettled) |
assetPriceUpdate/{feedId} |
None | ~3-5/sec | Oracle price (feed 1=BTC, 4=ETH) |
polymarketChance/{marketId} |
None | On change | Cross-venue Polymarket probability |
kalshiChance/{marketId} |
None | On change | Cross-venue Kalshi probability |
predictWalletEvents/{jwt} |
JWT | On event | Fill/settlement notifications |
Architecture
predict_fun_sdk
├── api — REST client, endpoint specs, raw/typed request helpers
├── ws — WebSocket client with auto-reconnect, heartbeat, typed messages
├── order — EIP-712 structs, signing, amount math, exchange addresses
└── execution — High-level pipeline: auth → prepare → sign → submit
Exchange Contracts
| Network | Type | Address |
|---|---|---|
| Mainnet | CTF | 0x8BC070BEdAB741406F4B1Eb65A72bee27894B689 |
| Mainnet | NegRisk | 0x365fb81bd4A24D6303cd2F19c349dE6894D8d58A |
| Mainnet | Yield | 0x6bEb5a40C032AFc305961162d8204CDA16DECFa5 |
| Mainnet | YieldNegRisk | 0x8A289d458f5a134bA40015085A8F50Ffb681B41d |
References
- Predict.fun Dev Docs
- OpenAPI Explorer
- TypeScript SDK (reference implementation)
- Python SDK
License
MIT