WebSocket API

Public methods

Get the current order book data

Open a connection to a public hub: [base]/marketdata/info

The order book channel name is Book.

Note

Upon subscription, a complete order book snapshot is sent (snapshot: true); all subsequent responses contain only updates to it, and not the entire book (snapshot: false).

REQUEST EXAMPLE
const { HubConnectionBuilder } = require("@microsoft/signalr"); // Package version must be >= 5.0.0

const url = "https://host.name/marketdata/info"; // Change [host.name] to your host name
const instrument = "btc_usd";
const channel = 'Book';

let connection = new HubConnectionBuilder()
    .withUrl(url)
    .build();

connection.start().then(function () {
connection.stream(channel, instrument)
    .subscribe({
        next: (item) => {
		console.log(JSON.stringify(item));
        },
        error: (err) => {
            console.log(err);
        },
});
});

Response

See Get an order book snapshot to learn more about the response data.


Get the current exchange status

Open a connection to a public hub: [base]/status-api/ws

One of the following exchange statuses is returned:

  • online

  • maintenance

  • down

The Status channel name is status.

REQUEST EXAMPLE
const { HubConnectionBuilder } = require("@microsoft/signalr");
const url = "https://host.name/status-api/ws"; // Change [host.name] to your host name

let connection = new HubConnectionBuilder()
  .withUrl(url)
  .build();

connection.start().then(function () {
  connection.stream('status')
    .subscribe({
      next: (item) => {
        console.log(JSON.stringify(item));
      },
      error: (err) => {
        console.log(err);
      },
    });
});

Response

RESPONSE BODY EXAMPLE
    {
        "exchangeStatus":"maintenance",
    }

Private methods

Get the stop orders data

Open a connection to a private hub: [base]/frontoffice/ws/stoporders

The channel name for receiving data about placed stop orders is OpenStopOrders.

REQUEST EXAMPLE
const { HubConnectionBuilder } = require("@microsoft/signalr"); // Package version must be >= 5.0.0
const crypto = require("crypto");
const Key = "1ff8924f-bf2..."; // Change to your PublicKey
const Secret = "cd91a3a6-f36..."; // Change to your Secret
const Payload = new Date().toISOString();
const Sign = crypto
  .createHmac('sha512', Secret)
  .update(Payload)
  .digest('hex')
  .toUpperCase();
const headers = {
  Key,
  Payload,
  Sign
};
const url = "[host.name]/frontoffice/ws/stoporders"; // Change [host.name] to your host name
const channel = "OpenStopOrders";
let connection = new HubConnectionBuilder()
  .withUrl(url, {headers: headers})
  .build();

connection.start().then(function () {
  connection.stream(channel)
    .subscribe({
      next: (item) => {
        console.log(JSON.stringify(item));
      },
      error: (err) => {
        console.log(err);
      },
    });
});

Response

Upon subscription, returns a Stop Order object.


Get the orders data

Open a connection to a private hub: [base]/frontoffice/ws/account

The channel name for receiving data about placed orders is OpenOrders.

REQUEST EXAMPLE
const { HubConnectionBuilder } = require("@microsoft/signalr"); // Package version must be >= 5.0.0
const crypto = require("crypto");
const Key = "7fa6ceec-d8fc..."; // Change to your PublicKey
const Secret = "7ae49b5b-99db..."; // Change to your Secret
const Payload = new Date().toISOString();
	const Sign = crypto
	.createHmac('sha512', Secret)
	.update(Payload)
	.digest('hex')
	.toUpperCase();
const headers = {
    Key,
    Payload,
    Sign
};

const url = "https://host.name/frontoffice/ws/account"; // Change [host.name] to your host name
const channel = "OpenOrders";
let connection = new HubConnectionBuilder()
    .withUrl(url, {headers: headers})
    .build();

connection.start().then(function () {
connection.stream(channel)
    .subscribe({
        next: (item) => {
		console.log(JSON.stringify(item));
        },
        error: (err) => {
            console.log(err);
        },
});
});

Response

Upon subscription, returns an Order object.


Get current balances

Open a connection to a private hub: [base]/frontoffice/ws/account

The channel name for receiving balance updates is FullBalance.

REQUEST EXAMPLE
const { HubConnectionBuilder } = require("@microsoft/signalr"); // Package version must be >= 5.0.0
const crypto = require("crypto");
const Key = "7fa6ceec-d8fc..."; // Change to your PublicKey
const Secret = "7ae49b5b-99db..."; // Change to your Secret
const Payload = new Date().toISOString();
	const Sign = crypto
	.createHmac('sha512', Secret)
	.update(Payload)
	.digest('hex')
	.toUpperCase();
const headers = {
    Key,
    Payload,
    Sign
};

const url = "https://host.name/frontoffice/ws/account"; // Change [host.name] to your host name
const channel = "FullBalance";
let connection = new HubConnectionBuilder()
    .withUrl(url, {headers: headers})
    .build();

connection.start().then(function () {
connection.stream(channel, {})
    .subscribe({
        next: (item) => {
		console.log(JSON.stringify(item));
        },
        error: (err) => {
            console.log(err);
        },
});
});

Response

asset string

The asset name

amount number

The asset amount

balance number

The total asset amount on a balance

locked number

The locked asset amount on a balance

RESPONSE BODY EXAMPLE
[
    {
        "asset": "ada",
        "amount": 1000000000,
        "balance": 1000000000,
        "locked": 0
    },
    {
        "asset": "bch",
        "amount": 9999999.99999999,
        "balance": 9999999.99999999,
        "locked": 0
    }
]