npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

api2trade-sdk

v1.0.0

Published

Official JavaScript/TypeScript SDK for the API2Trade MetaTrader REST API

Readme

API2Trade JavaScript / TypeScript SDK

Official JS/TS SDK for the API2Trade Metatrader API.
A robust API for Metatrader that lets you control your trading accounts programmatically from Node.js or the browser.
Build integrations, trading bots, and dashboards using this high-performance MT4 API and MT5 API — no MetaTrader terminal required.

npm version TypeScript License API Status Docs


Installation

# Using npm
npm install api2trade-sdk

# Using yarn
yarn add api2trade-sdk

# Using pnpm
pnpm add api2trade-sdk

60-Second Quickstart

import { Api2TradeClient, OrderType } from 'api2trade-sdk';

// Initialize with your API key from app.metatraderapi.dev
const client = new Api2TradeClient({ apiKey: 'YOUR_API_KEY' });

async function run() {
  // 1. Register your MT4/MT5 account
  const accountId = await client.accounts.register(
    '123456', 
    'BrokerPass', 
    'ICMarkets-Live01'
  );
  console.log(`Account UUID: ${accountId}`); // save this!

  // 2. Check live balance
  const summary = await client.accounts.summary(accountId);
  console.log(`Balance: ${summary.balance} ${summary.currency}`);
  console.log(`Equity:  ${summary.equity} ${summary.currency}`);

  // 3. Get a live quote
  const quote = await client.market.quote(accountId, 'EURUSD');
  console.log(`Ask: ${quote.ask}, Bid: ${quote.bid}`);

  // 4. Place a trade
  const result = await client.orders.send(
    accountId,
    'EURUSD',
    OrderType.BUY_MARKET,
    0.01,
    Number((quote.ask - 0.0020).toFixed(5)), // Stop Loss
    Number((quote.ask + 0.0040).toFixed(5))  // Take Profit
  );
  console.log(`Ticket: ${result.ticket}`);

  // 5. Close the trade
  await client.orders.close(accountId, result.ticket);
}

run().catch(console.error);

Configuration via Environment Variables

The SDK automatically picks up these environment variables if available in Node.js (e.g. via dotenv):

API2TRADE_API_KEY=sk-...
API2TRADE_BASE_URL=https://api.metatraderapi.dev    # optional
API2TRADE_WS_URL=wss://api.metatraderapi.dev/stream # optional
import { Api2TradeClient } from 'api2trade-sdk';
// Automatically uses process.env.API2TRADE_API_KEY
const client = new Api2TradeClient(); 

WebSocket Streaming

Receive real-time market data directly from the broker using our low-latency streaming client.

import { Api2TradeClient } from 'api2trade-sdk';

const client = new Api2TradeClient({ apiKey: 'YOUR_API_KEY' });

client.stream(
  'YOUR_ACCOUNT_ID',
  ['EURUSD', 'XAUUSD'],
  (tick) => {
    // Fired on every price update
    console.log(`${tick.symbol}: ${tick.bid} / ${tick.ask}`);
  },
  (error) => {
    console.error('Stream error:', error);
  },
  () => {
    console.log('Connected to stream!');
  }
);

Error Handling

The SDK provides specific, typed errors for common API rejections:

import { 
  Api2TradeClient, 
  BrokerRejectionError, 
  AuthenticationError 
} from 'api2trade-sdk';

const client = new Api2TradeClient();

try {
  await client.orders.send(accountId, 'EURUSD', 0, 0.01);
} catch (error) {
  if (error instanceof BrokerRejectionError) {
    console.log(`Broker rejected trade (Code: ${error.retcode}): ${error.comment}`);
  } else if (error instanceof AuthenticationError) {
    console.log('Invalid API key.');
  } else {
    console.error('Unknown API error:', error);
  }
}

Support

| Channel | Link | |---------|------| | 📧 Email | [email protected] | | 💬 Telegram | t.me/apisupport_en | | 📖 Docs | docs.metatraderapi.dev | | 🌐 Website | api2trade.com |


License

MIT — see LICENSE.


MetaTrader®, MT4®, and MT5® are trademarks of MetaQuotes Ltd. API2Trade is an independent service and is not affiliated with MetaQuotes Ltd.