Skip to main content

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:

VariableRequiredDescription
ZENOTC_API_KEYYesYour API key
ZENOTC_API_SECRETYesYour API secret
ZENOTC_ENVIRONMENTNoproduction or sandbox (default: production)
ZENOTC_BASE_URLNoOverride 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:

ClientDescription
client.executionOrder creation, cancellation, and status
client.marketMakingQuote submission and management
client.marketDataPrices, order books, trading pairs
client.portfolioBalances, positions, exposure
client.riskRisk 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