or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

error-handling.mdexchange-management.mdindex.mdmarket-data.mdprecision.mdtrading.mdutilities.mdwebsocket.md
tile.json

index.mddocs/

CCXT - Cryptocurrency Trading Library

CCXT is a comprehensive cryptocurrency trading library that provides unified APIs for connecting to 100+ cryptocurrency exchanges and payment processing services worldwide. It supports multiple programming languages and offers both public market data access and private trading functionality, enabling developers to build trading algorithms, perform analytics, and create automated trading systems.

Package Information

  • Package Name: ccxt
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install ccxt

Core Imports

import ccxt from 'ccxt';
// or import specific exchanges and utilities
import { binance, Exchange, Precise } from 'ccxt';

CommonJS:

const ccxt = require('ccxt');
// or destructured
const { binance, Exchange, Precise } = require('ccxt');

Basic Usage

import ccxt from 'ccxt';

// Create exchange instance
const exchange = new ccxt.binance({
  apiKey: 'your-api-key',
  secret: 'your-secret',
  sandbox: true, // use testnet for testing
});

// Fetch market data
const markets = await exchange.loadMarkets();
const ticker = await exchange.fetchTicker('BTC/USDT');
const orderbook = await exchange.fetchOrderBook('BTC/USDT');
const trades = await exchange.fetchTrades('BTC/USDT');

// Trading operations (requires API credentials)
const balance = await exchange.fetchBalance();
const order = await exchange.createLimitBuyOrder('BTC/USDT', 0.001, 50000);
const orderStatus = await exchange.fetchOrder(order.id, 'BTC/USDT');
await exchange.cancelOrder(order.id, 'BTC/USDT');

Architecture

CCXT is built around several key components:

  • Exchange Base Class: Abstract base class that all exchange implementations extend, providing common functionality and unified interface
  • Exchange Implementations: 100+ concrete exchange classes that inherit from the base class and implement exchange-specific logic
  • Unified API: Consistent method signatures and data structures across all exchanges for seamless multi-exchange development
  • WebSocket Support: Real-time streaming capabilities through the pro module for live data feeds
  • Precision Arithmetic: Precise class for handling high-precision financial calculations without floating-point errors
  • Error Hierarchy: Comprehensive error classification system for proper error handling and debugging
  • Utility Functions: Common helpers for data manipulation, formatting, authentication, and market operations

Capabilities

Exchange Management

Instantiate and configure exchange connections with unified interface across 100+ supported exchanges.

// Exchange classes - each extends the base Exchange class
class Exchange {
  constructor(config?: ExchangeConfig);
}

interface ExchangeConfig {
  apiKey?: string;
  secret?: string;
  uid?: string;
  login?: string;
  password?: string;
  privateKey?: string;
  walletAddress?: string;
  token?: string;
  sandbox?: boolean;
  timeout?: number;
  rateLimit?: number;
  enableRateLimit?: boolean;
  verbose?: boolean;
  proxy?: string;
  userAgent?: string;
}

Exchange Management

Market Data Access

Fetch public market information including tickers, order books, trades, and OHLCV data from any supported exchange.

loadMarkets(reload?: boolean, params?: object): Promise<Dictionary<Market>>;
fetchTicker(symbol: string, params?: object): Promise<Ticker>;
fetchOrderBook(symbol: string, limit?: number, params?: object): Promise<OrderBook>;
fetchTrades(symbol: string, since?: number, limit?: number, params?: object): Promise<Trade[]>;
fetchOHLCV(symbol: string, timeframe?: string, since?: number, limit?: number, params?: object): Promise<OHLCV[]>;

Market Data

Trading Operations

Execute trading operations including order placement, modification, cancellation, and account management.

fetchBalance(params?: object): Promise<Balances>;
createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: number, params?: object): Promise<Order>;
cancelOrder(id: string, symbol?: string, params?: object): Promise<Order>;
fetchOrder(id: string, symbol?: string, params?: object): Promise<Order>;
fetchOrders(symbol?: string, since?: number, limit?: number, params?: object): Promise<Order[]>;
fetchMyTrades(symbol?: string, since?: number, limit?: number, params?: object): Promise<Trade[]>;

Trading

WebSocket Streaming

Real-time data streaming capabilities for live market data and trading updates.

watchTicker(symbol: string, params?: object): Promise<Ticker>;
watchOrderBook(symbol: string, limit?: number, params?: object): Promise<OrderBook>;
watchTrades(symbol: string, since?: number, limit?: number, params?: object): Promise<Trade[]>;
watchOHLCV(symbol: string, timeframe?: string, since?: number, limit?: number, params?: object): Promise<OHLCV[]>;
watchBalance(params?: object): Promise<Balances>;
watchOrders(symbol?: string, since?: number, limit?: number, params?: object): Promise<Order[]>;

