Skip to content

Exchange Clients

Arbiter-Bot integrates with two prediction market exchanges via their APIs.

Client Trait

Location: arbiter-engine/src/market/client/mod.rs

All exchange clients implement a common trait:

#[async_trait]
pub trait ExchangeClient: Send + Sync {
    async fn place_order(&self, order: OrderRequest) -> Result<FillDetails, ExecutionError>;
    async fn cancel_order(&self, order_id: Uuid) -> Result<(), ExecutionError>;
    async fn check_connectivity(&self) -> Result<(), ExecutionError>;
    fn get_name(&self) -> &str;
}

Polymarket Client

Location: arbiter-engine/src/market/client/polymarket.rs

Authentication

Uses EIP-712 typed data signing via alloy-signer-local:

  • Orders are signed with Ethereum private key
  • Signature included in order payload
  • Chain ID: 137 (Polygon)

API Integration

  • Endpoint: https://clob.polymarket.com/order
  • Method: POST with signed order JSON
  • Connectivity Check: GET /time

Order Structure

struct PolymarketOrder {
    salt: String,           // Random nonce
    maker: String,          // Wallet address
    signer: String,         // Signing address
    taker: String,          // Usually 0x0 (any taker)
    tokenId: String,        // Outcome token ID (256-bit)
    makerAmount: String,    // Amount in smallest units
    takerAmount: String,    // Price in smallest units
    expiration: String,     // Unix timestamp
    nonce: String,          // Order nonce
    feeRateBps: String,     // Fee rate in basis points
    side: String,           // "BUY" or "SELL"
    signatureType: u8,      // Signature type
    signature: String,      // EIP-712 signature
}

Kalshi Client

Location: arbiter-engine/src/market/client/kalshi.rs

Authentication

Uses RSA-PSS signatures with SHA-256:

  • Signature: timestamp + method + path
  • Headers include key ID, timestamp, and signature

API Integration

  • Endpoint: https://trading-api.kalshi.com/trade-api/v2/portfolio/orders
  • Method: POST with order JSON
  • Connectivity Check: GET /v2/exchange/status

Headers

KALSHI-ACCESS-KEY: <key_id>
KALSHI-ACCESS-TIMESTAMP: <unix_timestamp>
KALSHI-ACCESS-SIGNATURE: <base64_signature>

Dry Run Mode

Both clients support dry-run mode (--dry-run flag):

  1. Full signing - All cryptographic operations execute
  2. Payload logged - Signed JSON printed to stdout
  3. No submission - HTTP request skipped
  4. Simulated fill - Fake FillDetails returned

This enables testing the full signing pipeline without financial risk.

Mock Client

For testing, a mock client is available that:

  • Instantly fills orders
  • Can be configured to return specific failures
  • Used in unit tests for saga state machine