WebSocket console

TickTrader Feeder WebSocket API

TickTrader Feeder WebSocket API is used to connect to the TickTrader Server using secure web sockets technology (wss://) to get feed information (currencies, symbols) and subscribe to real-time feed ticks.

Contents

Connect and login

Connection operation is perfromed in two phases. First you need to create and instance of WebSocket object and provide an address to connect. Then you should perfrom HMAC authentication in 'onopen' event handler.

Login request

Login request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Login",
  "Params": {
    "AuthType": "HMAC",
    "WebApiId":  <Web API Id>,
    "WebApiKey": <Web API Key>,
    "Timestamp": <timestamp (e.g. Date.now())>,
    "Signature": <signature>,
    "DeviceId":  <Device Id>,
    "AppSessionId":  <Application Session Id>
  }
}
              

Login response

Success Login response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Login",
  "Result": {
    "Info": "ok",
    "TwoFactorFlag": true or false
  }
}
              

Login error

Error Login response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Error",
  "Error": <error description from TickTrader Server>
}
              

Authentication

Signature should be calculated from "<timestamp>+<id>+<key>" with the "<secret>" using HMAC/SHA256 with BASE64 encoding. For example you can use Crypto-JS API to calculate the required signature:


function CreateSignature(timestamp, id, key, secret) {
  var hash = CryptoJS.HmacSHA256(timestamp + id + key, secret);
  return CryptoJS.enc.Base64.stringify(hash);
}
              

Two-factor server response

After success Login if session requires Two-factor authentication TickTrader Server will send TwoFactor response. It should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Response": "TwoFactor",
  "Result": {
    "Info": "Two-factor authentication is required."
  }
}
            

Two-factor client request

Client sends Two-factor authentication request to TickTrader Server. It should be a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Request": "TwoFactor",
  "Params": {
    "OneTimePassword": <One-time password (e.g. TOTP is generated by Google Authenticator)>
  }
}
              

To resume Two-factor authentication token the client sends request to TickTrader Server. It should be a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Request": "TwoFactor",
}
              

Success Two-factor response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "TwoFactor",
  "Result": {
    "Info": "Success",
    "ExpireTime": 1475157761354
  }
}
              

Two-factor error

Error Two-factor response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "TwoFactor",
  "Result": {
    "Info": "Invalid one-time password!"
 }
}
              

Example: Connect and login

Below you will find a complete JavaScript code fragment which connectes to TickTrader Server using WebSockets technology:


<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js" type='text/javascript'></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js" type='text/javascript'></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha256.js" type='text/javascript'></script>

<script>

function CreateSignature(timestamp, id, key, secret) {
  var hash = CryptoJS.HmacSHA256(timestamp + id + key, secret);
  return CryptoJS.enc.Base64.stringify(hash);
}

var socket = null;

function Connect(address, id, key, secret) {
  try {
    var timestamp = Date.now();
    var signature = CreateSignature(timestamp, id, key, secret);

    socket = new WebSocket(address);
    console.log('Socket state: ' + socket.readyState);
    socket.onopen = function() {
      console.log('Socket state: ' + socket.readyState + ' (open)');
      var request = {
        Id: "8AF57382-DE83-49DC-9B4E-CF9FF4A4A798",
        Request: "Login",
        Params: {
          AuthType: "HMAC",
          WebApiId: id,
          WebApiKey: key,
          Timestamp: timestamp,
          Signature: signature,
          DeviceId: "WebBrowser",
          AppSessionId: "123"
        }
      };
      var jsonrequest = JSON.stringify(request);
      socket.send(jsonrequest);
    }
    socket.onmessage = function(msg) {
      console.log(msg.data);
    }
    socket.onclose = function() {
      console.log('Socket state: ' + socket.readyState + ' (closed)');
      socket = null;
    }
  } catch(exception) {
    console.log('Error: ' + exception.text);
  }
}

</script>
              

Example: Two-factor


Disconnect

Disconnection from WebSockets interface is performed simply by closing web socket object:


function Disconnect() {
  socket.close();
}
              

Example: Disconnect

Session information

Client session contains information about the current TickTrader client session.

Session information request

Session information request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "SessionInfo"
}
              

Session information response

Success Session information response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "SessionInfo",
  "Result": {
    "ClientSessionId": "8165ADCC-5BFB-41B8-9A88-2F7CF0A0994B",
    "ClientSessionCreated": 1443722400000,
    "TradeAllowed": false
  }
}
              

Session information error

Error Session information response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Error",
  "Error": <error description from TickTrader Server>
}
              

Example: Session information


Currency information

Access to the currency list in TickTrader Server.

Currency information request

To get all avaliable currencies request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Currencies"
}
              

To get currency information by its name request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Currencies",
  "Params": {
    "Currency": <currency>
  }
}
              

Currency information response

Currency information response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Currencies",
  "Result": {
    "Currencies": [{
      "Name": "USD",
      "Precision": 2,
      "Description": "United States Dollar"
    }, {
      "Name": "EUR",
      "Precision": 2,
      "Description": "Euro"
    }]
  }
}
              

Currency information error

Error currency information response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Error",
  "Error": <error description from TickTrader Server>
}
              

Example: Get all currencies information


Example: Get currency by name


Symbols information

Access to the symbols list in TickTrader Server.

Symbols information request

To get all avaliable symbols request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Symbols"
}
              

To get symbol information by its name request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Symbols",
  "Params": {
    "Symbol": <symobl>
  }
}
              

Symbols information response

