For a deeper look into our Elektron API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles


1 1 1 2

node JS WSS connection timeout


I have been using the examples from the github repository:
Websocket-api NODE JS

The issue is that the socket connection does not open, but times out by default. I am using one with authentication and for the sake of simplicity, I have extracted temporary token from POSTMAN, and including that token directly in the new WS object. My code looks like below:

var WebSocket = require('ws')
var ip = require("ip");
var position = ip.address();
var testToken = // manually extracted token from POSTMAN
var appID = // app ID
var WS_URL = 'wss://';
console.log("Connecting to WebSocket " + WS_URL + " ...")
_websocket = new WebSocket(WS_URL, "tr_json2", {
    'headers':{'Cookie':"AuthToken=" + testToken + ";AuthPosition=" + position + ";applicationId=" + appID +";"}});
_websocket.onopen = onOpen;
_websocket.onclose = onClose;
_websocket.onerror = onError;

function onOpen(evt){
    console.log("WebSocket successfully connected!");

function onClose(evt){
    console.log("WebSocket Closed");

function onError(evt){

This is basicly a copy paste from the github repository node JS example, only with hardcoded values. If I run the code, it does not trigger any functions below, only the error one roughly 30 seconds after attempting to connect. My error message in TERMINAL :

$ node custom.js
Connecting to WebSocket wss:// ...
ErrorEvent {
   WebSocket {
     _events: { open: [Function], close: [Function], error: [Function] },
     _eventsCount: 3,
     _maxListeners: undefined,
     readyState: 2,
     protocol: '',
     _binaryType: 'nodebuffer',
     _closeFrameReceived: false,
     _closeFrameSent: false,
     _closeMessage: '',
     _closeTimer: null,
     _closeCode: 1006,
     _extensions: {},
     _isServer: false,
     _receiver: null,
     _sender: null,
     _socket: null,
     url: 'wss://',
     _req: null },
  type: 'error',
  message: 'connect ETIMEDOUT',
   { Error: connect ETIMEDOUT
       at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1161:14)
     errno: 'ETIMEDOUT',
     code: 'ETIMEDOUT',
     syscall: 'connect',
     address: '',
     port: 15000 } }
WebSocket Closed

My code, as I believe, is basicly a copy paste from the github functions in the official repo. Cant think anything where it breaks, or why am I getting refused. I generate a fresh token with POSTMAN, before sending it.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

18.1k 35 12 12

Hello @k1001

Firstly, The WS URL for TRKD should be wss:// (without port 15000), not wss:// .

Secondly, the Elektron WebSocket API supports the authentication via a JSON Login request message only. You cannot set TRKD authentication token via HTTP Header like TRKD JSON REST API. You need to set your username, application id and TRKD authentication token in the JSON login request message as following structure:

         "ApplicationId":"your TRKD application id",
         "AuthenticationToken":"Your TKRD Token",
         "Position":"<your position>"
      "Name":"Your TKRD username"

I have modified the market_price.js example and tested with my TRKD account. The application works

I connect to TRKD WebSocket server with this code:

var WS_URL_TRKD = 'wss://';
_websocket = new WebSocket(WS_URL_TRKD, "tr_json2");

Then I set my Login request message with the following code:

function onOpen(evt) {
    console.log("WebSocket successfully connected!");

    var msg = '{"ID":1,"Domain":"Login","Key":{"Name":"","NameType":"AuthnToken","Elements":{"ApplicationId":"","Position":"","AuthenticationToken":""}}}';

    var msgJson = JSON.parse(msg);
    msgJson.Key.Name = user
    msgJson.Key.Elements.ApplicationId = appId
    msgJson.Key.Elements.Position = position
    msgJson.Key.Elements.AuthenticationToken = testToken

    console.log(JSON.stringify(msgJson, null, 2));
} (3.2 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

17.6k 48 13 19

Seems to be the case of missing ping messages. Can you verify that your app receives ping message from server and responds with a pong message.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.