Node.js SDK Overview
The official ZenOTC SDK for Node.js and TypeScript. Build trading applications with full type safety and modern async/await syntax.
Installation
npm install zenotc
# or
pnpm add zenotc
# or
yarn add zenotc
Requirements
- Node.js 18.0 or higher
- TypeScript 5.0+ (optional, but recommended)
Quick Start
import { ZenOTCClient } from 'zenotc';
const client = new ZenOTCClient({
apiKey: 'your_api_key',
apiSecret: 'your_api_secret',
environment: 'sandbox', // or 'production'
});
// Create an order
const order = await client.execution.createOrder({
side: 'buy',
asset: 'BTC',
quantity: 1.0,
price: 50000,
});
console.log(`Order created: ${order.id}`);
Environment Variables
You can also initialize the client from environment variables:
// Reads ZENOTC_API_KEY, ZENOTC_API_SECRET, ZENOTC_ENVIRONMENT
const client = ZenOTCClient.fromEnv();
Set the following environment variables:
| Variable | Required | Description |
|---|---|---|
ZENOTC_API_KEY | Yes | Your API key |
ZENOTC_API_SECRET | Yes | Your API secret |
ZENOTC_ENVIRONMENT | No | production or sandbox (default: production) |
ZENOTC_BASE_URL | No | Override the base URL |
Configuration Options
const client = new ZenOTCClient({
apiKey: 'your_api_key',
apiSecret: 'your_api_secret',
environment: 'sandbox', // 'production' | 'sandbox'
timeout: 30000, // Request timeout in ms (default: 30000)
maxRetries: 3, // Max retry attempts (default: 3)
baseUrl: 'https://...', // Override base URL (optional)
});
Available Clients
The SDK provides specialized clients for different API domains:
| Client | Description |
|---|---|
client.execution | Order creation, cancellation, and status |
client.marketMaking | Quote submission and management |
client.marketData | Prices, order books, trading pairs |
client.portfolio | Balances, positions, exposure |
client.risk | Risk limits and pre-trade checks |
TypeScript Support
The SDK is written in TypeScript and exports all types:
import type {
Order,
Quote,
Balance,
CreateOrderParams,
OrderSide,
} from 'zenotc';
const params: CreateOrderParams = {
side: 'buy',
asset: 'BTC',
quantity: 1.0,
price: 50000,
};
Error Handling
import {
ZenOTCClient,
AuthenticationError,
ValidationError,
RateLimitError,
NotFoundError,
} from 'zenotc';
try {
const order = await client.execution.createOrder({...});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid API credentials');
} else if (error instanceof ValidationError) {
console.error('Validation failed:', error.fieldErrors);
} else if (error instanceof RateLimitError) {
console.error(`Rate limited. Retry after ${error.retryAfter}s`);
} else if (error instanceof NotFoundError) {
console.error('Resource not found');
} else {
throw error;
}
}
Next Steps
- Execution Client - Learn about order management
- Market Data Client - Access real-time market data
- Authentication - Understand the authentication flow