Skip to content

Server API Documentation

The Server API is a high-performance, persistent TCP connection designed specifically for real-time, high-throughput data streaming and server-to-server integration.

It delivers quotes, trade confirmations, margin updates, and notifications with minimal latency, making it the preferred choice for:

  • Back-office systems and CRM integrations
  • Risk-management and reporting services
  • Automated trading servers and liquidity bridges
  • Custom monitoring dashboards and analytics platforms
  • Desktop or server-side applications that require constant market data

Key advantages - Full-duplex streaming (quotes + events + commands in parallel) - Automatic reconnection and message queuing - Extremely low overhead compared to REST/WebSocket polling - Built-in JWT authentication and per-connection permissions - Ready-made client libraries for all major languages

Not for client trading terminals

This protocol is not intended for end-user trading platforms (MT4/MT5-style terminals).
For such cases use the dedicated Manager API or WebTrader API instead.


Quick Start

Ready plugins

These examples demonstrate connection, subscription/unsubscription, event handling, and a simple command (AddUser). All libraries handle reconnections and token auth automatically.

For full source code and installation, see the GitHub repositories.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Basic connectivity test (manual subscribe/unsubscribe not supported in nc)
# Use for quick server ping; replace with real host/token



### Quick Connect ###

# Using netcat (most common)
nc example.host 8080

# Using telnet
telnet example.host 8080

# Using socat (supports SSL, timeouts, etc.)
socat - TCP:example.host:8080

**Tip**: Use `nc -v` to see connection status: `nc -v example.host 8080`



### Common Commands ###

# Subscribe to quotes
echo '{"command":"Subscribe","data":{"chanels":["EURUSD","BTCUSD"]},"extID":"sub1","__token":"your-jwt-token"}\r\n' | nc example.host 8080

# Unsubscribe
echo '{"command":"Unsubscribe","data":{"chanels":["BTCUSD"]},"extID":"unsub1","__token":"your-jwt-token"}\r\n' | nc example.host 8080

# Create user
echo '{"command":"AddUser","data":{"group":"TestGroup","name":"John Doe","email":"[email protected]","password":"pass123","leverage":100,"enable":1},"extID":"adduser1","__token":"your-jwt-token"}\r\n' | nc example.host 8080



### Useful Tools ###

# Test connectivity
nc -zv example.host 8080

# View raw bytes (debug)
nc example.host 8080 | hexdump -C

GitHub: scaletrade-server-api — Node.js client with full event handling.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const STPlatform = require('scaletrade-server-api');

// Initialize with auto-subscribe to EURUSD and BTCUSD
const platform = new STPlatform(
    'example.host:8080',                        // Server host:port
    'scaletrade-js-demo',                       // Connection name for logs
    { autoSubscribe: ['EURUSD', 'BTCUSD'] },    // Auto-subscribe on connect
    null,                                       // Broker (optional)
    null,                                       // Context (optional)
    'your-jwt-auth-token'                       // JWT token (required)
);

// Subscribe to additional symbol (GBPUSD)
platform.subscribe('GBPUSD')
    .then(r => console.log('✓ Subscribed to GBPUSD:', r.data))
    .catch(err => console.error('✗ Subscribe failed:', err.message));

// Unsubscribe from BTCUSD after 10 seconds
setTimeout(() => {
    platform.unsubscribe('BTCUSD')
        .then(r => console.log('✓ Unsubscribed from BTCUSD:', r.data))
        .catch(err => console.error('✗ Unsubscribe failed:', err.message));
}, 10000);

// Create a new user account
platform.AddUser({
    group: 'TestGroup',
    name: 'John Doe',
    email: `john-${Date.now()}@example.com`,
    password: 'pass123',
    leverage: 100,
    enable: 1
})
    .then(res => console.log('✓ User created:', res.data?.login || res))
    .catch(err => console.error('✗ AddUser failed:', err.message));

// Event: real-time quotes (for subscribed symbols)
platform.emitter.on('quote', q => {
    console.log(`[QUOTE] ${q.symbol}: ${q.bid}/${q.ask} @ ${q.timestamp}`);
});

// Event: notifications (automatic, no subscribe needed)
platform.emitter.on('notify', n => {
    const levels = {10: 'INFO', 20: 'WARN', 30: 'ERROR', 40: 'PROMO'};
    console.log(`[NOTIFY:${levels[n.level] || n.level}] ${n.message} (Code: ${n.code})`);
});

// Graceful shutdown after 30 seconds
setTimeout(() => {
    console.log('Shutting down...');
    platform.destroy();
    process.exit(0);
}, 30000);

console.log('🚀 JS Demo started. Watch for quotes and events.');

GitHub: scaletrade-server-api-php — ReactPHP-based async client.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
require 'vendor/autoload.php';

use ScaleTrade\STPlatform;

$platform = new STPlatform(
    'example.host:8080',
    'scaletrade-php-demo',
    ['autoSubscribe' => ['EURUSD', 'BTCUSD']], // Auto-subscribe on connect
    null, null,
    'your-api-token'
);

