TypeScript SDK — Quickstart
Install the SDK, choose an entry point, and make your first request.
Install
Code
The package has two entry points. Pick the one that matches your runtime:
| Entry point | Import from | Use when |
|---|---|---|
| Server | gemini-markets/server | Node.js, Bun, Deno — API keys, HMAC signing, confidential OAuth, authenticated WebSocket |
| Browser | gemini-markets/browser | Frontend apps, Cloudflare Workers — public data, OAuth PKCE (no secrets) |
The server entry re-exports everything from the browser entry, so you never need both imports in one file.
Server — authenticated client
Code
createClient() is async on the server — it preloads the ws package for authenticated WebSocket support. If you only need REST, skip that overhead:
Code
Browser — public data
Code
For authenticated browser access (e.g. placing orders on behalf of a user), use OAuth PKCE. See Authentication.
Environments
The SDK supports two environments:
Code
Code
Warning: The default environment is production. If you omit
env, the SDK connects to live Gemini APIs with real money. Always passenv: "sandbox"during development and testing.
Get sandbox credentials at exchange.sandbox.gemini.com. See the sandbox guide for details.
Service namespaces
The client exposes every API surface as a typed namespace:
| Namespace | Description |
|---|---|
client.predictions | Prediction markets — events, orders, positions, combos |
client.marketData | Symbols, tickers, candles, order books, prices |
client.trading | Spot orders, trade history, volume |
client.margin | Margin account, rates, order preview |
client.perpetuals | Perpetual futures — positions, funding, risk |
client.accountServices | Balances, transfers, deposit addresses, staking |
client.clearingInstant | Clearing orders, quotes, brokers |
client.websocket | Real-time streams — trades, depth, orders, account |
Every method is fully typed. Use your IDE's autocomplete to explore parameters and responses — the types are generated from the OpenAPI specifications.
What's next
- Authentication — HMAC, OAuth, and browser PKCE setup
- WebSocket — real-time streams and live order books
- Error handling — error classes, diagnostics, and safe logging
- Patterns & recipes — pagination, timeouts, heartbeat, and advanced configuration
- REST API Reference — every operation across all namespaces
- WebSocket Reference — streams, methods, and wire format