Symbols information response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Symbols",
  "Result": {
    "Symbols": [{
       "Symbol": "EURUSD",
       "Precision": 5,
       "IsTradeAllowed": true,
       "MarginMode": "Forex",
       "ProfitMode": "Forex",
       "ContractSize": 100000,
       "MarginHedged": 0.5,
       "MarginFactor": 1,
       "MarginCurrency": "EUR",
       "MarginCurrencyPrecision": 2,
       "ProfitCurrency": "USD",
       "ProfitCurrencyPrecision": 2,
       "Description": "Euro vs US Dollar",
       "SwapEnabled": true,
       "SwapSizeShort": 2.23,
       "SwapSizeLong": 2.32,
       "MinTradeAmount": 1000.00,
       "MaxTradeAmount": 10000000,
       "TradeAmountStep": 1000.00,
       "CommissionType": "Percentage",
       "CommissionChargeType": "PerLot",
       "CommissionChargeMethod": "RoundTurn",
       "Commission": 0.005,
       "LimitsCommission": 0.005
    }]
  }
}
              

Symbols information error

Error symbols information response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Error",
  "Error": <error description from TickTrader Server>
}
              

Example: Get all symbols information


Example: Get symbol by name


Feed subscribe

Subscribe to feed ticks updates in TickTrader Server.

Feed subscribe request

Feed subscribe request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "FeedSubscribe",
  "Params": {
    "Subscribe": [{
      "Symbol": <symobl 1>,
      "BookDepth": <book depth 1>
    }, {
      "Symbol": <symobl N>,
      "BookDepth": <book depth N>
    }]
  }
}
              

Feed subscribe response

Feed subscribe response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "FeedSubscribe",
  "Result": {
    "Snapshot": [{
      "Symbol": "EURUSD",
      "Timestamp": 1443789754160,
      "BestBid": {
        "Type": "Bid",
        "Price": 1.12912,
        "Volume": 1000000
      },
      "BestAsk": {
        "Type": "Ask",
        "Price": 1.12913,
        "Volume": 1000000
      },
      "Bids": [{
        "Type": "Bid",
        "Price": 1.12912,
        "Volume": 1000000
      }, {
        "Type": "Bid",
        "Price": 1.12911,
        "Volume": 2500000
      }, {
        "Type": "Bid",
        "Price": 1.1291,
        "Volume": 3700000
      }],
      "Asks": [{
        "Type": "Ask",
        "Price": 1.12913,
        "Volume": 1000000
      }, {
        "Type": "Ask",
        "Price": 1.12914,
        "Volume": 500000
      }, {
        "Type": "Ask",
        "Price": 1.12915,
        "Volume": 2550000
      }]
    }]
  }
}
              
After feed subscribe response response you will start to recieve feed tick update notifications!

Feed subscribe error

Error feed subscribe response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Error",
  "Error": <error description from TickTrader Server>
}
              

Example: Subscribe to symbols feed ticks


Feed unsubscribe

Unsubscribe from feed ticks updates in TickTrader Server.

Feed unsubscribe request

Feed unsubscribe request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "FeedSubscribe",
  "Params": {
    "Unsubscribe": [
      <symobl 1>,
      <symobl N>
    }]
  }
}
              

Feed unsubscribe response

Feed unsubscribe response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "FeedSubscribe",
  "Result": {
    "Snapshot": []
  }
}
              
After feed unsubscribe response response you will stop to recieve feed tick update notifications!

Feed unsubscribe error

Error feed unsubscribe response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Error",
  "Error": <error description from TickTrader Server>
}
              

Example: Unsubscribe from symbols feed ticks


Quote history

Access to the quote history in TickTrader Server.

Quote history version request

Quote history version request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "QuoteHistoryVersion"
}
              

Quote history supported symbols request

Quote history supported symbols request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "QuoteHistorySymbols"
}
              

Quote history supported periodicities request

Quote history supported periodicities request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "QuoteHistoryPeriodicities",
  "Params": {
    "Symbol": <symobl>
  }
}
              

Quote history bars meta information request

Quote history bars meta information request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "QuoteHistoryBarsInfo",
  "Params": {
    "Symbol": <symobl>,
    "Periodicity": <periodicity>,
    "PriceType": <bid/ask>
  }
}
              

Quote history bars request

Quote history bars request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "QuoteHistoryBars",
  "Params": {
    "Symbol": <symobl>,
    "Periodicity": <periodicity>,
    "PriceType": <bid/ask>,
    "Timestamp": <timestamp>,
    "Count": <[-1000, -1]/[1, 1000]>
  }
}
              

Example: Get quote history version


Example: Get quote history supported symbols


Example: Get quote history supported periodicities


Example: Get quote history bars meta information


Example: Get quote history bars


Notifications

Notification: Feed tick update

After subscription to some symbol in TickTrader Server you will recieve the following notifications with a new feed tick value. Count of 'Bids' and 'Asks' collections are similar to the subscription book depth.


{
  "Response": "FeedTick",
  "Result": {
    "Symbol": "EURUSD",
    "Timestamp": 1443789756132,
    "BestBid": {
      "Type": "Bid",
      "Price": 1.12906,
      "Volume": 550000
    },
    "BestAsk": {
      "Type": "Ask",
      "Price": 1.12908,
      "Volume": 2000000
    },
    "Bids": [{
      "Type": "Bid",
      "Price": 1.12906,
      "Volume": 550000
    }, {
      "Type": "Bid",
      "Price": 1.12905,
      "Volume": 1500000
    }, {
      "Type": "Bid",
      "Price": 1.12904,
      "Volume": 6000000
    }],
    "Asks": [{
     "Type": "Ask",
     "Price": 1.12908,
     "Volume": 2000000
    }, {
     "Type": "Ask",
     "Price": 1.12909,
     "Volume": 1500000
    }, {
     "Type": "Ask",
     "Price": 1.1291,
     "Volume": 1000000
    }]
  }
}