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.
These examples demonstrate connection, subscription/unsubscription, event handling, and a simple command (AddUser). All libraries handle reconnections and token auth automatically.
# 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)
ncexample.host8080# Using telnet
telnetexample.host8080# Using socat (supports SSL, timeouts, etc.)
socat-TCP:example.host:8080
**Tip**:Use`nc-v`toseeconnectionstatus:`nc-vexample.host8080`### Common Commands #### Subscribe to quotesecho'{"command":"Subscribe","data":{"chanels":["EURUSD","BTCUSD"]},"extID":"sub1","__token":"your-jwt-token"}\r\n'|ncexample.host8080# Unsubscribeecho'{"command":"Unsubscribe","data":{"chanels":["BTCUSD"]},"extID":"unsub1","__token":"your-jwt-token"}\r\n'|ncexample.host8080# Create userecho'{"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'|ncexample.host8080### Useful Tools #### Test connectivity
nc-zvexample.host8080# View raw bytes (debug)
ncexample.host8080|hexdump-C
constSTPlatform=require('scaletrade-server-api');// Initialize with auto-subscribe to EURUSD and BTCUSDconstplatform=newSTPlatform('example.host:8080',// Server host:port'scaletrade-js-demo',// Connection name for logs{autoSubscribe:['EURUSD','BTCUSD']},// Auto-subscribe on connectnull,// 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 secondssetTimeout(()=>{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 accountplatform.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=>{constlevels={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 secondssetTimeout(()=>{console.log('Shutting down...');platform.destroy();process.exit(0);},30000);console.log('🚀 JS Demo started. Watch for quotes and events.');
<?phprequire'vendor/autoload.php';useScaleTrade\STPlatform;$platform=newSTPlatform('example.host:8080','scaletrade-php-demo',['autoSubscribe'=>['EURUSD','BTCUSD']],// Auto-subscribe on connectnull,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();
usingSystem;usingSystem.Collections.Generic;usingSystem.Threading.Tasks;usingScaleTrade;classProgram{staticasyncTaskMain(){varplatform=newSTPlatform("example.host:8080","scaletrade-csharp-demo",newDictionary<string,object>{["autoSubscribe"]=new[]{"EURUSD","BTCUSD"}},// Auto-subscribenull,null,"your-api-token");// Event: quotesplatform.Quote+=(s,q)=>Console.WriteLine($"[QUOTE] {q.Symbol}: {q.Bid:F5}/{q.Ask:F5} @ {q.Timestamp}");// Event: notificationsplatform.Notify+=(s,n)=>{varlvl=n.Levelswitch{10=>"INFO",20=>"WARN",30=>"ERROR",40=>"PROMO",_=>n.Level.ToString()};Console.WriteLine($"[NOTIFY:{lvl}] {n.Message} (Code: {n.Code})");};// Subscribe to GBPUSDawaitplatform.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 proxydynamiccmd=platform.Command;varuser=awaitcmd.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);awaitTask.Delay(30000);Console.WriteLine("Shutting down...");platform.Dispose();}}
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.