// Event: real-time quotes
$platform->on('quote', function ($q) {
    printf("[QUOTE] %s: %.5f/%.5f @ %s\n", $q->symbol, $q->bid, $q->ask, $q->timestamp);
});

// Event: notifications
$platform->on('notify', function ($n) {
    $levels = [10=>'INFO', 20=>'WARN', 30=>'ERROR', 40=>'PROMO'];
    $lvl = $levels[$n->level] ?? $n->level;
    printf("[NOTIFY:%s] %s (Code: %d)\n", $lvl, $n->message, $n->code);
});

// Subscribe to additional symbol (GBPUSD)
$platform->subscribe('GBPUSD')
    ->then(fn($r) => printf("✓ Subscribed to GBPUSD: %s\n", json_encode($r->data)));

// Unsubscribe from BTCUSD after 10 seconds
$platform->loop->addTimer(10.0, function () use ($platform) {
    $platform->unsubscribe('BTCUSD')
        ->then(fn($r) => printf("✓ Unsubscribed from BTCUSD: %s\n", json_encode($r->data)));
});

// Create user
$platform->AddUser([
    'group'    => 'TestGroup',
    'name'     => 'John Doe',
    'email'    => 'john' . time() . '@example.com',
    'password' => 'pass123',
    'leverage' => 100,
    'enable'   => 1
])->then(
    fn($res) => printf("✓ User created: login %s\n", $res->data->login ?? 'unknown'),
    fn($e)   => printf("✗ AddUser error: %s\n", $e->getMessage())
);

// Auto shutdown after 30 seconds
$platform->loop->addTimer(30.0, fn() => $platform->destroy());

echo "🚀 PHP Demo started. Watch for quotes and events.\n";
$platform->loop->run();

GitHub: scaletrade-server-api-java — Netty-based high-performance client.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import com.scaletrade.STPlatform;
import java.util.List;
import java.util.Map;

public class Example {
    public static void main(String[] args) throws Exception {
        var platform = new STPlatform(
            "example.host:8080",
            "scaletrade-java-demo",
            Map.of("autoSubscribe", List.of("EURUSD", "BTCUSD")), // Auto-subscribe
            null, null,
            "your-api-token"
        );

        // Event: quotes
        platform.on("quote", q -> 
            System.out.printf("[QUOTE] %s: %.5f/%.5f @ %s%n", 
                q.get("symbol").asText(), q.get("bid").asDouble(), q.get("ask").asDouble(), q.get("timestamp").asText()));

        // Event: notifications
        platform.on("notify", n -> {
            String lvl = switch (n.get("level").asInt()) {
                case 10 -> "INFO"; case 20 -> "WARN"; case 30 -> "ERROR"; case 40 -> "PROMO";
                default -> String.valueOf(n.get("level").asInt());
            };
            System.out.printf("[NOTIFY:%s] %s (Code: %d)%n", lvl, n.get("message").asText(), n.get("code").asInt());
        });

        // Subscribe to GBPUSD
        platform.subscribe("GBPUSD")
            .thenAccept(r -> System.out.println("✓ Subscribed to GBPUSD: " + r));

        // Unsubscribe from BTCUSD after 10 seconds
        new Thread(() -> {
            try { Thread.sleep(10000); } catch (InterruptedException e) { }
            platform.unsubscribe("BTCUSD")
                .thenAccept(r -> System.out.println("✓ Unsubscribed from BTCUSD: " + r));
        }).start();

        // Create user
        platform.call("AddUser", Map.of(
            "group", "TestGroup",
            "name", "John Doe",
            "email", "john" + System.currentTimeMillis() + "@example.com",
            "password", "pass123",
            "leverage", 100,
            "enable", 1
        ))
        .thenAccept(r -> System.out.println("✓ User created: " + r));

        // Shutdown after 30 seconds
        Thread.sleep(30000);
        System.out.println("Shutting down...");
        platform.destroy();
    }
}

GitHub: scaletrade-server-api-csharp — .NET TCP client with async events.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ScaleTrade;

class Program
{
    static async Task Main()
    {
        var platform = new STPlatform(
            "example.host:8080",
            "scaletrade-csharp-demo",
            new Dictionary<string, object> { ["autoSubscribe"] = new[] { "EURUSD", "BTCUSD" } }, // Auto-subscribe
            null, null,
            "your-api-token"
        );

        // Event: quotes
        platform.Quote += (s, q) => 
            Console.WriteLine($"[QUOTE] {q.Symbol}: {q.Bid:F5}/{q.Ask:F5} @ {q.Timestamp}");

        // Event: notifications
        platform.Notify += (s, n) =>
        {
            var lvl = n.Level switch { 10 => "INFO", 20 => "WARN", 30 => "ERROR", 40 => "PROMO", _ => n.Level.ToString() };
            Console.WriteLine($"[NOTIFY:{lvl}] {n.Message} (Code: {n.Code})");
        };

        // Subscribe to GBPUSD
        await platform.SubscribeAsync("GBPUSD");
        Console.WriteLine("✓ Subscribed to GBPUSD");

        // Unsubscribe from BTCUSD after 10 seconds
        _ = Task.Delay(10000).ContinueWith(_ => {
            _ = platform.UnsubscribeAsync("BTCUSD").ContinueWith(t => {
                if (t.IsCompletedSuccessfully) Console.WriteLine("✓ Unsubscribed from BTCUSD");
            });
        });

        // Create user via dynamic proxy
        dynamic cmd = platform.Command;
        var user = await cmd.AddUser(new
        {
            group = "TestGroup",
            name = "John Doe",
            email = $"john{DateTimeOffset.Now.ToUnixTimeSeconds()}@example.com",
            password = "pass123",
            leverage = 100,
            enable = 1
        });
        Console.WriteLine("✓ User created: " + user);

        await Task.Delay(30000);
        Console.WriteLine("Shutting down...");
        platform.Dispose();
    }
}

