Want to build a bot that monitors prediction markets and places trades automatically? With PAPI, you can get one running in under five minutes. Let's walk through it.
Prerequisites
Step 1: Set Up Your Project
Create a new Rust project and add the PAPI SDK:
cargo new papi-bot && cd papi-bot
cargo add papi-sdk tokioStep 2: Connect to PAPI
Initialize the client with your API key:
use papi_sdk::PapiClient;
#[tokio::main]
async fn main() {
let client = PapiClient::new("your-api-key");
}Step 3: Fetch Markets
Search for markets you're interested in:
let markets = client
.markets()
.search("election")
.execute()
.await
.unwrap();
for market in &markets {
println!("{}: {}", market.title, market.last_price);
}Step 4: Place a Trade
When you find a market you like, place an order:
let order = client
.orders()
.create()
.market_id(&markets[0].id)
.side("yes")
.size(10.0)
.limit_price(0.65)
.execute()
.await
.unwrap();
println!("Order placed: {}", order.id);Step 5: Monitor Your Position
Check your positions across all exchanges:
let positions = client.positions().list().execute().await.unwrap();
for pos in &positions {
println!("{}: {} @ {}", pos.market_title, pos.size, pos.avg_price);
}Next Steps
From here, you could add WebSocket streaming for real-time prices, implement a simple strategy based on price thresholds, or expand to monitor multiple markets. Check the documentation for the full SDK reference.



