Skip to main content

Rust SDK

Installation

Add to your Cargo.toml:
[dependencies]
gimme-sdk = "0.1"
The crate will be published to crates.io soon. For now, use a git dependency:
gimme-sdk = { git = "https://github.com/J0xhen/gimme-fast", path = "sdks/rust" }

Quick Start

use gimme_sdk::GimmeClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = GimmeClient::new("gf_your_key_here");

    // List active markets
    let markets = client.list_markets(Some(true), None, None).await?;
    for market in &markets {
        println!("{}: {}", market.id, market.question);
    }

    // Get current price
    let price = client.get_price("token-id").await?;
    println!("Price: ${}, 24h volume: ${}", price.price, price.volume_24h);

    Ok(())
}

REST Client

Markets

// List markets with filters
let markets = client.list_markets(
    Some(true),       // active only
    Some("bitcoin"),  // search query
    Some(20),         // limit
).await?;

// Get a single market
let market = client.get_market("market-uuid").await?;

Trades

// Recent trades
let trades = client.list_trades(Some(50)).await?;

// Trades for a specific token
let token_trades = client.market_trades("token-id", Some(100)).await?;

Pricing

// Current price + 24h stats
let price = client.get_price("token-id").await?;

// OHLCV candles
let candles = client.get_candles("token-id", Some("1h"), Some(24)).await?;

Orderbook

let book = client.get_orderbook("token-id").await?;
if let Some(best_bid) = book.bids.first() {
    println!("Best bid: {} (size: {})", best_bid.price, best_bid.size);
}

WebSocket Client

use gimme_sdk::ws::{GimmeWebSocket, WsConfig, SubscriptionChannel};
use tokio_tungstenite::tungstenite::Message;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = WsConfig {
        api_key: "gf_your_key_here".into(),
        compress: true,
        ..Default::default()
    };

    let mut ws = GimmeWebSocket::connect(config).await?;

    // Subscribe to all trades
    ws.subscribe(SubscriptionChannel::Trades).await?;

    // Subscribe to a specific token
    ws.subscribe(SubscriptionChannel::TokenTrades {
        token_id: "21742633...".into(),
    }).await?;

    // Process events
    while let Some(event) = ws.next_event().await? {
        match event {
            WsEvent::Trade(trade) => {
                println!("{} {} @ {}", trade.side, trade.size, trade.price);
            }
            WsEvent::Resolution(res) => {
                println!("Resolved: {}", res.condition_id);
            }
            _ => {}
        }
    }

    Ok(())
}

Error Handling

use gimme_sdk::error::GimmeError;

match client.get_market("nonexistent").await {
    Ok(market) => println!("{}", market.question),
    Err(GimmeError::NotFound(msg)) => println!("Not found: {}", msg),
    Err(GimmeError::RateLimited) => println!("Slow down!"),
    Err(GimmeError::Unauthorized) => println!("Check your API key"),
    Err(e) => eprintln!("Error: {}", e),
}

Types

All API responses are deserialized into strongly-typed structs:
pub struct Market {
    pub id: String,
    pub condition_id: String,
    pub question: String,
    pub token_ids: Vec<String>,
    pub active: bool,
    pub resolved: bool,
}

pub struct Trade {
    pub id: String,
    pub tx_hash: String,
    pub block_number: i64,
    pub token_id: String,
    pub side: String,
    pub price: String,
    pub size: String,
    pub maker: String,
    pub taker: String,
}

pub struct TokenPricing {
    pub token_id: String,
    pub price: String,
    pub volume_24h: String,
    pub change_24h: String,
    pub complement_price: String,
}

Configuration

let client = GimmeClient::builder()
    .api_key("gf_your_key")
    .base_url("https://api.gimme.fast") // Custom URL (optional)
    .build()?;