GeminiGemini
Demo environmentGet API key
  • Overview
  • Crypto Trading
  • Prediction Markets
  • Perpetuals
  • Stocks
  • API Reference
  • SDKs & Tools
Changelog
Gemini logoGemini logo

© 2026 Gemini Space Station, Inc.

TypeScript SDK — WebSocket Reference

Every WebSocket stream and method, with the exact payload field names. WebSocket messages use a compact wire format with single-letter field names — this page maps each letter to its meaning so you never need to inspect the source.

Public streams and controls are on client.websocket.public; authenticated streams and controls are on client.websocket.private in the server entry point. These are separate WebSocket connections: public frames never enter the authenticated session, and private operations are not available through the browser entry point. See the WebSocket guide for lifecycle, reconnection, and usage patterns.

Public streams

No authentication required. Each returns a WebSocketStream<T> you subscribe to with .on("message", …).

MethodPayload typeDescription
public.trades(symbol, options?)TradeReal-time trade prints
public.bookTicker(symbol, options?)BookTickerBest bid/ask updates
public.depthUpdates(symbol, options?)DepthUpdateIncremental order book diffs
public.depth(symbol, options)OrderBookSnapshotPeriodic top-N depth snapshots (options.levels: 5, 10, or 20)
public.contractStatus(options?)ContractStatusPrediction market contract status changes
public.rfqs(options?)RfqPublicEventPublic request-for-quote events (production beta; no authentication required)

Authenticated streams

Require an auth strategy and the server entry point (browser WebSocket cannot set upgrade headers).

MethodPayload typeDescription
private.orders(options)OrderUpdateOrder lifecycle updates (options.scope: "account" or "session")
private.balances(options?)BalanceUpdateBalance changes (options.intervalMs: 0 or 1000)
private.positions(options?)PositionReportPosition updates (options.intervalMs: 0 or 1000); terminal prediction-market settlement rows are available on the realtime stream
private.rfqDeliveries(options)RfqPrivateDeliveryPrivate RFQ delivery confirmations (options.scope) (production beta; quoting requires an eligible account)

intervalMs: 1000 selects positions@account@1s, a periodic snapshot of open positions. It does not include terminal settlement rows.

Request/response methods

These send a request and resolve with a response, rather than streaming.

MethodReturnsDescription
private.placeOrder(params, options?)OrderActionResponsePlace an order over WebSocket
private.cancelOrder(params, options?)OrderActionResponseCancel a single order
private.cancelAllOrders(options)OrderActionResponseCancel all orders (options.confirm must be true)
private.cancelSessionOrders(options)OrderActionResponseCancel session orders (options.confirm must be true)
public.ping(options?)GenericSuccessResponseRound-trip liveness check on the public connection
public.time(options?)GenericSuccessResponseServer time from the public connection
public.conninfo(options?)WebSocketJsonObjectConnection info for the public connection
public.listSubscriptions(options?)ListSubscriptionsResponseSubscriptions on the public connection
public.depthSnapshot(symbol, options?)DepthResponseOne-shot depth snapshot
private.conninfo(options?)WebSocketJsonObjectConnection info for the authenticated private connection
private.listSubscriptions(options?)ListSubscriptionsResponseSubscriptions on the authenticated private connection

RFQ quote methods

Availability: RFQ streams and methods are available in production for beta testing. Quoting requires an eligible account with the required capabilities.

Accessed via client.websocket.private.rfq on server clients:

MethodParamsReturns
private.rfq.submitQuote(params, options?)RfqSubmitQuoteParamsRfqSubmitQuoteResponse
private.rfq.withdrawQuote(params, options?)RfqWithdrawQuoteParamsRfqWithdrawQuoteResponse
private.rfq.confirmQuote(params, options?)RfqConfirmQuoteParamsRfqConfirmQuoteResponse

Wire format

WebSocket payloads use single-letter field names. These are the exact fields on each type. Prices and quantities are decimal strings (never floats — see Data Types); timestamps and IDs may be bigint.

Trade

Code
const trades = client.websocket.public.trades("BTCUSD"); trades.on("message", (t) => console.log(t.p, t.q, t.m));
FieldTypeMeaning
Enumber | bigintEvent time (nanoseconds)
sstringSymbol
tnumber | bigintTrade ID
pstringPrice
qstringQuantity
mbooleanWhether the buyer is the maker

BookTicker

