Gemini Crypto Exchange Logo
Order Events

WebSocket Request

wss://api.gemini.com/v1/order/events

Roles

The API key you use to access this endpoint must have the Trader or Auditor role assigned. See Roles for more information.

Note: Using a Master scoped API key receives event data for all accounts in the group.

Headers

Your WebSocket request needs to include these three headers:

Header

Value

X-GEMINI-APIKEY

Your Gemini API session key

X-GEMINI-PAYLOAD

Before base64-encoding, the JSON payload for the X-GEMINI-PAYLOAD header looks like this, where 123456 is a valid nonce value for your account.

{
   request: /v1/order/events,
   nonce: 123456
}
json

X-GEMINI-SIGNATURE

See Private API Invocation for an explanation of how to create the signature hash.

URL Parameters

Parameter

Type

Required?

Description

symbolFilter

string

N

Optional symbol filter for order event subscription

apiSessionFilter

string

N

Optional API session key filter for order event subscription

eventTypeFilter

string

N

Optional order event type filter for order event subscription

heartbeat

boolean

N

Optional filter to stream heartbeats. The default for this parameter is false.

Examples

Shell Example

npm install -g wscat
wscat -H X-GEMINI-PAYLOAD:your-payload \
 -H X-GEMINI-APIKEY:your-api-key \
 -H X-GEMINI-SIGNATURE:your-signature \
 --connect wss://api.gemini.com/v1/order/events
shell

Python Example

import ssl
import websocket
import json
import base64
import hmac
import hashlib
import time

def on_message(ws, message):
    print(message)

def on_error(ws, error):
    print(error)

def on_close(ws):
    print("### closed ###")

gemini_api_key = "mykey"
gemini_api_secret = "1234abcd".encode()

payload = {"request": "/v1/order/events","nonce": time.time()}
encoded_payload = json.dumps(payload).encode()
b64 = base64.b64encode(encoded_payload)
signature = hmac.new(gemini_api_secret, b64, hashlib.sha384).hexdigest()


ws = websocket.WebSocketApp("wss://api.gemini.com/v1/order/events?symbolFilter=btcusd&eventTypeFilter=fill&eventTypeFilter=closed&apiSessionFilter=UI&heartbeat=true",
                            on_message=on_message,
                            header={
                                'X-GEMINI-PAYLOAD': b64.decode(),
                                'X-GEMINI-APIKEY': gemini_api_key,
                                'X-GEMINI-SIGNATURE': signature
                            })
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
python