← Back to blog
TutorialsMar 8, 20265 min read

Build a Prediction Market Bot in 5 Minutes

A step-by-step tutorial for building a simple prediction market trading bot using the PAPI SDK and a few lines of code.

P
PAPI

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

  • A PAPI account with an API key (grab one from the dashboard)
  • Rust installed (we'll use the Rust SDK, but the concepts apply to any language)
  • 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 tokio

    Step 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.

    Ready to start building?

    Create an account and get your API key in under a minute.

    Create free account

    Related posts