Stream Orderbook
Stream the order book
The order book is a dynamic electronic list of buy and sell orders for an asset (in this case, cryptocurrencies) organised by price level. You can receive real-time updates on the Buycoins order book by connecting to our order book WebSockets API.

General considerations

  • All messages sent and received via WebSockets are encoded in binary format.
  • Please use the getPairs query to retrieve the list of pairs which you can subscribe to updates for using the WebSockets API.
    • Our getPairs query returns pairs in this format ${baseCurrency}_${quoteCurrency} . The WebSockets API requires pairs in this format ${baseCurrency}/${quoteCurrency}
    • For example, (GraphQL API) btc_usdt -> (WebSockets API) BTC/USDT

Streaming order book updates

Endpoint: wss://markets.buycoins.tech/ws?pair=${PAIR}
You should immediately start receiving a stream of binary-encoded protocol buffer messages once you successfully connect to the endpoint provided above with a valid currency pair. To decode the binary-encoded protocol buffer messages, you'll need to use one of our protocol buffer client libraries:

Connecting to the WebSocket API

1
// JavaScript example
2
3
import {Orderbook} from 'public-protos-js/proto/orderbook_socket/v1/orderbook_pb';
4
5
const baseUrl = `wss://markets.buycoins.tech/ws?pair=BTC/USDT`;
6
7
const orderbookSocket = new WebSocket(baseUrl);
8
orderbookSocket.binaryType = 'arraybuffer';
9
10
window.orderbookSocket.addEventListener('open', () => {
11
console.log('Disconnected from orderbook WebSocket API');
12
});
13
14
window.orderbookSocket.addEventListener('close', () => {
15
console.log('Disconnected from orderbook WebSocket API');
16
// Implement reconnection logic here..
17
});
18
19
window.orderbookSocket.addEventListener('message', ({ data }) => {
20
console.log('Order Book update received');
21
const market = Orderbook.deserializeBinary(data).toObject();
22
console.log(market);
23
});
24
Copied!
Last modified 7mo ago