WebSocket console

TickTrader Trade WebSocket API

TickTrader Trade WebSocket API is used to connect to the TickTrader Server using secure web sockets technology (wss://) to get account information, assets, positions & trades and perform trade operations.

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
  }
}
              
After login response if Two-factor login is not required you will recieve trade session information notification and account information notification!

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

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


Trade session information

Trade session contains information about TickTrader Server configuration and working time.

Trade session information request

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


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

Trade session information response

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


{
  "Id": <your unique Id>,
  "Response": "TradeSessionInfo",
  "Result": {
    "PlatformName": "TickTrader Demo Server",
    "PlatformCompany": "MyCompany",
    "PlatformAddress": "MyCompany.com",
    "PlatformTimezoneOffset": 3,
    "SessionId": "e36c076b-4e38-472d-b271-017a4152f09e",
    "SessionStatus": "Opened",
    "SessionStartTime": 1443722400000,
    "SessionEndTime": 253402297200000,
    "SessionOpenTime": 1443722400000,
    "SessionCloseTime": 253402297200000
  }
}
              

Trade session information error

Error trade 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: Trade session information


Account information

Access to the account information in Tick Trader Server.

Account information request

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


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

Account information response

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


{
  "Id": <your unique Id>,
  "Response": "Account",
  "Result": {
    "Id": 5,
    "AccountingType": "Gross",
    "Name": "DemoForexGross",
    "Comment": "Test account",
    "Registered": 1404114533000,
    "IsArchived": false,
    "IsBlocked": false,
    "IsReadonly": false,
    "IsValid": true,
    "IsWebApiEnabled": true,
    "Leverage": 100,
    "Balance": 999999741.1900000000,
    "BalanceCurrency": "USD",
    "Profit": 0.0,
    "Commission": 0.0,
    "AgentCommission": 0.0,
    "Swap": 0.0,
    "Equity": 999999741.1900000000,
    "Margin": 0,
    "MarginLevel": 0,
    "MarginCallLevel": 50,
    "StopOutLevel": 30
  }
}
              

Account information error

Error Account 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: Account information


Assets information (Cash accounts only!)

Access to the cash account assets information in Tick Trader Server. Works only for cash accounts!

Assets information request

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


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

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


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

Assets information response

Cash account assets information response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Assets",
  "Result": {
    "Assets": [{
      "Currency": "USD",
       "Amount": 873244.4,
       "FreeAmount": 873244.4,
       "LockedAmount": 0.0
    }, {
       "Currency": "EUR",
       "Amount": 89995.0,
       "FreeAmount": 89995.0,
       "LockedAmount": 0.0
    }, {
       "Currency": "AUD",
       "Amount": 14119.7,
       "FreeAmount": 14119.7,
       "LockedAmount": 0.0
    }, {
       "Currency": "GBP",
       "Amount": 9999.5,
       "FreeAmount": 9999.5,
       "LockedAmount": 0.0
    }]
  }
}
              

Assets information error

Error cash account assets 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 assets information


Example: Get asset by currency name


Positions information (Net accounts only!)

Access to the net account positions information in Tick Trader Server. Works only for net accounts!

Positions information request

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


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

To get net account position information by Id request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Positions",
  "Params": {
    "Id": <id>
  }
}
              

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


{
  "Id": <some unique Id>,
  "Request": "Positions",
  "Params": {
    "Symbol": <symbol>
  }
}
              

Positions information response

Net account positions information response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Positions",
  "Result": {
    "Positions": [{
      "Id": 555003,
      "Symbol": "EUR/USD",
      "LongAmount": 2970000,
      "LongPrice": 1.08,
      "ShortAmount": 0,
      "ShortPrice": 0,
      "Commission": -40.37,
      "AgentCommission": 0,
      "Swap": 4065.10,
      "Modified": 1444003200004
    }]
  }
}
              

Positions information error

Error net account positions 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 positions information


Example: Get position by Id


Example: Get position by symbol name


Trades information

Access to the account trades information in Tick Trader Server.

Trades information request

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


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

