General WebSocket API information

  • The base URL: wss://api-adapter.backend.currency.com/connect
  • The base URL, demo account: wss://demo-api-adapter.backend.currency.com/connect
  • All endpoints return either a JSON object or array.
  • All time and timestamp related fields are in milliseconds.
  • Websocket API connection is closed in case API is not pinged for a 30-seconds time interval.
  • All the tokenised assets except companies tokens, tokenized bonds, tokens “KARMA.cx” and tokenised assets from Hong Kong markets  are available in the first version (v1) of our API. In the second API version (v2) Hong Kong markets became also available.
  • The list of assets available for leverage trading within API can be found here.

!Note. For the successful signature generation please sort parameters in the request payload according to the alphabetical order.

Please, refer to the WebSocket API part within the Swagger in order to get the information needed. More usage examples can be found here.

Troubleshooting

Change log

July, 2021: the second version (v2) of the WS API was added with a complete list of the leverage instruments available there, please note that for the demo accounts only the first version (v1) is available; added the /tradingPositionsHistory endpoint which provides an opportunity to view the historic trades info per symbol.

June, 2021: added an opportunity to use the demo account with the first version (v1) of the WS API;  added the showZeroBalance parameter for the /account endpoint in order clients could turn on or off the zero balances depiction in the response.

May, 2021: added an opportunity to view data on the Heiken-Ashi type of the bars in the /klines and OHLCMarketData.subscribe streams. 

December, 2020: fixed an issue with the concurrent Websocket requests, fixed error message texts when setting the wrong stopLoss or takeProfit values, updated request limits for openOrders endpoint which is now equal to 5 requests per second instead of 10, fixed accountId parameter values wrong representation;

November, 2020: changing of the HTTP codes logic and representing them in the right way, unification of error messages between Rest and Websocket APIs, /updateTradingOrder endpoint fix, got rid off unnecessary parameters in /myTrades, /aggTrades, /order and /updateTradingOrder endpoints, fixed an inability to set expireTimestamp parameter for exchange limit orders.

June, 2020: 50 tokenised assets and cryptocurrency market pairs were added and became available for trading in the leverage mode within our API.

May, 2020: a new STOP order type was added. It is available within the ‘leverage’ trading mode; added an opportunity to use ‘leverage’ trading mode with BTC/USD; ETH/USD; Crude Oil (XTI.cx); Brent Oil (XBR.cx); S&P 500 (SPXm.cx); LTC/USD; Gold (XAUm.cx); EUR/USD; Tesla (TSLA.cx); XRP/USD market pairs.

Subscribe method

 
const ws = new WebSocket ('wss://api-adapter.backend.currency.com/connect', {perMessageDeflate: true}); let responseList = []; let request, response = Object();

Callbacks

 
await ws.on('open', async function open() { console.log("connected"); }); ws.on('close', async function close() { console.log('disconnected'); }); ws.on('error', async function error(data) { console.log('error'); console.log(data); }); ws.on('message', async function incoming(data) { response = JSON.parse(data); responseList.push(response); });

Correlation ID

This ID is needed for mapping asynchronous response with request

request.correlationId = request.correlationId + 1;

Request model

 
//Destination request.destination = "/api/v1/leverageSettings"; //Request payload request.payload = {"symbol": ETH/USD, "timestamp": Date.now(), "apiKey": apiKey}; request.payload.signature = getHash(request); function getHash(request) { let payload = ""; Object.keys(request.payload).sort().forEach(function(key) { payload += key + "=" + request.payload[key] + "&"; }); payload = payload.substring(0, payload.length - 1); console.log(payload); let hash = CryptoJS.HmacSHA256(payload, apiSecret).toString(); console.log(hash); return hash; } //Send request message = JSON.stringify(request); ws.send(message); await sleep(5000); index = responseList.findIndex(i => i.correlationId === request.correlationId.toString()); console.log('============================'); console.log('index: ' + index); console.log(responseList[index]); console.log('============================');

‘Symbol’ parameter description

Both for the exchange and leverage trading modes 'symbol' parameter can be checked within exchangeInfo stream.
Exchange trading mode: use symbol from the exchangeInfo stream;
Leverage trading mode: look into the 'symbol' from the exchangeInfo stream. In case ‘symbol’ has currencies in its name then the following format should be used: ‘BTC%2FUSD_LEVERAGE’. In case ‘symbol’ has only an asset name then the following format is correct: ‘Oil%20-%20Brent.’

ENUM definitions

Order types (orderTypes, type):

  • LIMIT
  • MARKET
  • STOP

Order side (side):

  • BUY
  • SELL

Time in force (timeInForce):

  • GTC
  • IOC
  • FOK

Kline/Candlestick chart intervals:
m -> minutes; h -> hours; d -> days; w -> weeks

  • 1m
  • 5m
  • 15m
  • 30m
  • 1h
  • 4h
  • 1d
  • 1w

Please note that in case no value for the "intervals" parameter is mentioned when using the wss:OHLCMarketData.subscribe endpoint then '1m' value is set by default.