WebSocket Data Interface (WebSocket API)

WebSocket Data Interface (WebSocket API)

Interface URI: wss://ro.exchange:2096
Return the result format: JSON
  • The WebSocket API provides a more real-time data access. Your server can change the orderbook turnover and market data connections in real-time via websocket (push) to the user WebSocket API's.

    The WebSocket API can be divided into three simple steps:

    1. Establishing of websocket connection
    2. Use api token to verify identity
    3. Receiving and processing data
  • WebSocket is a widely used as standard and supports a variety of languages. In Javascript for example:


    var host = 'wss://ro.exchange:2096';
    var socket = new WebSocket(host);
    socket.onopen = function() {
    socket.onmessage = function(msg) {
    socket.onclose = function() {

    You can also refer to the implementation of the official Ruby client:https://github.com/MassICTBV/Ro.Exchange-client-ruby/blob/master/lib/Ro.Exchange_api/streaming_client.rb

  • Prior to access, you must prepare your access/secret key. After registration by simply accessing the API Tokens page you can get your key.

    Once you establish a WebSocket connection with the server, the server returns a message in the following format:


    The challenge contains a randomly generated string which the client needs to use access/secret key signature of this string, and then signing back to the server, which verifies the signature, then continue to the next step. Otherwise it returns an error message.

    Signature generation is very simple, first put your access key and challenge string concatenation:

    payload = access_key + challenge

    Assuming access key for the "abc", challenge for the "def", the payload is "abcdef" followed by HMAC-SHA256 and secret key computing payload signature:

    signature = HMAC-SHA256(secret_key, payload).to_hex

    Assuming secret_key for 'ghi', using HMAC-SHA256 for the signature on the case of the payload results:

    signature = HMAC-SHA256('ghi', 'abcdef').to_hex
              = '52ca0e5beab532532c62155e78d81c7dc8ad6d6f744cf3797668cf52dd2f9a41'

    Now we just need to get the signature back to the server in the following format:

    {auth: {access_key: 'your_access_key', answer: 'the_signature'}}

    For more information you can refer to the brave official Ruby client implementation:https://github.com/MassICTBV/Ro.Exchange-client-ruby/blob/master/lib/peatio_api/streaming_client.rb

  • After validation by real-time data can be sent by the server to accept the current offer two types of real-time data via brave WebSocket API:. Trade and Orderbook detailed data format is as follows:

    Type Data structure / example Remarks
    { "trade"=>
        { "id"=>2435,
            "id"=>3248, "side"=>"buy", "price"=>nil,
            "avg_price"=>"3500.0", "state"=>"done", "market"=>"ltcbtc",
            "created_at"=>"2016-08-16T05:02:37Z", "volume"=>"0.0331",
            "remaining_volume"=>"0.0", "executed_volume"=>"0.0331"

    Trade messages on behalf of your pending order a new deal.

    price / volume: price / number of transactions

    funds: Turnover (to quote currency)

    market: market: the base currency / Quote currency

    side: your role in this transaction in the (ask: seller, bid: buyer)

    ask or bid: ask or bid: Transaction data after lodging

    { "orderbook"=>
      { "action"=>"add",

    Orderbook message representative orderbook has changed.

    Orderbook add a message ("action" => "add") to indicate a new order to join orderbook.

    Orderbook remove the message ("action" => "remove") indicates orderbook removed this order (may be due to the user cancels the pending order or a pending order completely turnover).

    Orderbook update messages ("action" => "update") indicates orderbook in order to be updated.

    action: orderbook operating ranges: add, remove, update

    order: the order being operated