To get account trade information by Id request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "Trades",
  "Params": {
    "Id": <id>
  }
}
              

Trades information response

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


{
  "Id": <your unique Id>,
  "Response": "Trades",
  "Result": {
    "Trades": [{
      "Id": 769002,
      "ClientId": "bf9e37b3-b2f6-42ca-9946-86309d4ed746",
      "AccountId": 5,
      "Type": "Position",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "Calculated",
      "Symbol": "EURUSD",
      "Price": 1.11992,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Commission": -5.60,
      "AgentCommission": 0,
      "Created": 1444060398377,
      "Modified": 1444060398384,
      "Filled": 1444060398384,
      "PositionCreated": 1444060398384
    }, {
      "Id": 769004,
      "ClientId": "1da440da-2854-40ab-8246-167436fffb34",
      "AccountId": 5,
      "Type": "Limit",
      "InitialType": "Limit",
      "Side": "Buy",
      "Status": "Calculated",
      "Symbol": "AUDCAD",
      "Price": 0.82679,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Created": 1444060421926,
      "Modified": 1444060421934
    }, {
      "Id": 769008,
      "ClientId": "e22ccc93-88e1-4006-a0a7-3200b6fbccab",
      "AccountId": 5,
      "Type": "Stop",
      "InitialType": "Stop",
      "Side": "Buy",
      "Status": "Calculated",
      "Symbol": "CADCHF",
      "Price": 0.84515,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Created": 1444061178536,
      "Modified": 1444061178544
    }]
  }
}
              

Trades information error

Error account trades 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 trades information


Example: Get trade by Id


Trade create

Create new trades in Tick Trader Server.

Trade create request

To create new market trade request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeCreate",
  "Params": {
    "Type": "Market",
    "Side": "Buy" | "Sell",
    "Symbol": <symbol>,
    "Amount": <amount>,
    "StopLoss": <stop loss (optional)>,
    "TakeProfit": <take profit (optional)>,
    "Comment": <comment (optional)>,
    "ClientId": <client trade Id (optional)>
  }
}
              

To create new limit trade request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeCreate",
  "Params": {
    "Type": "Limit",
    "Side": "Buy" | "Sell",
    "Symbol": <symbol>,
    "Amount": <amount>,
    "Price": <price>,
    "Expired": <expiration timestamp (optional, milliseconds)>,
    "StopLoss": <stop loss (optional)>,
    "TakeProfit": <take profit (optional)>,
    "Comment": <comment (optional)>,
    "ClientId": <client trade Id (optional)>
  }
}
              

To create new stop trade request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeCreate",
  "Params": {
    "Type": "Stop",
    "Side": "Buy" | "Sell",
    "Symbol": <symbol>,
    "Amount": <amount>,
    "Price": <price>,
    "Expired": <expiration timestamp (optional, milliseconds)>,
    "StopLoss": <stop loss (optional)>,
    "TakeProfit": <take profit (optional)>,
    "Comment": <comment (optional)>,
    "ClientId": <client trade Id (optional)>
  }
}
              

To create new immediate-or-cancel limit trade (IOC) request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeCreate",
  "Params": {
    "Type": "Limit",
    "ImmediateOrCancel": true,
    "Side": "Buy" | "Sell",
    "Symbol": <symbol>,
    "Amount": <amount>,
    "Price": <price>,
    "StopLoss": <stop loss (optional)>,
    "TakeProfit": <take profit (optional)>,
    "Comment": <comment (optional)>,
    "ClientId": <client trade Id (optional)>
  }
}
              

Trade create response

Before trade create response response you will recieve a set of execution reports notifications! Trade create response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "TradeCreate",
  "Result": {
    "Trade": {
      "Id": 769009,
      "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21",
      "AccountId": 5,
      "Type": "Market",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "Filled",
      "Symbol": "EURUSD",
      "Price": 1.12142,
      "Amount": 0,
      "InitialAmount": 100000,
      "Created": 1444139200012,
      "Modified": 1444139200020,
      "Filled": 1444139200020,
      "Comment": "WebSocket API market"
    }
  }
}
              

