Margin trading
Margin trading on Gemini
Trade with leverage, monitor margin accounts, review tiered borrow rates, and preview pre-trade order impacts via Gemini REST and WebSocket APIs.
Margin Trading Operations
Access margin account summaries, check tiered borrow interest rates, and evaluate pre-trade leverage impact.
Inspect Margin & Preview Orders
Use account-scoped REST endpoints to monitor margin status and validate order risk prior to submission.
1. Fetch Account Summary
Query current initial margin, maintenance margin, and buying power.
# Fetch Margin Account Summary
import requests, hmac, hashlib, base64, time, json
API_KEY = "account-xxx"
API_SECRET = "secret-xxx"
URL = "https://api.gemini.com/v1/margin/account"
payload = {
"request": "/v1/margin/account",
"nonce": int(time.time() * 1000)
}
encoded_payload = base64.b64encode(json.dumps(payload).encode())
signature = hmac.new(API_SECRET.encode(), encoded_payload, hashlib.sha384).hexdigest()
headers = {
"Content-Type": "text/plain",
"Content-Length": "0",
"X-GEMINI-APIKEY": API_KEY,
"X-GEMINI-PAYLOAD": encoded_payload.decode(),
"X-GEMINI-SIGNATURE": signature,
}
response = requests.post(URL, headers=headers)
print(response.json())Spot Endpoints Supported for Margin Trading
Margin trading uses Gemini's core Spot order book and matching engine. You use the exact same Spot order endpoints, authenticated with a Margin-enabled account context.
New Order (`POST /v1/order/new`)
Supports MarginSubmit limit, market, IOC, and stop-limit orders using your margin account credentials or margin account context.
View Endpoint Reference →Cancel Order (`POST /v1/order/cancel`)
Supports MarginCancel resting margin orders on the shared Spot order matching engine.
View Endpoint Reference →Active & Past Orders (`POST /v1/orders`)
Supports MarginList open or historical margin orders and trades for the authenticated margin account.
View Endpoint Reference →WebSocket Order Events Stream
Supports MarginSubscribe to real-time margin fills, order cancellations, and margin liquidation notifications.
View WebSocket Reference →