Since the very beginning of our service, the Websocket API has been the most useful and popular with our Enterprise clients.
Our price updates in real-time are invaluable for any business that wants to perform any type of price analysis as soon as soon as the market moves.

Websocket V1

The first implementation of Cryptocurrency Websocket API provides price snapshots at set intervals, these intervals are different for every plan. The inefficiency appears because these snapshots are being sent even if the price does not get updated. For less active cryptocurrencies that get traded only for a few hours per day or some that stay dormant for a week, this is highly inefficient.
This is why we decided to make a new version that provides quicker updates with less bandwidth.

New Websocket V2

The new version actively listens for price changes from all the major cryptocurrency exchanges. When a change occurs, our index is immediately calculated and the price is pushed through the new websocket channels.
This allows us to send updates even faster than one second, for popular markets like Bitcoin to US Dollar (BTC/USD) or Ethereum to Bitcoin (ETH/BTC), while saving up resources and bandwidth on less active markets that get updated less often.
The Websocket API V2 consists of two channels one for Index (Ticker) data and one for raw exchanges data.

Using the API

This new API is available only to Enterprise users, however even if you are a free user you can contact us to provide you with a promo code that will grant you 15 days of Enterprise plan for free.

Authentication

The authentication scheme is the same as in version 1. You need to make a signed GET request to the Ticket URL show below to receive a ticket. Then use that ticket together with your public key in the connection url. Documentation for signing requests.
Ticket URL: https://apiv2.bitcoinaverage.com/websocket/v2/get_ticket

Ticker channel

URL: wss://apiv2.bitcoinaverage.com/websocket/v2/ticker

Example URL with authentication parameters:
wss://apiv2.bitcoinaverage.com/websocket/v2/ticker?public_key=ZWI0YTM2ZWZmMGFkNDRkNmJiMTBkOWRmZTNhMTgwODA&ticket=mJiMNhMTgwWZmMGFkN

Once you connect to the channel you need to send a subscribe message where you tell the server which markets you are interested in.

Ticker subscribe message:

    {
        "event": "message",
        "data": {
            "operation": "subscribe",
            "options": {
                "currency_list": ["BTCUSD", "BTCGBP", "ETHUSD"],
                "symbol_set": "global"
            }
        }
    }

To stop receiving updates for a particular market, send a unsubscribe message that contains the markets you want to disconnect from.

Ticker unsubscribe message:

    {
    "event": "message",
    "data": {
        "operation": "unsubscribe",
        "options": {
            "currency_list": ["BTCUSD"],
            "symbol_set": "global"
        }
    }
}

Response

The response contains the markets grouped by their symbol set:

{
    "event": "message",
    "data":{
        "global": {
            "BTCUSD": {},
            "ETHEUR": {},
            ...
            },
        "crypto":{
            "ETHBTC": {},
            "BCHBTC": {},
            ...
        }
    }
}

The for each market contains the full ticker data:
Example for BTCUSD:

 {
    "ask": 7499.94,
    "bid": 7496.78,
    "last": 7504.12,
    "high": 7543.17,
    "low": 7292.06,
    "open": {
        "hour": 7498.96,
        "day": 7384.83,
        "week": 7568.76,
        "month": 9295.23,
        "month_3": 10626.22,
        "month_6": 9947.53,
        "year": 2253.65
    },
    "averages": {
        "day": 7429.10,
        "week": 7436.05,
        "month": 7491.99
    },
    "volume": 71213.17447933,
    "changes": {
        "price": {
            "hour": 5.17,
            "day": 119.29,
            "week": -64.64,
            "month": -1791.11,
            "month_3": -3122.10,
            "month_6": -2443.41,
            "year": 5250.47
        },
        "percent": {
            "hour": 0.07,
            "day": 1.62,
            "week": -0.85,
            "month": -19.27,
            "month_3": -29.38,
            "month_6": -24.56,
            "year": 232.98
        }
    },
    "volume_percent": 82.37,
    "timestamp": 1527746490,
    "display_timestamp": "2018-05-31 06:01:30"
}

Exchange channel

URL: wss://apiv2.bitcoinaverage.com/websocket/v2/exchanges

The authentication is exactly the same as the Ticker channel.

The format of the subscribe message is slightly different. Here instead of currency_list we have exchange_list parameter.

Exchange subscribe message:

{
    "event": "message",
    "data": {
        "operation": "subscribe",
        "options": {
            "exchange_list": ["bitstamp", "bitfinex"],
        }
    }
}

To stop receiving updates for an exchange, send a unsubscribe message

{
    "event": "message",
    "data": {
        "operation": "unsubscribe",
        "options": {
            "exchange_list": ["bitstamp"],
        }
    }
}

Reference to the documentation for the new Websocket API V2: https://apiv2.bitcoinaverage.com/#new-websocket-api-v2

If you need further assistance or you have any questions, please contact us at: info@bitcoinaverage.com

Leave a Reply

Your email address will not be published. Required fields are marked *