Trade create error

Error trade create 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: Create market trade


Example: Create limit trade


Example: Create stop trade


Example: Create contingent trade is triggering on time


Example: Create immediate-or-cancel limit trade (IOC)


Trade create oco

Create new oco trades in Tick Trader Server.

Trade create oco request

To create new stop-limit oco trade request should be a valid JSON message with the following fields:


{
    "Id": <some unique Id>,
    "Request": "TradeCreate",
    "FirstRequest": {
        "Type": "Stop",
        "Side": "Buy" | "Sell",
        "Symbol": <symbol>,
        "Amount": <amount>,
        "StopPrice": <stopprice>,
        "Comment": <comment (optional)>,
        "ClientId": <client trade Id (optional)>
    },
    "SecondRequest": {
        "Type": "Stop",
        "Side": "Buy" | "Sell",
        "Symbol": <symbol>,
        "Amount": <amount>,
        "StopPrice": <stopprice>,
        "Comment": <comment (optional)>,
        "ClientId": <client trade Id (optional)>
    }
}

To create new stop-limit oco trade request should be a valid JSON message with the following fields:


{
    "Id": <some unique Id>,
    "Request": "TradeCreate",
    "FirstRequest": {
        "Type": "Stop",
        "Side": "Buy" | "Sell",
        "Symbol": <symbol>,
        "Amount": <amount>,
        "StopPrice": <stopprice>,
        "Comment": <comment (optional)>,
        "ClientId": <client trade Id (optional)>
    },
    "SecondRequest": {
        "Type": "Limit",
        "Side": "Buy" | "Sell",
        "Symbol": <symbol>,
        "Amount": <amount>,
        "Price": <price>,
        "Comment": <comment (optional)>,
        "ClientId": <client trade Id (optional)>
    }
}

Trade create oco response

Before trade create response response you will recieve a set of execution reports notifications! Trade create response from TickTrader Server is a valid JSON message with the following fields:


{
    "Id": <your unique Id>,
    {
    "Result": {
        "FirstTrade": {
            "Created": 1620986198805,
            "FilledAmount": 0,
            "RemainingAmount": 100000,
            "InitialAmount": 100000,
            "OneCancelsTheOther": false,
            "MarketWithSlippage": false,
            "ImmediateOrCancel": false,
            "AccountId": 11,
            "Id": 8383002,
            "Type": "Stop",
            "InitialType": "Stop",
            "Side": "Buy",
            "Status": "Calculated",
            "Slippage": 0.33334,
            "Modified": 1620986199441,
            "Profit": 0,
            "Margin": 400002.000000,
            "StopPrice": 3,
            "SymbolPrecision": 5,
            "Comment": "WebSocket API market",
            "Symbol": "EURUSD1",
            "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21"
        },
        "SecondTrade": {
            "Created": 1620986199441,
            "FilledAmount": 0,
            "RemainingAmount": 100000,
            "InitialAmount": 100000,
            "OneCancelsTheOther": true,
            "MarketWithSlippage": false,
            "ImmediateOrCancel": false,
            "AccountId": 11,
            "Id": 8383003,
            "Type": "Limit",
            "InitialType": "Limit",
            "Side": "Buy",
            "Status": "Calculated",
            "RelatedTradeId": 8383002,
            "Modified": 1620986199468,
            "Profit": 0,
            "Margin": 100000.0,
            "Price": 1,
            "SymbolPrecision": 5,
            "Comment": "WebSocket API market",
            "Symbol": "EURUSD1",
            "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21"
        }
    },
        "Response": "TradeCreateOco"
    }
    }
}

Trade create oco error

Error trade create 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: Create oco stop-limit trades


Trade modify

Modify trades in Tick Trader Server.

Trade modify request

To modify market trade request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeModify",
  "Params": {
    "Id": <trade Id>,
    "StopLoss": <stop loss (optional)>,
    "TakeProfit": <take profit (optional)>,
    "Comment": <comment (optional)>
  }
}
              

