High-performance TCP client for ScaleTrade — ultra-low latency server-to-server integration with real-time quotes, trade events, balance updates, and full symbol/user management.
npm install scaletrade-server-apiUltra-low latency Node.js TCP client for ScaleTrade
Real-time market data, trade execution, balance & user management via TCP.
!npm
!Node.js
!License
!Downloads
!Zero Dependencies
> Server-to-Server (S2S) integration — ideal for brokers, CRMs, HFT bots, and back-office systems.
---
| Feature | Description |
|---------|-------------|
| Zero Dependencies | Removed shortid and jsonrepair - pure Node.js stdlib only! |
| Native crypto.randomUUID() | Uses built-in crypto for ID generation (Node 14.17+) |
| Improved Error Handling | Better reconnection logic with exponential backoff |
| Promise-based Responses | More reliable response handling with Map storage |
| Memory Management | Automatic cleanup of seen tokens (10k limit) |
| Better Connection Recovery | Stops after 10 consecutive errors |
| Performance | 15-20% faster without external dependencies |
---
| Feature | Description |
|-------|-------------|
| TCP S2S | Direct TCP connection — no HTTP overhead |
| Real-time Events | Quotes, trades, balance, user & symbol updates |
| Optimized Subscribe | platform.subscribe() / unsubscribe() |
| Dynamic Commands | platform.AddUser({}), platform.GetTrades() |
| Auto-reconnect | Robust reconnection with exponential backoff |
| Event Filtering | ignoreEvents, per-symbol listeners |
| extID Tracking | Reliable command responses |
| Zero Dependencies | Pure Node.js - no external packages needed |
---
``bash`
npm install scaletrade-server-api
Requirements:
- Node.js >= 14.17.0 (for crypto.randomUUID support)
- No external dependencies!
---
`js
const STPlatform = require('scaletrade-server-api');
// Initialize with minimal config
const platform = new STPlatform(
'broker.scaletrade.com:8080', // Host:port
'my-trading-bot',
{ autoSubscribe: ['EURUSD', 'BTCUSD'] },
null, null,
'your-jwt-auth-token'
);
// Real-time quotes
platform.emitter.on('quote', q => {
console.log(${q.symbol}: ${q.bid}/${q.ask});
});
// Trade events
platform.emitter.on('trade:event', e => {
const d = e.data;
console.log(#${d.order} ${d.cmd === 0 ? 'BUY' : 'SELL'} ${d.volume} ${d.symbol});
});
// Subscribe to new symbol
await platform.subscribe('XAUUSD');
// Create user
await platform.AddUser({
name: 'John Doe',
group: 'VIP',
leverage: 500,
email: 'john@example.com'
});
// Graceful shutdown
platform.destroy();
`
---
| Event | Description | Example |
|------|-------------|--------|
| quote | Real-time tick | { symbol: 'EURUSD', bid: 1.085, ask: 1.086 } |quote:SYMBOL
| | Per-symbol | quote:EURUSD |notify
| | System alerts | notify:20 (warning) |trade:event
| | Order open/close/modify | data.order, data.profit |balance:event
| | Balance & margin update | data.equity, data.margin_level |user:event
| | User profile change | data.leverage, data.group |symbol:event
| | Symbol settings update | data.spread, data.swap_long |group:event
| | Group config change | data.default_leverage |symbols:reindex
| | Symbol index map | [[symbol, sym_index, sort_index], ...] |security:reindex
| | Security group map | [[sec_index, sort_index], ...] |
---
| Method | Description |
|-------|-------------|
| subscribe(channels) | Fast subscribe to symbols |unsubscribe(channels)
| | Fast unsubscribe |platform.CommandName(data)
| | Dynamic command (e.g., AddUser) |platform.send(payload)
| | Legacy format: { command, data } |platform.destroy()
| | Close connection |platform.isConnected()
| | Check connection status |
---
`js
// Single symbol
await platform.subscribe('GBPUSD');
// Multiple symbols
await platform.subscribe(['GBPUSD', 'USDJPY']);
// Unsubscribe
await platform.unsubscribe('BTCUSD');
`
`js`
try {
const user = await platform.AddUser({ name: 'Test' });
if (user.status === 200) {
console.log('✓ Success:', user.data);
} else {
console.error('✗ Failed:', user);
}
} catch (err) {
console.error('❌ Error:', err.message);
}
`js`
const users = await platform.GetUsers({});
console.log(users);
`jsUser ${e.data.login}: Equity = ${e.data.equity}
platform.emitter.on('balance:event', e => {
console.log();
});
// Listen to specific user
platform.emitter.on('balance:event:12345', e => {
console.log('User 12345 balance updated');
});
`
---
| Option | Type | Default | Description |
|-------|------|----------|-------------|
| autoSubscribe | string[] | [] | Auto-subscribe on connect |ignoreEvents
| | boolean | false | Disable all event emission |mode
| | 'live' \| 'demo' | 'live' | Environment mode |prefix
| | string | 'nor' | Event prefix (reserved) |
---
| Metric | v0.1.5 | v1.0 | Improvement |
|--------|------|--------|-------------|
| Dependencies | 2 | 0 | 100% reduction |
| Install size | ~500KB | ~10KB | 98% smaller |
| Startup time | ~120ms | ~50ms | 58% faster |
| Memory usage | ~15MB | ~8MB | 47% less |
| extID generation | 5.2M/s | 7.6M/s | 46% faster |
---
1. Removed dependencies - No need to install shortid or jsonrepair
2. Node.js requirement - Minimum version is now 14.17.0
Your existing code will work without modifications:
`js`
const STPlatform = require('scaletrade-server-api');
const platform = new STPlatform(/ ... /);
---
`js
const EventEmitter = require('events');
const customEmitter = new EventEmitter();
const platform = new STPlatform(
url, name, options,
null, null, token,
customEmitter // Use custom emitter
);
`
`js`
setInterval(() => {
if (platform.isConnected()) {
console.log('✓ Connected');
} else {
console.log('✗ Disconnected - reconnecting...');
}
}, 5000);
`js`
process.on('SIGINT', () => {
console.log('Shutting down...');
platform.destroy();
process.exit(0);
});
---
`js
// Check connection status
console.log('Connected:', platform.isConnected());
// Monitor error count
platform.emitter.on('error', (err) => {
console.error('Error:', err.message);
});
`
`js
// v1.0 automatically limits seenNotifyTokens to 10,000 entries
// No manual cleanup needed!
// Optional: Monitor event listeners
console.log('Listeners:', platform.emitter.listenerCount('quote'));
`
---
- TCP API: https://scaletrade.com/tcp
- Client API: https://scaletrade.com/client-api
- FIX API: https://scaletrade.com/fix-api
---
Distributed under the MIT License.
See LICENSE` for more information.
Made with passion for high-frequency trading