Unofficial Node.js client for the DXtrade trading API with full TypeScript support. Connect, trade, and manage positions on any broker that supports DXtrade.
npm install dxtrade-api- Authentication & session management
- Submit orders (market, limit, stop)
- Get & cancel orders
- Positions (get, close, close all)
- Position metrics (per-position P&L)
- Account metrics, trade journal & trade history
- Symbol search & instrument info
- OHLC / price bar data (one-shot & streaming)
- PnL assessments
- Multi-broker support (FTMO, Eightcap, Lark Funding)
- Persistent WebSocket with
connect() - Real-time position streaming
- Full TypeScript support
- Batch orders
- Modify existing orders
- Real-time OHLC streaming
import { DxtradeClient, ORDER_TYPE, SIDE, BROKER } from "dxtrade-api";
const client = new DxtradeClient({
username: "your_username",
password: "your_password",
broker: BROKER.FTMO,
accountId: "optional_account_id",
});
// await client.auth(); // Auth only
await client.connect(); // Auth + persistent WebSocket (recommended)
const suggestions = await client.symbols.search("EURUSD");
const symbol = suggestions[0];
const order = await client.orders.submit({
symbol: symbol.name,
side: SIDE.BUY,
quantity: 0.01,
orderType: ORDER_TYPE.MARKET,
instrumentId: symbol.id,
});
console.log(`Order ${order.orderId}: ${order.status}`);
client.disconnect(); // disconnect stream -- only needed if client.connect()// 1. Persistent WebSocket (recommended) — reuses one WS for all data, enables streaming
await client.connect();
client.disconnect(); // when done
// 2. Lightweight — auth only, each data call opens a temporary WebSocket
await client.auth();| Option | Type | Required | Description |
|---|---|---|---|
username |
string |
Yes | DXtrade account username |
password |
string |
Yes | DXtrade account password |
broker |
string |
Yes | Broker identifier (e.g. "LARKFUNDING", "EIGHTCAP") |
accountId |
string |
No | Account ID to auto-switch after login |
brokerUrls |
Record<string, string> |
No | Custom broker URL mapping |
retries |
number |
No | Retry count for failed requests (default: 3) |
debug |
boolean | string |
No | Enable debug logging (true for all, or a WS message type to filter) |
callbacks |
DxtradeCallbacks |
No | Event callbacks |
import { BROKER } from "dxtrade-api";
BROKER.LARKFUNDING // "https://trade.gooeytrade.com"
BROKER.EIGHTCAP // "https://trader.dx-eightcap.com"
BROKER.FTMO // "https://dxtrade.ftmo.com"client.connect()— Auth + persistent WebSocket. Recommended for most use cases.client.auth()— Lightweight: login, fetch CSRF, WebSocket handshake, optional account switch. No persistent WS.client.disconnect()— Close the persistent WebSocket connectionclient.login()— Authenticate with brokerclient.fetchCsrf()— Fetch CSRF token from broker pageclient.switchAccount(accountId)— Switch to a specific account
client.positions.get()— Get all open positions with P&L metrics merged (margin, plOpen, marketValue, etc.)client.positions.close(params)— Close a position (supports partial closes via the quantity field)client.positions.closeAll()— Close all open positions with market ordersclient.positions.stream(callback)— Stream real-time position updates with live P&L (requiresconnect()). Returns an unsubscribe function.
client.orders.get()— Get all pending/open ordersclient.orders.submit(params)— Submit an order and wait for WebSocket confirmationclient.orders.cancel(orderChainId)— Cancel a single pending orderclient.orders.cancelAll()— Cancel all pending orders
client.account.metrics()— Get account metrics (equity, balance, margin, open P&L, etc.)client.account.tradeJournal({ from, to })— Fetch trade journal entries for a date range (Unix timestamps)client.account.tradeHistory({ from, to })— Fetch trade history for a date range (Unix timestamps)
client.symbols.search(text)— Search for symbolsclient.symbols.info(symbol)— Get instrument info (volume limits, lot size)client.symbols.limits()— Get order size limits and stop/limit distances for all symbols
client.instruments.get(params?)— Get all available instruments, optionally filtered by partial match (e.g.{ type: "FOREX" })
client.ohlc.get(params)— Fetch OHLC price bars for a symbol (resolution, range, maxBars, priceField)client.ohlc.stream(params, callback)— Stream real-time OHLC bar updates (requiresconnect()). Returns a promise that resolves with an unsubscribe function after the snapshot is received.
client.assessments.get(params)— Fetch PnL assessments for a date range
import { ORDER_TYPE, SIDE, ACTION, TIF } from "dxtrade-api";
ORDER_TYPE.MARKET | ORDER_TYPE.LIMIT | ORDER_TYPE.STOP
SIDE.BUY | SIDE.SELL
ACTION.OPENING | ACTION.CLOSING
TIF.GTC | TIF.DAY | TIF.GTDconst client = new DxtradeClient({
// ...
callbacks: {
onLogin: () => console.log("Logged in"),
onAccountSwitch: (id) => console.log(`Switched to ${id}`),
onOrderPlaced: (order) => console.log("Order placed", order),
onOrderUpdate: (update) => console.log("Order update", update),
onError: (err) => console.error(`[${err.code}] ${err.message}`),
},
});cp .env.example .env # fill in credentials
npm run example:connect
npm run example:debug
npm run example:positions:get
npm run example:positions:close
npm run example:positions:close-all
npm run example:positions:metrics
npm run example:positions:stream
npm run example:orders:submit
npm run example:account:metrics
npm run example:account:trade-journal
npm run example:account:trade-history
npm run example:symbols:info
npm run example:symbols:info:btc
npm run example:instruments:get
npm run example:instruments:get:forex
npm run example:ohlc:get
npm run example:ohlc:stream
npm run example:ohlc:stream:btc
npm run example:assessments:get
npm run example:assessments:get:btchttps://demo.dx.trade/developers/#/
MIT