To modify pending trade request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeModify",
  "Params": {
    "Id": <trade Id>,
    "Amount": <new amount (obsolete, optional, ignored if AmountChange is not empty)>,
    "AmountChange": <a value by which the amount of pending order will be changed (optional)>,
    "Price": <pending trade price (optional)>,
    "Expired": <expiration timestamp (optional, milliseconds)>,
    "StopLoss": <stop loss (optional)>,
    "TakeProfit": <take profit (optional)>,
    "Comment": <comment (optional)>
  }
}
              

Trade modify response

Before trade create response response you will recieve a set of execution reports notifications! Trade modify response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "TradeModify",
  "Result": {
    "Trade": {
      "Id": 769009,
      "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21",
      "AccountId": 5,
      "Type": "Market",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "Filled",
      "Symbol": "EURUSD",
      "Price": 1.12142,
      "Amount": 0,
      "InitialAmount": 100000,
      "Created": 1444139200012,
      "Modified": 1444139200020,
      "Filled": 1444139200020,
      "Comment": "Modified trade"
    }
  }
}
              

Trade modify error

Error trade modify 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: Modify market trade


Example: Modify pending trade


Trade cancel/close

Cancel/close trades in Tick Trader Server.

Trade cancel/close request

To cancel pending trade request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeDelete",
  "Params": {
    "Type": "Cancel",
    "Id": <trade Id>
  }
}
              

To close market trade (full) request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeDelete",
  "Params": {
    "Type": "Close",
    "Id": <trade Id>
  }
}
              

To close market trade (partial) request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeDelete",
  "Params": {
    "Type": "Close",
    "Id": <trade Id>,
    "Amount": <close amount>
  }
}
              

To close market trade by another marker trade request should be a valid JSON message with the following fields:


{
  "Id": <some unique Id>,
  "Request": "TradeDelete",
  "Params": {
    "Type": "CloseBy",
    "Id": <trade Id>,
    "ById": <by trade Id>,
  }
}
              

Trade cancel/close response

Before trade create response response you will recieve a set of execution reports notifications! Trade cancel/close response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "TradeDelete",
  "Result": {
    "Trade": {
      "Id": 769023,
      "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21",
      "AccountId": 5,
      "Type": "Position",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "Filled",
      "Symbol": "EURUSD",
      "Price": 1.12521,
      "Amount": 0,
      "InitialAmount": 100000,
      "Commission": -5.63,
      "AgentCommission": 0,
      "Created": 1444214766990,
      "Modified": 1444214925697,
      "Filled": 1444214766999,
      "PositionCreated": 1444214766999,
      "Comment": "Closed trade"
    }
  }
}
              

Trade cancel/close error

Error trade cancel/close 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: Cancel pending trade


Example: Close market trade (full)


Example: Close market trade (partial)


Example: Close market trade by another market trade


Trade history

Get trade history from Tick Trader Server.

Trade history request

To get trade history with paging the first request should be a valid JSON message with the following fields:


    {
    "Id": <some unique Id>,
    "Request": "TradeHistory",
    "Params": {
    "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)>
    }
    }

To get trade history with paging all next requests should be a valid JSON message with the following fields:


    {
    "Id": <some unique Id>,
    "Request": "TradeHistory",
    "Params": {
    "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)>
    }
    }

Trade history response

