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.
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 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>
}
}
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
}
}
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>
}
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);
}
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."
}
}
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
}
}
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!"
}
}
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>
Disconnection from WebSockets interface is performed simply by closing web socket object:
function Disconnect() {
socket.close();
}
Client session contains information about the current TickTrader client session.
Session information request should be a valid JSON message with the following fields:
{
"Id": <some unique Id>,
"Request": "SessionInfo"
}
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
}
}
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>
}
Access to the currency list in TickTrader Server.
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 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"
}]
}
}
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>
}
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 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"
}]
}
}
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>
}
Access to the symbols list in TickTrader Server.
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 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
}]
}
}
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>
}
Subscribe to feed ticks updates in TickTrader Server.
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 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!
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>
}
Unsubscribe from feed ticks updates in TickTrader Server.
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 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!
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>
}
Access to the quote history in TickTrader Server.
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 should be a valid JSON message with the following fields:
{
"Id": <some unique Id>,
"Request": "QuoteHistorySymbols"
}
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 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 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]>
}
}
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
}]
}
}