Snapshot, then replay

  1. Read /v1/snapshot for public books, or /v1/me/snapshot with a session or read credential for your open orders, open fills and quote identities. Store its cursor with that state.
  2. Replay events after the cursor over HTTP or WebSocket.
  3. Apply each page in order, then persist your state and next_cursor together.
  • Each event carries its resource’s revision: skip revisions already applied.
  • Its data is rendered when it is published, never older than the snapshot it follows.
  • Events signal changes; a state can change more than once between two events.
  • Snapshot and event rows are summaries. Read GET /v1/orders/{id} for last_sequence, available_to_quote and quote_set before preparing a set.
  • Above 1,000 rows a snapshot answers 503 SNAPSHOT_TOO_LARGE: stop quoting. History pages cannot replace its cursor.
In TypeScript, changes does all three, WebSocket first and HTTP replay between connections.

HTTP replay

  • A page can hold zero events with has_more: true: each request scans at most 1,000 journal positions. Always continue from next_cursor.
  • Cursors are globally ordered decimal strings, with gaps between a subscriber’s events.
  • A cursor below the retained range or ahead of the journal answers 410 RESYNC_REQUIRED: replace local state from a fresh snapshot.

WebSocket

Connect to wss://api.lamarge.trade/v1/stream and send, within five seconds:
  • Omit token for public events only.
  • Frames have the HTTP page shape. The server sends a page at least every 500 ms, even if empty.
  • Any client message other than a ping or pong closes the stream, as does a frame that cannot be sent within five seconds. An invalid subscription closes it without a control frame.
A control frame with a reason can precede closure: After a disconnection, resume from the last processed page’s cursor, not the last received. Each balance.changed only says to refetch /v1/balances: a replay may omit a venue balance’s earlier ones that moved no funds, never its latest. Only the initial authentication counts against the request budget. During a stream outage, stop renewing quotes on stale state: let the lease expire, or cancel.

Event kinds

  • occurred_at is the originating change’s time.
  • Private streams include public events. A credential sees only its own identity’s orders, maker fills and lease.
  • Streams never carry bearers, transaction bytes, signatures or secrets.
A quoting bot reacts to:
  • order.changed not live, or with a null sequence: the order is off the book. Once it is live, reread it and publish a new set. A new cancel_epoch voids drafts prepared before it.
  • fill.changed with role: "maker": a reservation or its outcome changed the order’s inventory; reread the order before sizing the next set.
  • lease.changed with active: false: the lease lapsed, the credential ended or LaMarge disabled its quoting (renewal answers 403 FORBIDDEN). Renew the lease, which advances the generation, and publish again; or stop.
  • fill.changed for a Lighter or Aster pool with maker_accept_by set and maker_accepted_at null: accept it before maker_accept_by if you can deliver it; once PAID, deliver it (bot loop).
Keep your own timers for admission deadlines and reconcile periodically even while connected.

History

Order, fill, withdrawal and trade history pages use opaque backward cursors, unrelated to event cursors. Rows show current state: use GET /v1/orders/{id} or GET /v1/takes/{id} for signing and transaction details, and event replay for forward changes. GET /v1/takes/history, with a master session, pages whole takes with all their fills: use it for complete transfer receipts. GET /v1/fills lists only open fills and the last 50 final ones. A transfer’s take_final tells when its take has ended.