Trade history response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "TradeHistory",
  "Result": {
    "IsLastReport": false,
    "TotalReports": 10,
    "Records": [{
      "Id": "542b29688eeafa14e09e42b9",
      "TransactionType": "Balance",
      "TransactionReason": "DealerDecision",
      "TransactionTimestamp": 1412114792915,
      "TradeId": 62006,
      "TradeCreated": 1412114792915,
      "Balance": 0.0000000000,
      "BalanceMovement": 0,
      "BalanceCurrency": "USD"
    }, {
      "Id": "542b2ab88eeafa265c466f62",
      "TransactionType": "PositionClosed",
      "TransactionReason": "StopOut",
      "TransactionTimestamp": 1412115114535,
      "Symbol": "AUDCAD",
      "TradeId": 62002,
      "ParentTradeId": 62002,
      "ClientTradeId": "ManagerOrder-6f521755-937f-4a38-8960-ebae978fc276",
      "TradeSide": "Buy",
      "TradeType": "Position",
      "TradeCreated": 1412114750693,
      "PositionId": 62002,
      "PositionAmount": 0,
      "PositionInitialAmount": 100000,
      "PositionLastAmount": 100000,
      "PositionOpenPrice": 0.97952,
      "PositionOpened": 1412114751410,
      "PositionClosePrice": 0.97933,
      "PositionClosed": 1412115114535,
      "Balance": -16.96,
      "BalanceMovement": -16.96,
      "BalanceCurrency": "USD",
      "Commission": 0,
      "AgentCommission": 0,
      "Swap": 0,
      "Comment": "Closed trade",
      "MarginRateInitial": 0.87458
    }]
  }
}
              

Trade history error

Error trade history 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: Trade history first request


Example: Trade history next request


Daily account snapshots

Get daily account snapshots from Tick Trader Server.

Daily account snapshots request

To get daily account snapshots with paging the first request should be a valid JSON message with the following fields:


    {
    "Id": <some unique Id>,
    "Request": "DailySnapshots",
    "Params": {
    "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)>
    }
    }

To get daily account snapshots with paging all next requests should be a valid JSON message with the following fields:


    {
    "Id": <some unique Id>,
    "Request": "DailySnapshots",
    "Params": {
    "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)>
    }
    }

Daily account snapshots response

Daily account snapshots response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "DailySnapshotsReport",
  "Result": {
    "IsLastReport": false,
    "TotalReports": 10,
    "Records": [
    {
      "TotalCommission": 0,
      "TotalProfitLoss": 0,
      "MarginLevel": 0,
      "Margin": 0,
      "Equity": 0,
      "Swap": 0,
      "AgentCommission": 0,
      "Commission": 0,
      "Profit": 0,
      "Balance": 0,
      "Timestamp": 1518048000000,
      "IsValid": true,
      "IsReadonly": false,
      "IsBlocked": false,
      "Leverage": 0,
      "AccountId": 13,
      "Assets": [
        {
          "LockedAmount": 0,
          "FreeAmount": 999964685.8,
          "Amount": 999964685.8,
          "Currency": "USD"
        },
        {
          "LockedAmount": 0,
          "FreeAmount": 29970,
          "Amount": 29970,
          "Currency": "EUR"
        },
        {
          "LockedAmount": 0,
          "FreeAmount": 999.99999,
          "Amount": 999.99999,
          "Currency": "BTC"
        },
        {
          "LockedAmount": 0,
          "FreeAmount": 0.01998,
          "Amount": 0.01998,
          "Currency": "PPC"
        }
      ],
      "Positions": [],
      "AccountingType": "Cash",
      "Group": "demo_cash"
    }]
  }
}
              

Daily account snapshots error

Error daily account snapshots 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: Daily account snapshots first request


Example: Daily account snapshots next request


Notifications

Notification: Trade session information

When Trade 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": "MyCompany",
    "PlatformAddress": "MyCompany.com",
    "PlatformTimezoneOffset": 3,
    "SessionId": "e36c076b-4e38-472d-b271-017a4152f09e",
    "SessionStatus": "Opened",
    "SessionStartTime": 1443787200000,
    "SessionEndTime": 253402297200000,
    "SessionOpenTime": 1443787200000,
    "SessionCloseTime": 253402297200000
  }
}
              

Notification: Account information

When Account state is changed TickTrader Server will send corresponding notification. You will recieve this notification after successfull login as well!