WebSocket Streaming

Precision Arithmetic

High-precision arithmetic operations for accurate financial calculations without floating-point errors.

class Precise {
  constructor(number: bigint | string, decimals?: number);
  mul(other: Precise): Precise;
  div(other: Precise, precision?: number): Precise;
  add(other: Precise): Precise;
  sub(other: Precise): Precise;
  toString(): string;
  equals(other: any): boolean;
}

Precision Arithmetic

Utility Functions

Common utility functions for data manipulation, formatting, authentication, and cryptocurrency operations.

// Generic utilities
function keys(object: object): string[];
function values(object: object): any[];
function extend(...objects: object[]): object;
function clone(object: any): any;

// String utilities  
function capitalize(string: string): string;
function strip(string: string): string;

// Number utilities
function precisionFromString(string: string): number;
function decimalToPrecision(number: number, roundingMode: number, precision: number): string;

// Time utilities
function iso8601(timestamp: number): string;
function parse8601(string: string): number;
function timeout(ms: number, promise: Promise<any>): Promise<any>;

// Cryptographic utilities
function hmac(message: string, secret: string, algorithm: string, digest?: string): string;
function hash(message: string, algorithm: string, digest?: string): string;
function jwt(request: object, secret: string, algorithm?: string): string;

Utilities

Error Handling

Comprehensive error classification system for proper error handling and debugging in trading applications.

class BaseError extends Error {}
class ExchangeError extends BaseError {}
class AuthenticationError extends ExchangeError {}
class InsufficientFunds extends ExchangeError {}
class InvalidOrder extends ExchangeError {}
class OrderNotFound extends ExchangeError {}
class NetworkError extends BaseError {}
class RateLimitExceeded extends NetworkError {}

Error Handling

Core Types

interface Market {
  id: string;
  symbol: string;
  base: string;
  quote: string;
  baseId: string;
  quoteId: string;
  active: boolean;
  type: MarketType;
  spot: boolean;
  margin: boolean;
  swap: boolean;
  future: boolean;
  option: boolean;
  contract: boolean;
  settle?: string;
  settleId?: string;
  contractSize?: number;
  linear?: boolean;
  inverse?: boolean;
  expiry?: number;
  expiryDatetime?: string;
  strike?: number;
  optionType?: string;
  precision: {
    amount: number;
    price: number;
    cost?: number;
  };
  limits: {
    amount?: MinMax;
    cost?: MinMax;
    leverage?: MinMax;
    price?: MinMax;
  };
  info: any;
}

interface Ticker {
  symbol: string;
  info: any;
  timestamp?: number;
  datetime?: string;
  high?: number;
  low?: number;
  bid?: number;
  bidVolume?: number;
  ask?: number;
  askVolume?: number;
  vwap?: number;
  open?: number;
  close?: number;
  last?: number;
  previousClose?: number;
  change?: number;
  percentage?: number;
  average?: number;
  baseVolume?: number;
  quoteVolume?: number;
}

interface OrderBook {
  symbol: string;
  bids: [number, number][];
  asks: [number, number][];
  timestamp: number;
  datetime: string;
  nonce?: number;
}

interface Trade {
  info: any;
  amount: number;
  datetime: string;
  id: string;
  order?: string;
  price: number;
  timestamp: number;
  type?: string;
  side: OrderSide;
  symbol: string;
  takerOrMaker?: string;
  cost: number;
  fee?: Fee;
}

interface Order {
  info: any;
  id: string;
  clientOrderId?: string;
  datetime: string;
  timestamp: number;
  lastTradeTimestamp?: number;
  symbol: string;
  type: OrderType;
  timeInForce?: string;
  amount: number;
  filled: number;
  remaining: number;
  cost: number;
  average?: number;
  price?: number;
  side: OrderSide;
  status: OrderStatus;
  fee?: Fee;
  trades?: Trade[];
  fees?: Fee[];
}

interface Balance {
  free: number;
  used: number;
  total: number;
}

interface Balances {
  info: any;
  [currency: string]: Balance;
}

type OrderSide = 'buy' | 'sell';
type OrderType = 'limit' | 'market';
type OrderStatus = 'open' | 'closed' | 'canceled' | 'expired' | 'rejected';
type MarketType = 'spot' | 'margin' | 'swap' | 'future' | 'option' | 'delivery' | 'index';

interface MinMax {
  min: number;
  max: number;
}

interface Fee {
  currency: string;
  cost: number;
  rate?: number;
}

type OHLCV = [number, number, number, number, number, number?];

interface Dictionary<T> {
  [key: string]: T;
}