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.

Overview
Spot
    OverviewGet started
    Orders API
    Market Data API
    Fund Management API
    Instant Orders API
    WebSocket API
      OverviewAuthenticationMessage FormatPublic & Private Streams
    FIX API
Margin
    Overview
    Margin REST API
      Get Margin Account SummaryGet Margin Interest RatesPreview Margin Order Impact
Staking
    Overview
    Staking REST API
      List Staking BalancesStake Crypto FundsUnstake Crypto FundsList Staking Event HistoryList Staking RatesList Staking Rewards
Clearing
    Clearing REST API
      Clearing Orders
      Broker & Trade Operations
AuthenticationMessage Format
Streams
    OverviewBook TickerL2 Partial DepthL2 Differential DepthTrade StreamOrder EventsBalance Updates
Utility
    conninfopingsubscribelist_subscriptionsunsubscribetime
L2 Data
    depth
Trading
    order.cancelorder.cancel_allorder.cancel_sessionorder.placerfq.confirm_quoterfq.createrfq.submit_quoterfq.withdraw_quote
WebSocket API

Authentication

Core APIShared across supported Gemini trading products.

The WebSocket API accepts either an HMAC-signed API key or an OAuth 2.0 bearer token on the connection upgrade. Pick whichever fits your app.

Generate an API Key

API keys for our WebSocket API have special requirements:

  1. Navigate to API Settings
  2. Click "Create API key"
  3. Scope: Select the account you want to trade with
  4. Settings:
    • ✅ Enable "Uses a time-based nonce"
    • ✅ Enable "Trading"
  5. Save your API key and secret securely

Only account-scoped keys with time-based nonces are accepted.


Create an Authenticated Connection

Pass the following headers when establishing the websocket connection,

HeaderValue
X-GEMINI-APIKEYYour Gemini API key (session key)
X-GEMINI-NONCECurrent epoch timestamp in seconds
X-GEMINI-SIGNATUREhex(HMAC_SHA384(base64(nonce), key=api_secret))
X-GEMINI-PAYLOADbase64(nonce)

Authentication is required for trading operations and order event subscriptions. Market data streams are available without authentication.

:::info Browser WebSocket Clients The standard browser WebSocket constructor (new WebSocket(url)) does not allow setting custom HTTP headers during the upgrade handshake. For browser-based applications, connect via backend proxy services or use query-string session authentication where supported. Node.js (ws), Python, Go, and native clients can supply standard HTTP headers during the handshake. :::

Authentication headers must be provided during the initial WebSocket handshake—you cannot authenticate after the connection is established.

Signature Generation Step-by-Step

Code
# Create a nonce from the current epoch time in seconds nonce = current_timestamp_in_seconds # Our payload will be the base64 encoded nonce for simplicity payload = base64_encode(nonce.toString) # Generate a signature using the hmac_sha384 algorithm signature = hmac_sha384(payload, api_secret) # Convert the signature to hex so it can be passed in the headers hexSignature = hex(signature)

Alternative: OAuth 2.0 Bearer Token

If your application uses OAuth 2.0 to access the Gemini API, you can authenticate the WebSocket connection with the same access token instead of provisioning an API key.

Pass the access token in the Authorization header on the WebSocket upgrade request:

HeaderValue
AuthorizationBearer <access_token>

When using OAuth, you do not send the X-GEMINI-APIKEY, X-GEMINI-NONCE, X-GEMINI-PAYLOAD, or X-GEMINI-SIGNATURE headers.

The access token must have scopes that cover the streams you intend to subscribe to (for example, orders:read for orders@account). See OAuth scopes.

Access tokens are short-lived (default 24 hours). If the token expires during a session, the server will close the connection and you must reconnect with a refreshed token — tokens cannot be rotated on a live connection. See Using Refresh Tokens.

OverviewMessage Format
On this page
  • Generate an API Key
  • Create an Authenticated Connection
    • Signature Generation Step-by-Step
  • Alternative: OAuth 2.0 Bearer Token