Coinbase Institutional CBInternational Exchange cb intx websocket JavaScript example for the Siebly Coinbase SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.
We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.
coinbase-api instead of hand-written HTTP request plumbing.Coinbase/Institutional/CBInternationalExchange/cb-intx-ws.ts.WebsocketClient.on(), subscribe().import 'dotenv/config'; import { WebsocketClient, WsTopicRequest } from 'coinbase-api'; const client = new WebsocketClient( { apiKey: process.env.CB_INTX_API_KEY!, apiSecret: process.env.CB_INTX_API_SECRET!, apiPassphrase: process.env.CB_INTX_API_PASSPHRASE!, }, // logger,); client.on('open', (data) => { console.log('open: ', data?.wsKey);}); // Data receivedclient.on('update', (data) => { console.info(new Date(), 'data received: ', JSON.stringify(data));}); // Something happened, attempting to reconnectclient.on('reconnect', (data) => { console.log('reconnect: ', data);}); // Reconnect successfulclient.on('reconnected', (data) => { console.log('reconnected: ', data);}); // Connection closed. If unexpected, expect reconnect -> reconnected.client.on('close', (data) => { console.error('close: ', data);}); // Reply to a request, e.g. "subscribe"/"unsubscribe"/"authenticate"client.on('response', (data) => { console.info('response: ', JSON.stringify(data, null, 2));}); client.on('exception', (data) => { console.error('exception: ', data);}); const OrderbookSubscribeRequest: WsTopicRequest = { topic: 'LEVEL1', // ws topic /** * Anything in the payload will be merged into the subscribe "request", * allowing you to send misc parameters supported by the exchange (such as `product_ids: string[]`) */ payload: { product_ids: ['BTC-PERP'], },};client.subscribe(OrderbookSubscribeRequest, 'internationalMarketData'); We use essential cookies and optional analytics. Read the Privacy Policy.
Essential cookies stay on. Toggle analytics if you want to share anonymous usage insights. You can revisit this anytime via Cookie Settings in the footer.