OKX JavaScript SDK example: rest-public.ts

OKX REST public JavaScript example for the Siebly OKX 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.

examples/OKX/Rest/rest-public.ts

What this example covers

  • OKX REST API JavaScript example.
  • Uses the Siebly OKX SDK package okx-api instead of hand-written HTTP request plumbing.
  • Source path: OKX/Rest/rest-public.ts.
  • Imports SDK symbols including RestClient.
  • Calls SDK methods such as getInstruments().

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 { RestClient } from 'okx-api'; const client = new RestClient(); /** * This is a simple script wrapped in a immediately invoked function expression, designed to make public API calls without credentials */(async () => {  try {    const results = await client.getInstruments({ instType: 'SPOT' });     console.log(      'result: ',      results.filter((row) => row.baseCcy === 'SUI'),    );     return;  } catch (e) {    console.error('request failed: ', e);  }})(); 

Subscribe on Substack

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