FieldTypeMeaning
unumber | bigintUpdate ID
Enumber | bigintEvent time (nanoseconds)
sstringSymbol
bstringBest bid price
BstringBest bid quantity
astringBest ask price
AstringBest ask quantity
cstring?Last trade price (present once the book has traded)
Cstring?Last trade quantity

DepthUpdate

FieldTypeMeaning
e"depthUpdate"Event type discriminator
Enumber | bigintEvent time (nanoseconds)
sstringSymbol
Unumber | bigintFirst update ID in this diff
unumber | bigintLast update ID in this diff
bstring[][]Bid changes as [price, quantity] pairs
astring[][]Ask changes as [price, quantity] pairs

A quantity of "0" means the level was removed. See Order Book Reconstruction for how the SDK applies these.

OrderUpdate

Code
const orders = client.websocket.private.orders({ scope: "session" }); orders.on("message", (o) => console.log(o.i, o.X, o.z));
FieldTypeMeaning
e"orderUpdate"Event type discriminator
Enumber | bigintEvent time (nanoseconds)
sstringSymbol
inumber | bigintOrder ID
cstring?Client order ID. For RFQ maker fills, this is the clientId supplied to rfq.submit_quote, or Gemini's deterministic RFQ client order ID when omitted.
S"BUY" | "SELL" (optional)Side
o"LIMIT" | "MARKET" | "STOP_LIMIT" | "STOP_MARKET" (optional)Order type
X"NEW" | "OPEN" | "FILLED" | "PARTIALLY_FILLED" | "CANCELED" | "REJECTED" | "MODIFIED"Order status
O"YES" | "NO" (optional)Prediction outcome
pstring?Order price
Pstring?Stop price
qstring?Order quantity
zstring?Remaining quantity
Zstring?Executed quantity (last fill for FILLED/PARTIALLY_FILLED; cumulative for CANCELED and other terminal events)
Lstring?Last fill price
tnumber | bigint (optional)Trade ID of the last fill
nstring?Commission
mboolean?Whether this order was the maker
rstring?Reject reason
Tnumber | bigintTransaction time (nanoseconds)

BalanceUpdate

Code
const balances = client.websocket.private.balances(); balances.on("message", (u) => { for (const b of u.B) console.log(b.a, b.f, b.c); });
FieldTypeMeaning
e"balanceUpdate"Event type discriminator
Enumber | bigintEvent time (nanoseconds)
unumber | bigintUpdate ID
BBalance[]Balance entries

Each Balance:

FieldTypeMeaning
astringAsset
fstringFree (available) balance
cstringLocked balance

PositionReport

FieldTypeMeaning
e"positionReport"Event type discriminator
Enumber | bigintEvent time (nanoseconds)
unumber | bigintLast account-update timestamp (nanoseconds)
Anumber | bigintAccount reference
PPositionRow[]Position entries

Each PositionRow:

FieldTypeMeaning
tstringType
sstringSymbol
aNamedAmount[]Named amounts for the position

Each NamedAmount:

FieldTypeMeaning
tstringAmount label, such as position or settlement_payout
vstringDecimal amount; position quantities are signed
cstring?Optional asset code, such as usd for settlement payouts
o("YES" | "NO" | "UNSPECIFIED")?Settlement outcome on settlement_payout amounts

For a settled event-contract position, the terminal row includes a position amount with value "0" and a settlement_payout amount. The payout amount uses c: "usd" and includes o: "YES", "NO", or "UNSPECIFIED".

Terminal settlement rows are delivered only by the realtime positions@account stream. The one-second positions@account@1s stream reports open-position snapshots and omits those terminal rows.

ContractStatus

FieldTypeMeaning
e"contractStatus"Event type discriminator
Enumber | bigintEvent time (milliseconds)
sstringSymbol
kstringEvent ticker
cstringContract ticker
inumber | bigintContract ID
pstring?Price
ostringPrevious status
nstringNew status

What's next

  • Order Book Reconstruction — how depth diffs become a live book
  • RFQ Protocol — the request-for-quote maker flow
  • Data Types — why timestamps are bigint and prices are strings
On this page
  • Public streams
  • Authenticated streams
  • Request/response methods
    • RFQ quote methods
  • Wire format
    • Trade
    • BookTicker
    • DepthUpdate
    • OrderUpdate
    • BalanceUpdate
    • PositionReport
    • ContractStatus
  • What's next
TypeScript
TypeScript
TypeScript