Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Types

Core types for orders, actions, and responses.

Order Types

OrderRequest

const OrderRequest = struct {
    asset: u32,              // Market index (0=BTC, 1=ETH, ...)
    is_buy: bool,
    limit_px: Decimal,       // Price as 38-digit decimal
    sz: Decimal,             // Size
    reduce_only: bool,
    order_type: OrderType,   // Limit, trigger, or market
    cloid: Cloid,            // Client order ID (optional)
};

OrderType

const OrderType = union(enum) {
    limit: struct { tif: TimeInForce },
    trigger: struct {
        trigger_px: Decimal,
        is_market: bool,
        tpsl: TpSl,
    },
};

TimeInForce

ValueMeaning
GtcGood-til-cancelled
IocImmediate-or-cancel
AloAdd-liquidity-only (post-only)
FrontendMarketMarket order (used internally)

BatchOrder

const BatchOrder = struct {
    orders: []const OrderRequest,
    grouping: OrderGrouping,  // .na, .normalTpSl, .positionTpSl
};

Response Types

All 62 response types live in response.zig. Key ones:

ClearinghouseState

const ClearinghouseState = struct {
    marginSummary: MarginSummary,
    crossMarginSummary: MarginSummary,
    assetPositions: []AssetPosition,
    // ... 
};

OpenOrder

const OpenOrder = struct {
    coin: []const u8,
    side: []const u8,
    limitPx: []const u8,
    sz: []const u8,
    oid: u64,
    // ...
};

Response Conventions

  • All fields use camelCase matching JSON keys exactly
  • All fields have defaults for forward compatibility: = "", = 0, = Decimal.ZERO
  • Parse options: { .ignore_unknown_fields = true, .allocate = .alloc_always }
  • Returned as Parsed(T) — call .deinit() to free

Decimal Type

Decimal is a 38-digit decimal type used for all prices and sizes:

const Decimal = hlz.math.decimal.Decimal;
 
const price = try Decimal.fromString("50000.5");
const size = try Decimal.fromString("0.001");
 
// Arithmetic
const total = price.mul(size);
 
// Format to string (stack buffer, no allocation)
var buf: [32]u8 = undefined;
const str = total.toString(&buf);

Outcome Types

OutcomeMeta

const OutcomeMeta = struct {
    outcomes: []OutcomeInfo,
    questions: []OutcomeQuestion,
};

OutcomeInfo

const OutcomeInfo = struct {
    outcome: u32,           // Outcome ID
    name: []const u8,       // e.g. "Recurring"
    description: []const u8, // e.g. "class:priceBinary|underlying:BTC|..."
    sideSpecs: []OutcomeSideSpec,
};

OutcomeQuestion

const OutcomeQuestion = struct {
    question: u32,
    name: []const u8,
    description: []const u8,
    fallbackOutcome: ?u32,
    namedOutcomes: []u32,
    settledNamedOutcomes: []u32,
};

RecurringEvent and parseRecurringEvent

Recurring outcome descriptions ship as a pipe-delimited bag like class:priceBinary|underlying:BTC|expiry:20260317-0300|targetPrice:74212|period:1d. Decode them with parseRecurringEvent(description):

const ev = response.parseRecurringEvent(outcome.description) orelse return;
// ev.underlying == "BTC", ev.target_price == 74212, ev.period == "1d"

Free-text descriptions and payloads missing any required key return null. Field slices alias the source description string and are only valid while it stays alive.

Asset Index Resolution

The SDK resolves human-readable asset names to numeric indices at runtime:

"BTC"        → asset index 0
"ETH"        → asset index 1
"PURR/USDC"  → spot market index (10000 + index)
"xyz:BTC"    → HIP-3 DEX market index (100000 + dex * 10000 + index)
"#12730"     → outcome market (100_000_000 + encoding)

This resolution uses the metadata from getMetaAndAssetCtxs(), getSpotMeta(), and getOutcomeMeta().