WebSocket console

TickTrader Feed WebSocket API

TickTrader Feed 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(), milliseconds)>,
    "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 types request

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


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

Currency types response

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


{
  "Id": <your unique Id>,
  "Response": "CurrencyTypes",
  "Result": {
    "CurrencyTypes": [{
      "Name": "Default",
      "Description": "Default currency type"
    }, {
      "Name": "Share",
      "Description": "Share"
    }]
  }
}
              

Currency types error

Error currency types 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 currency types


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 currencies by its names request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Currencies",
  "Params": {
    "Currency": "currency1;currency2;currency3"
  }
}
              

NOTE: An empty response may be returned if none of the currencies matches the Params.Currency

To get currencies by its types request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Currencies",
  "Params": {
    "Type": <currencyType1;currencyType2;currencyType3>
  }
}
              

NOTE: An empty response may be returned if none of the currencies matches the Params.Type

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


Example: Get currencies by names


Example: Get currencies by types


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 symbols by its names request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Symbols",
  "Params": {
    "Symbol": "symbol1;symbol2;symbol3"
  }
}
              

NOTE: An empty response may be returned if none of the symbols matches the Params.Symbol

To get symbols by its security names request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Symbols",
  "Params": {
    "Security": "security1;security2;security3"
  }
}
              

NOTE: An empty response may be returned if none of the symbols matches the Params.Security

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
       "MinCommission": 0.005, 
       "MinCommissionCurrency": 0.005, 
       "DefaultSlippage": 0.005, 
       "StatusGroupId ": "Default",
       "SecurityName": "Forex", 
       "SecurityDescription": "Forex",
       "StopOrderMarginReduction": 0.005, 
       "HiddenLimitOrderMarginReduction": 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


Example: Get symbols by names


Example: Get symbols by security names


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": <symbol 1>,
      "BookDepth": <book depth 1>
    }, {
      "Symbol": <symbol N>,
      "BookDepth": <book depth N>
    }]
  }
}
              

Frequency Feed subscribe

Subscribe to feed ticks updates in TickTrader Server with selected frequency (once per 2FrequencyPriority*500 ms).

Frequency 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": <symbol 1>,
      "BookDepth": <book depth 1>,   
      "FrequencyPriority" : <frequency priority 1>
    }, {
      "Symbol": <symbol N>,
      "BookDepth": <book depth N>,   
      "FrequencyPriority" : <frequency priority 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


Example: Subscribe to symbols frequency 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": [
      <symbol 1>,
      <symbol 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


Bar Feed subscribe

Subscribe to feed bar updates in TickTrader Server.

Bar Feed subscribe request

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


{
    "Id": <your unique Id>,
    "Request": "BarFeedSubscribe",
    "Params":
    {
        "Subscribe":
        [{
            "Symbol": <symbol>,
            "BarParams":
            [{
                "Periodicity" : <periodicity>,
                "PriceType" : <price type>
            }]
        }]
    }
}

Bar Feed subscribe response

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



{
    "Result":
    {
        "Updates":
        [{
            "Low": 1.13788,
            "High": 1.13798,
            "Time": 1643191200000,
            "Open": 1.13788,
            "PriceType": "Ask",
            "Periodicity": "H1"
        }],
        "AskClose": 1.1379,
        "SymbolAlias": "EURUSD"
    },
    "Response": "FeedBarUpdate"

}
After feed subscribe response response you will start to recieve bar update notifications!

Bar Feed subscribe error

Error bar 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 bar updates


Bar Feed unsubscribe

Unsubscribe from bar updates in TickTrader Server.

Bar Feed unsubscribe request

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


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

Bar Feed unsubscribe response

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


{
  "Id": <your unique Id>,
  "Response": "BarFeedSubscribe",
  "Result": {
  }
}
              
After feed unsubscribe response response you will stop to recieve bar update notifications!

Bar Feed unsubscribe error

Error bar 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 bar updates


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": <symbol>
  }
}
              

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": <symbol>,
    "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": <symbol>,
    "Periodicity": <periodicity>,
    "PriceType": <bid/ask>,
    "Timestamp": <timestamp in milliseconds>,
    "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


Interest Rate History

Access to the interest rate history in TickTrader Server.

Interest rate history request

Interest rate history request should be a valid JSON message with the following fields:


{
    "Id": <some unique Id>,
    "Request": "InterestRateHistory",
    "Params": {
    "Currency": <currency>,
    "TimestampFrom": <from timestamp (optional, milliseconds)>,
    "TimestampTo": <to timestamp (optional, milliseconds)>,
    "RequestDirection": <direction "Forward" or "Backward" (optional, default is "Forward")>,
    "RequestPageSize": <page size (optional, default is 100)>,
    "RequestLastId": <last record Id in previous request (optional)>
    }
}

Example: Get interest rate history


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

Notification: Bar update

After subscription to some bar (symbol, periodicity and price type are required) in TickTrader Server you will recieve the following notifications with a bar updates and closed bars.


{
    "Result":
    {
        "Updates":
        [{
            "Low": 1.13788,
            "High": 1.13798,
            "Time": 1643191200000,
            "Open": 1.13788,
            "PriceType": "Ask",
            "Periodicity": "H1"
        }],
    "AskClose": 1.1379,
    "SymbolAlias": "EURUSD"
    },
    "Response": "FeedBarUpdate"
}