CCXT

The CCXT integration is in alpha and is not yet published to npm. Install directly from the branch (see below).

CCXT is an open-source library that provides a unified trading API across 100+ cryptocurrency exchanges. The dreamDEX integration lets you use the same familiar CCXT interface to interact with the DEX.

The source lives on the add-dreamdex-exchange branch of Somnia's CCXT fork. TypeScript source and built JavaScript are available; other CCXT-supported languages (Python, PHP, C#, Go) have not yet been generated.

Installation

Install directly from the branch:

bash
npm install github:somnia-chain/ccxt#add-dreamdex-exchange

REST API

typescript
import ccxt from 'ccxt';

const exchange = new ccxt.dreamdex({
    walletAddress: '0xYourAddress',
    privateKey: '0xYourPrivateKey',
});

// Public – no authentication required
const markets = await exchange.fetchMarkets();
const ticker = await exchange.fetchTicker('SOMI/USDC');
const orderBook = await exchange.fetchOrderBook('SOMI/USDC');
const trades = await exchange.fetchTrades('SOMI/USDC');
const candles = await exchange.fetchOHLCV('SOMI/USDC', '1h');

// Authenticated
const order = await exchange.createOrder('SOMI/USDC', 'limit', 'buy', 100, 1.5);
// → returns an unsigned EVM transaction to sign and broadcast

createOrder returns an unsigned EVM transaction ({ chainId, data, to, value }), not a confirmed order. You must sign and broadcast it to the Somnia network yourself — see the Quick Start guide for the full flow.

WebSocket (Pro)

typescript
import ccxt from 'ccxt';

const exchange = new ccxt.pro.dreamdex({
    walletAddress: '0xYourAddress',
    privateKey: '0xYourPrivateKey',
});

// Real-time order book
while (true) {
    const orderBook = await exchange.watchOrderBook('SOMI/USDC');
    console.log(orderBook.bids[0], orderBook.asks[0]);
}

Supported WebSocket methods: watchOrderBook, watchTrades, watchOHLCV.

Vault Operations

The integration exposes dreamDEX vault operations as additional methods. Each returns an unsigned transaction.

typescript
await exchange.vaultApprove('SOMI/USDC', 'SOMI', 100);
await exchange.vaultDeposit('SOMI/USDC', 'SOMI', 100);
await exchange.vaultWithdraw('SOMI/USDC', 'SOMI', 50);
const balance = await exchange.fetchBalance({ symbol: 'SOMI/USDC' });

Supported Methods

MethodDescription
fetchMarketsList available trading pairs
fetchCurrenciesList supported currencies
fetchOrderBookOrder book depth
fetchTickerTicker snapshot
fetchTradesRecent trades
fetchOHLCVCandlestick data
createOrderPrepare an order (returns unsigned tx)
fetchOrderGet order by ID
fetchOrdersList orders for a market
fetchOpenOrdersList open orders
cancelOrderCancel an order
fetchBalanceVault balances (requires params.symbol)
vaultApproveApprove token spending
vaultDepositDeposit into vault
vaultWithdrawWithdraw from vault