{
  "Response": "Account",
  "Result": {
    "Id": 5,
    "Domain": "Default",
    "Group": "demoforex_gross",
    "AccountingType": "Gross",
    "Name": "DemoForexGross",
    "Comment": "Test account",
    "Registered": 1404114533000,
    "IsArchived": false,
    "IsBlocked": false,
    "IsReadonly": false,
    "IsValid": true,
    "IsWebApiEnabled": true,
    "Leverage": 100,
    "Balance": 999999741.1900000000,
    "BalanceCurrency": "USD",
    "Profit": 0.0,
    "Commission": 0.0,
    "AgentCommission": 0.0,
    "Swap": 0.0,
    "Equity": 999999741.1900000000,
    "Margin": 0,
    "MarginLevel": 0,
    "MarginCallLevel": 50,
    "StopOutLevel": 30
  }
}
              

Notification: Execution reports

Execution reports are sent by TickTrader Server during life time of all trade.


{
  "Id": "EBBDCD41-6BD9-4365-B6A7-7074DC433A3A",
  "Response": "ExecutionReport",
  "Result": {
    "Event": "Accepted",
    "Trade": {
      "Id": 769021,
      "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21",
      "AccountId": 5,
      "Type": "Market",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "New",
      "Symbol": "EURUSD",
      "Price": 1.12539,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Created": 1444143232606,
      "Comment": "WebSocket API market"
    }
  }
}
              

{
  "Id": "EBBDCD41-6BD9-4365-B6A7-7074DC433A3A",
  "Response": "ExecutionReport",
  "Result": {
    "Event": "Filled",
    "Trade": {
      "Id": 769021,
      "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21",
      "AccountId": 5,
      "Type": "Market",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "Filled",
      "Symbol": "EURUSD",
      "Price": 1.12539,
      "Amount": 0,
      "InitialAmount": 100000,
      "Created": 1444143232606,
      "Modified": 1444143232614,
      "Filled": 1444143232614,
      "Comment": "WebSocket API market"
    },
    "Fill": {
      "Amount": 100000,
      "Price": 1.12539
    }
  }
}
              

{
  "Id": "EBBDCD41-6BD9-4365-B6A7-7074DC433A3A",
  "Response": "ExecutionReport",
  "Result": {
    "Event": "Allocated",
    "Trade": {
      "Id": 769021,
      "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21",
      "AccountId": 5,
      "Type": "Position",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "Calculated",
      "Symbol": "EURUSD",
      "Price": 1.12539,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Commission": -5.63,
      "AgentCommission": 0,
      "Created": 1444143232606,
      "Modified": 1444143232614,
      "Filled": 1444143232614,
      "PositionCreated": 1444143232614,
      "Comment": "WebSocket API market"
    }
  }
}
              

{
  "Id": "EBBDCD41-6BD9-4365-B6A7-7074DC433A3A",
  "Response": "ExecutionReport",
  "Result": {
    "Event": "PendingModify",
    "Trade": {
      "Id": 769022,
      "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21",
      "AccountId": 5,
      "Type": "Position",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "Calculated",
      "Symbol": "EURUSD",
      "Price": 1.127,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Commission": -5.64,
      "AgentCommission": 0,
      "Created": 1444148517905,
      "Modified": 1444148517918,
      "Filled": 1444148517918,
      "PositionCreated": 1444148517918,
      "Comment": "WebSocket API market"
    }
  }
}
              

{
  "Id": "EBBDCD41-6BD9-4365-B6A7-7074DC433A3A",
  "Response": "ExecutionReport",
  "Result": {
    "Event": "Modified",
    "Trade": {
      "Id": 769022,
      "ClientId": "client-market-2FD798ED-4444-4385-AAC3-11B590699D21",
      "AccountId": 5,
      "Type": "Position",
      "InitialType": "Market",
      "Side": "Buy",
      "Status": "Calculated",
      "Symbol": "EURUSD",
      "Price": 1.127,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Commission": -5.64,
      "AgentCommission": 0,
      "Created": 1444148517905,
      "Modified": 1444148673132,
      "Filled": 1444148517918,
      "PositionCreated": 1444148517918,
      "Comment": "Modified trade"
    }
  }
}
              

