Dzengi.com WebSocket API

GO TO SWAGGER

General WebSocket API information

  • The base URL: wss://api-adapter.dzengi.com/connect
  • The base URL, demo account: wss://demo-api-adapter.dzengi.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

Subscribe method

const ws = new WebSocket

('wss://api-adapter.backend.dzengi.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.

Go help.dzengi.com