GitHub: scaletrade-server-api-py — Asyncio-based Python client.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import asyncio
from st_platform import STPlatform

async def main():
    platform = STPlatform(
        url="example.host:8080",
        name="scaletrade-py-demo",
        options={"auto_subscribe": ["EURUSD", "BTCUSD"]}, # Auto-subscribe
        token="your-api-token"
    )

    # Event: quotes
    @platform.emitter.on("quote")
    def on_quote(q):
        print(f"[QUOTE] {q['symbol']}: {q['bid']:.5f}/{q['ask']:.5f} @ {q.get('timestamp', 'N/A')}")

    # Event: notifications
    @platform.emitter.on("notify")
    def on_notify(n):
        levels = {10: "INFO", 20: "WARN", 30: "ERROR", 40: "PROMO"}
        lvl = levels.get(n['level'], n['level'])
        print(f"[NOTIFY:{lvl}] {n['message']} (Code: {n['code']})")

    # Subscribe to GBPUSD
    resp = await platform.subscribe("GBPUSD")
    print(f"✓ Subscribed to GBPUSD: {resp.get('data', resp)}")

    # Unsubscribe from BTCUSD after 10 seconds
    async def unsubscribe_delayed():
        await asyncio.sleep(10)
        resp = await platform.unsubscribe("BTCUSD")
        print(f"✓ Unsubscribed from BTCUSD: {resp.get('data', resp)}")

    asyncio.create_task(unsubscribe_delayed())

    # Create user
    resp = await platform.add_user(
        group="TestGroup",
        name="John Doe",
        email=f"john{int(asyncio.get_event_loop().time())}@example.com",
        password="pass123",
        leverage=100,
        enable=1
    )
    print(f"✓ User created: {resp.get('data', resp)}")

    await asyncio.sleep(30)
    print("Shutting down...")
    platform.destroy()

asyncio.run(main())

GitHub: scaletrade-server-api-go — Go TCP client with goroutines for events.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main

import (
    "fmt"
    "time"
    st "github.com/ScaleTrade/server-api-go"
)

func main() {
    platform := st.NewSTPlatform(
        "example.host:8080",
        "scaletrade-go-demo",
        ion.Options{AutoSubscribe: []string{"EURUSD", "BTCUSD"}}, // Auto-subscribe
        nil, nil,
        "your-api-token",
    )
    defer platform.Destroy()

    // Event: quotes
    platform.Emitter.On("quote", func(data interface{}) {
        q := data.(map[string]interface{})
        fmt.Printf("[QUOTE] %s: %v/%v @ %v\n", q["symbol"], q["bid"], q["ask"], q["timestamp"])
    })

    // Event: notifications
    platform.Emitter.On("notify", func(data interface{}) {
        n := data.(map[string]interface{})
        level := "UNKNOWN"
        switch int(n["level"].(float64)) {
        case 10: level = "INFO"
        case 20: level = "WARN"
        case 30: level = "ERROR"
        case 40: level = "PROMO"
        }
        fmt.Printf("[NOTIFY:%s] %s (Code: %v)\n", level, n["message"], n["code"])
    })

    time.Sleep(2 * time.Second)
    if !platform.IsConnected() {
        fmt.Println("Not connected")
        return
    }

    // Subscribe to GBPUSD
    resp, _ := platform.Subscribe("GBPUSD")
    fmt.Printf("✓ Subscribed to GBPUSD: %+v\n", resp)

    // Unsubscribe from BTCUSD after 10 seconds
    go func() {
        time.Sleep(10 * time.Second)
        resp, _ := platform.Unsubscribe("BTCUSD")
        fmt.Printf("✓ Unsubscribed from BTCUSD: %+v\n", resp)
    }()

    // Create user
    resp, _ = platform.Call("AddUser", map[string]interface{}{
        "group":    "TestGroup",
        "name":     "John Doe",
        "email":    fmt.Sprintf("john%[email protected]", time.Now().Unix()),
        "password": "pass123",
        "leverage": 100,
        "enable":   1,
    })
    fmt.Printf("✓ User created: %+v\n", resp)

    time.Sleep(30 * time.Second)
    fmt.Println("Shutting down...")
}

The Commands class registers and processes over 100 different commands.
Below are the main groups of commands:

General API Overview

Welcome to the General API Reference.
This page provides a categorized overview of the main functionality of the server API.
Each section contains a short description and links to detailed documentation.