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.
Your WebSocket request needs to include these three headers:
| |
---|
| Your Gemini API session key |
| 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
}
|
| |
URL Parameters
| | | |
---|
| | | Optional symbol filter for order event subscription |
| | | Optional API session key filter for order event subscription |
| | | |
| | | 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
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})
Last modified on