Skip to main content

Crate limitless

Crate limitless 

Source
Expand description

§rs_limitless — Limitless Exchange API bindings for Rust

A strongly-typed Rust client library for the Limitless Exchange prediction market API. Covers both REST and WebSocket interfaces for browsing markets, trading prediction positions, managing portfolio data, and navigating the market hierarchy.

§Quick Start

use limitless::prelude::*;

#[tokio::main]
async fn main() -> Result<(), LimitlessError> {
    // Public endpoints — no API keys needed
    let api = LimitlessClient::builder().build()?;
    let active = api.browse_active(None, None, Some(5), None, None, None).await?;
    println!("Active markets: {}", active.total_markets_count);

    // Authenticated — creates `Trader`, `Portfolio`, `Stream` under the hood
    let api = LimitlessClient::builder()
        .set_credentials("lmts_sk_...", "your_base64_secret")
        .build()?;
    let positions = api.get_positions().await?;
    println!("CLOB positions: {}", positions.clob.len());

    // Place a GTC limit buy — signs + submits in one call
    let order = api.buy_gtc(
        "0xYourPrivateKey...",
        "btc-above-100k",
        "1234567890",  // token_id as decimal string
        0.55,          // price
        10.0,          // size
        42,            // owner_id (from GET /profiles/:address)
    ).await?;
    println!("Order placed: {}", order.order.id);

    Ok(())
}

§Feature Overview

ModuleTypeAuthDescription
MarketsRESTNoBrowse, search, market details, oracle data
TraderRESTYesOrders (GTC/FOK), orderbook, cancel, user orders
PortfolioRESTYesProfile, positions (AMM+CLOB), PnL, history, points
NavigationRESTNoNavigation tree, market pages, property keys/options
StreamWSVariesReal-time orderbook, prices, positions, transactions
Eip712SignerEIP-712 order signing (GTC, FOK)

§Crate Structure

limitless                    # Crate name (published as `rs_limitless`)
├── prelude::*              # Import everything in one go
├── LimitlessError          # Top-level error type
├── LimitlessClient         # Unified entry point (builder pattern)
├── Markets / Trader / Portfolio / Navigation / Stream  # Manager types
├── signing::Eip712Signer   # EIP-712 order signing
├── ws::channel             # WS channel enums & event payloads
└── models::order           # Order models, amount calculations, validation

§Authentication

The Limitless Exchange uses HMAC-SHA256 request signing. Pass credentials via the builder or create managers directly:

use limitless::prelude::*;

// Builder (reads LIMITLESS_API_KEY / LIMITLESS_API_SECRET from env)
let api = LimitlessClient::builder().build()?;

// Or explicit credentials:
let api = LimitlessClient::builder()
    .set_credentials("lmts_sk_...", "base64_secret")
    .build()?;

// Or use managers directly:
let trader = Trader::new(Some("key".into()), Some("secret".into()));

§EIP-712 Order Signing

CLOB orders (GTC / FOK) require an EIP-712 signature on-chain. Use the signing::Eip712Signer for direct control, or the convenience methods on Trader / LimitlessClient:

use limitless::prelude::*;
use limitless::signing::Eip712Signer;

let signer = Eip712Signer::new(
    "0xYourPrivateKey...",
    "0xVenueExchangeContract...",  // from GET /markets/:slug → venue.exchange
)?;

// Build + sign a GTC limit order
let order_data = signer.build_gtc_order(
    "0xYourWallet...",
    "1234567890",  // token_id
    OrderSide::Buy,
    0.55,
    10.0,
    0,  // fee_rate_bps
)?;

§WebSocket Streams

use limitless::prelude::*;
use serde_json::Value;
use tokio::sync::mpsc;

#[tokio::main]
async fn main() -> Result<(), LimitlessError> {
    let ws: Stream = Limitless::new(None, None);
    let (cmd_tx, cmd_rx) = mpsc::unbounded_channel();

    // Start event loop
    tokio::spawn(async move {
        let _ = ws.ws_subscribe_with_commands(cmd_rx, |event: Value| {
            println!("Event: {event}");
            Ok(())
        }).await;
    });

    // Subscribe to market prices
    let sub = r#"{"type":2,"data":["subscribe_market_prices",{"marketSlugs":["btc-above-100k"]}]}"#;
    cmd_tx.send(sub.to_string()).unwrap();

    Ok(())
}

For more details see the ws module and the websocket example.

§Feature Flags

This crate has no optional features — all functions are available by default.

Re-exports§

pub use prelude::*;

Modules§

prelude
The prelude module re-exports all commonly used types.
retry
Retry logic with exponential backoff for transient API failures.
signing
EIP-712 order signing for the Limitless Exchange CLOB.
ws