Coinbase Institutional CBInternational Exchange JavaScript SDK example: cb-intx-ws.ts

Coinbase Institutional CBInternational Exchange cb intx websocket JavaScript example. Review the source code and SDK calls in the matching GitHub example.

This example uses coinbase-api, the JavaScript and TypeScript SDK for Coinbase. Install it with npm install coinbase-api.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Coinbase/Institutional/CBInternationalExchange/cb-intx-ws.ts

What this example covers

  • Coinbase exchange API JavaScript example.
  • Uses the Siebly Coinbase SDK package coinbase-api instead of hand-written HTTP request plumbing.
  • Source path: Coinbase/Institutional/CBInternationalExchange/cb-intx-ws.ts.
  • Example category: Institutional CBInternational Exchange.
  • Imports SDK symbols including WebsocketClient.
  • Calls SDK methods such as on(), subscribe().

How to use this example

  • Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
  • Open the repository source when you need the latest committed version: GitHub source file.
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'); 

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.