A TypeScript SDK for interacting with the Gemini Cryptocurrency Exchange API. This SDK provides a simple interface for both REST and WebSocket APIs.
- 🔒 Secure authentication handling with nonce support
- 🌀 REST API support
- 🔄 Real-time WebSocket data streams
- 💪 Strongly typed responses
- 🎮 Sandbox environment support
npm install gemini-crypto-ts-sdk
To use the Gemini API, you'll need to generate API keys:
- Log in to your Gemini account at exchange.gemini.com
- Navigate to Settings > API
- Create a new API key pair
- Make sure to save both the API key and API secret securely
- Set appropriate permissions for your use case, this SDK supports using nonces.
import { Gemini } from 'gemini-crypto-ts-sdk';
// Initialize the client
const gemini = new Gemini({
apiKey: 'your-api-key',
apiSecret: 'your-api-secret',
mode: 'sandbox' // or 'live'
});
// REST API Examples
// Get ticker info
const ticker = await gemini.api.getTicker('btcusd');
// Place a new order
const order = await gemini.api.newOrder({
symbol: 'btcusd',
amount: '100',
price: '125000',
side: 'buy',
type: 'exchange limit',
options: ["immediate-or-cancel"]
});
// Get account balances
const balances = await gemini.api.getBalances();
// WebSocket Example - Market Data
gemini.socket({
endpoint: "/v2/marketdata/BTCUSD",
messageHandler: (data) => {
const message = JSON.parse(data.toString());
console.log('Market Data Update:', message);
},
subscriptions: [
{
type: "subscribe",
subscriptions: [{ name: "candles_1m", symbols: ["BTCUSD"] }],
},
],
});
// WebSocket Example - Order Events
gemini.socket({
endpoint: "/v1/order/events",
messageHandler: (data) => {
const message = JSON.parse(data.toString());
console.log('Order Event:', message);
},
});
This SDK provides a wrapper for endpoints documented in the Gemini REST API Documentation. It is not exhaustive, PRs are welcome.
Key features include:
- Market Data Order Management
- Account Management
- Trading
- Settlement
Real-time data streaming is available as documented in the Gemini WebSocket API Documentation.
Supported streams:
- Market Data
- Order Events
- Candles
- Trading
The SDK supports both production and sandbox environments:
// Sandbox Environment
const sandboxClient = new Gemini({
apiKey: 'sandbox-key',
apiSecret: 'sandbox-secret',
mode: 'sandbox'
});
// Production Environment
const productionClient = new Gemini({
apiKey: 'live-key',
apiSecret: 'live-secret',
mode: 'live'
});
The SDK provides detailed error information through the GeminiAPIError
class:
try {
await gemini.api.newOrder(/* ... */);
} catch (error) {
if (error instanceof GeminiAPIError) {
console.error('API Error:', error.message);
console.error('Error Code:', error.code);
}
}
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
See CHANGELOG.md for release history.