{
  "Id": "EBBDCD41-6BD9-4365-B6A7-7074DC433A3A",
  "Response": "ExecutionReport",
  "Result": {
    "Event": "PendingCancel",
    "Trade": {
      "Id": 769028,
      "ClientId": "client-limit-3AE8716F-0EA9-43ED-A638-21AD054056CB",
      "AccountId": 5,
      "Type": "Limit",
      "InitialType": "Limit",
      "Side": "Buy",
      "Status": "Calculated",
      "Symbol": "EURUSD",
      "Price": 1,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Created": 1444215160806,
      "Modified": 1444215160814,
      "Comment": "WebSocket API limit"
    }
  }
}
              

{
  "Id": "EBBDCD41-6BD9-4365-B6A7-7074DC433A3A",
  "Response": "ExecutionReport",
  "Result": {
    "Event": "Canceled",
    "Trade": {
      "Id": 769028,
      "ClientId": "client-limit-3AE8716F-0EA9-43ED-A638-21AD054056CB",
      "AccountId": 5,
      "Type": "Limit",
      "InitialType": "Limit",
      "Side": "Buy",
      "Status": "Canceled",
      "Symbol": "EURUSD",
      "Price": 1,
      "Amount": 100000,
      "InitialAmount": 100000,
      "Created": 1444215160806,
      "Modified": 1444215170961,
      "Comment": "WebSocket API limit"
    }
  }
}
              

Splits

Access to the split list in TickTrader Server.

Split list request

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


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

Symbols information response

Split list response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Split",
  "Result": {
    "Splits": [{
       "Id": 638273510970197437,
       "ToFactor": 1,
       "FromFactor": 3.33333333333333,
       "Ratio": 0.3,
       "StartTime": 1714521600000,
       "Symbols": ["AUDCAD", "CADCHF", "CADJPY", "EURCADd", "GBPCAD", "NZDCAD", "USDCAD"],
       "Currencies": ["CAD"],
       "SymbolsNotAffectQH": ["AUDCAD", "CADCHF", "CADJPY", "EURCADd", "GBPCAD", "NZDCAD", "USDCAD"]
    }]
  }
}
              

Split list error

Error split list 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 split list


Dividends

Access to the dividend list in TickTrader Server.

Dividend list request

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


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

Dividend information response

Dividend list response from TickTrader Server is a valid JSON message with the following fields:


{
  "Id": <your unique Id>,
  "Response": "Dividend",
  "Result": {
    "Dividends": [{
       "Id": 12,
       "Symbol": "EURUSD",
       "Time": 1443789756132,
       "GrossRate": 0.2
    }]
  }
}
              

Dividend list error

Error dividend list 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 dividend list


MergersAndAcquisitions

Access to the merger-and-acquisition list in TickTrader Server.

MergerAndAcquisition list request

To get merger-and-acquisition list by symbol list name request should be a valid JSON message with the following fields:


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

MergerAndAcquisition information response

MergerAndAcquisition list response from TickTrader Server is a valid JSON message with the following fields:


{
    "Id": <your unique Id>,
    "Response": "MergerAndAcquisition",
    "Result": {
        "MergersAndAcquisitions": [{
            "Id": "021e4e71-da12-4d88-818f-f3d63e8d96db",
            "Values": {
                "eventId": "4AJZ8X6A",
                "actionType": "ACQUISITION",
                "actionStatus": "ANNOUNCED",
                "acquirerCompanyId": "1",
                "acquirerSymbol": "AAPL",
                "acquirerName": "Apple Inc.",
                "targetCompanyId": "2",
                "targetSymbol": "GOOGL",
                "targetName": "Alphabet Inc.",
                "announceDate": "2020-03-05T00:00:00Z",
                "etFlag": "N",
                "srFlag": "N",
                "newsReferences": "",
                "actionNotes": "",
                "updated": "1583308828000",
                "source": "",
                "key": "GOOGL",
                "subkey": "4AJZ8X6A",
                "date": "1583236860000",
                "pricePerShareCurrency": "USD",
                "purchasePricePerShare": "10",
                "id": "5e5fa179c2f16d4ec48d24ac"
            }
        }]
    }
}

MergerAndAcquisition list error

Error merger-and-acquisition list 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 merger-and-acquisition list