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>
}
}
Success Login response from TickTrader Server is a valid JSON message with the following fields:
{
"Id": <your unique Id>,
"Response": "Login",
"Result": "ok"
}
Just after login response you will recieve session information notification!
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);
}
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
}
};
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();
}
Feed session contains information about TickTrader Server configuration and working time.
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": {
"PlatformName": "TickTrader Demo Server",
"PlatformCompany": "Soft-FX",
"PlatformAddress": "ttdemo.soft-fx.com",
"PlatformTimezoneOffset": 3,
"SessionId": "e36c076b-4e38-472d-b271-017a4152f09e",
"SessionStatus": "Opened",
"SessionStartTime": 1443722400000,
"SessionEndTime": 253402297200000,
"SessionOpenTime": 1443722400000,
"SessionCloseTime": 253402297200000
}
}
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 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
}]
}
}
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>
}
When Feed session state is changed TickTrader Server will send corresponding notification. You will recieve this notification after successfull login as well!
{
"Response": "SessionInfo",
"Result": {
"PlatformName": "TickTrader Demo Server",
"PlatformCompany": "Soft-FX",
"PlatformAddress": "ttdemo.soft-fx.com",
"PlatformTimezoneOffset": 3,
"SessionId": "e36c076b-4e38-472d-b271-017a4152f09e",
"SessionStatus": "Opened",
"SessionStartTime": 1443787200000,
"SessionEndTime": 253402297200000,
"SessionOpenTime": 1443787200000,
"SessionCloseTime": 253402297200000
}
}
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
}]
}
}