Skip to main content

Crate polyoxide

Crate polyoxide 

Source
Expand description

§polyoxide

Unified Rust client for Polymarket APIs, combining CLOB (trading), Gamma (market data), and Data APIs.

§Features

  • Unified access to CLOB, Gamma, and Data APIs
  • Type-safe API with idiomatic Rust patterns
  • EIP-712 order signing and HMAC authentication
  • Comprehensive market data and trading operations

§Example

use polyoxide::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Load account from environment variables
    let account = Account::from_env()?;

    // Create unified client
    let polymarket = Polymarket::builder(account)
        .chain(Chain::PolygonMainnet)
        .build()?;

    // Use Gamma API to list markets
    let markets = polymarket.gamma.markets()
        .list()
        .open(true)
        .limit(10)
        .send()
        .await?;

    // Use Data API to get user positions
    let positions = polymarket.data
        .user("0x1234567890123456789012345678901234567890")
        .list_positions()
        .limit(10)
        .send()
        .await?;

    for position in &positions {
        println!("Position: {} - size: {}", position.title, position.size);
    }

    // Use CLOB API to place an order
    if let Some(first_market) = markets.first() {
        if let Some(token) = first_market.tokens.first() {
            let order_params = CreateOrderParams {
                token_id: token.token_id.clone(),
                price: 0.52,
                size: 100.0,
                side: OrderSide::Buy,
                expiration: None,
                order_type: OrderKind::Gtc,
                post_only: false,
                funder: None,
                signature_type: Some(SignatureType::PolyProxy),
            };

            let response = polymarket.clob.place_order(&order_params, None).await?;
            println!("Order placed: {:?}", response.order_id);
        }
    }

    Ok(())
}

Re-exports§

pub use polyoxide_clob;
pub use polyoxide_data;
pub use polyoxide_gamma;

Modules§

prelude
Prelude module for convenient imports

Structs§

Polymarket
Unified Polymarket client
PolymarketBuilder
Builder for Polymarket client

Enums§

PolymarketError
Error types for Polymarket operations