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

scaletrade-server-api

v1.0.11

Published

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.

Readme

ScaleTrade Server Api JS

Ultra-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.

Documentation · Examples · Report Bug


🎉 What's New in v1.0

| 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 |


Features

| 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 |


Installation

npm install scaletrade-server-api

Requirements:

  • Node.js >= 14.17.0 (for crypto.randomUUID support)
  • No external dependencies!

Quick Start

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: '[email protected]'
});

// Graceful shutdown
platform.destroy();

Supported Events

| 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], ...] |


API

Methods

| 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 |


Examples

Subscribe & Unsubscribe

// Single symbol
await platform.subscribe('GBPUSD');

// Multiple symbols
await platform.subscribe(['GBPUSD', 'USDJPY']);

// Unsubscribe
await platform.unsubscribe('BTCUSD');

Error Handling

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);
}

Get All Users

const users = await platform.GetUsers({});
console.log(users);

Listen to Balance Changes

platform.emitter.on('balance:event', e => {
  console.log(`User ${e.data.login}: Equity = ${e.data.equity}`);
});

// Listen to specific user
platform.emitter.on('balance:event:12345', e => {
  console.log('User 12345 balance updated');
});

Full Example

See example/example.js


Configuration

| 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) |


Performance Improvements

v0.1.5 vs v1.0

| 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 |


Migration from v0.1.5 vs v1.0

Changes

  1. Removed dependencies - No need to install shortid or jsonrepair
  2. Node.js requirement - Minimum version is now 14.17.0

No Code Changes Required!

Your existing code will work without modifications:

const STPlatform = require('scaletrade-server-api');
const platform = new STPlatform(/* ... */);

Advanced Usage

Custom Event Emitter

const EventEmitter = require('events');
const customEmitter = new EventEmitter();

const platform = new STPlatform(
  url, name, options, 
  null, null, token,
  customEmitter  // Use custom emitter
);

Connection Status Monitoring

setInterval(() => {
  if (platform.isConnected()) {
    console.log('✓ Connected');
  } else {
    console.log('✗ Disconnected - reconnecting...');
  }
}, 5000);

Graceful Shutdown

process.on('SIGINT', () => {
  console.log('Shutting down...');
  platform.destroy();
  process.exit(0);
});

Troubleshooting

Connection Issues

// Check connection status
console.log('Connected:', platform.isConnected());

// Monitor error count
platform.emitter.on('error', (err) => {
  console.error('Error:', err.message);
});

Memory Leaks

// v1.0 automatically limits seenNotifyTokens to 10,000 entries
// No manual cleanup needed!

// Optional: Monitor event listeners
console.log('Listeners:', platform.emitter.listenerCount('quote'));

Documentation


License

Distributed under the MIT License.
See LICENSE for more information.

Made with passion for high-frequency trading

scaletrade.com · GitHub