Register Account

Cloud9Trader API

WebSocket API

The WebSocket API can be connected to with native WebSocket over TCP. If you are developing in JavaScript, the WebSocket API Client Library will be the quickest way for you to get started.

The API can be connected to publicly or authenticated. The public socket provides real time market data - pricing, tickers, order books and the public trades feed. To initiate a public socket, connect to wss://sockets.cloud9trader.com/, for example in NodeJS:

const WebSocket = require("ws");

const socket = new WebSocket("wss://sockets.cloud9trader.com/");

socket.addEventListener("open", () => {
    console.info("Cloud9Trader socket open");
    socket.send(JSON.stringify(["subscribe", "order-book.XBTUSD:BitMEX"]));
});

socket.addEventListener("close", () => {
    console.info("Cloud9Trader socket closed");
});

socket.addEventListener("message", (event) => {
    try {
        let [topic, ...args] = JSON.parse(event.data);
        console.info("Cloud9Trader socket received", topic, ...args);
    } catch (error) {
        return console.error("Cloud9Trader socket could not parse incoming message");
    }
});

You'll notice messages are transmitted as stringified arrays of arguments. More information on that on the Message Structure page.

To submit orders and stream your balances, positions and other private data, you'll need an authenticated socket. Instructions are over on the WebSocket Authentication page.

Was this page useful? If you find any errors or have any questions please get in touch at support@cloud9trader.com.