mt5feed
v1.0.0
Published
Official JavaScript SDK for the mt5feed.com real-time metals & crypto price API
Maintainers
Readme
mt5feed
Official JavaScript SDK for the mt5feed.com real-time metals & crypto price API.
Installation
npm install mt5feedQuick Start
const { MT5Feed } = require('mt5feed');
const feed = new MT5Feed({ apiKey: 'your-api-key' });REST API
Get all prices
const prices = await feed.getPrices();
console.log(prices.XAUUSD.price); // 2345.67Get a single price
const gold = await feed.getPrice('XAUUSD');
console.log(gold.price); // 2345.67
console.log(gold.bid); // 2345.50
console.log(gold.ask); // 2345.84
console.log(gold.changePct); // 0.42
console.log(gold.high); // 2360.10
console.log(gold.low); // 2330.55WebSocket — Live Prices
Option 1 — inline callback (simplest)
feed.subscribe(['XAUUSD', 'BTCUSDT'], (data) => {
console.log(data.symbol, data.price);
});Option 2 — per-symbol events
feed.connect().subscribe(['XAUUSD', 'BTCUSDT']);
feed.on('tick:XAUUSD', (data) => console.log('Gold:', data.price));
feed.on('tick:BTCUSDT', (data) => console.log('Bitcoin:', data.price));Option 3 — single tick handler for all symbols
feed.connect().subscribe(['XAUUSD', 'XAGUSD', 'BTCUSDT', 'ETHUSDT']);
feed.on('tick', (data) => {
console.log(`${data.symbol}: ${data.price}`);
});Unsubscribe from a symbol
feed.unsubscribe('XAGUSD');Disconnect
feed.disconnect();Events
| Event | Payload | Description |
|---|---|---|
| connected | — | WebSocket connected |
| disconnected | reason: string | WebSocket disconnected |
| error | Error | Connection error |
| rate_limit | { code, limit, used } | Daily limit reached |
| tick | PriceData | Price tick (all symbols) |
| tick:SYMBOL | PriceData | Price tick for a specific symbol |
PriceData shape
{
symbol: string; // e.g. "XAUUSD"
price: number; // mid price
bid: number;
ask: number;
spread: number;
changePct: number; // % change from open
high: number; // day high
low: number; // day low
weekHigh: number;
weekLow: number;
display: string; // formatted display string
updatedAt: string; // ISO 8601 timestamp
}Error handling
// REST errors have a .status property
try {
const price = await feed.getPrice('XAUUSD');
} catch (err) {
console.error(err.message); // e.g. "Upgrade to Pro to access this pair"
console.error(err.status); // 403
}
// WebSocket errors
feed.on('error', (err) => console.error('WS error:', err.message));
// Rate limit reached
feed.on('rate_limit', ({ code, limit, used }) => {
console.warn(`Rate limit: ${used}/${limit} daily requests used`);
feed.disconnect();
});TypeScript
Full TypeScript types are included.
import { MT5Feed, PriceData } from 'mt5feed';
const feed = new MT5Feed({ apiKey: 'your-api-key' });
feed.on('tick:XAUUSD', (data: PriceData) => {
console.log(data.price);
});Available Symbols
| Symbol | Description |
|---|---|
| XAUUSD | Gold / US Dollar |
| XAGUSD | Silver / US Dollar |
| XPTUSD | Platinum / US Dollar |
| BTCUSDT | Bitcoin / Tether |
| ETHUSDT | Ethereum / Tether |
Symbol availability depends on your subscription plan.
Requirements
- Node.js 18+ (uses native
fetch) - An API key from mt5feed.com
