Bybit JavaScript SDK example: rest-v5-private.ts

Bybit REST V5 private JavaScript example. Read the source code, review its SDK calls, and browse related exchange integration examples.

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

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

examples/Bybit/Rest/rest-v5-private.ts

What this example covers

  • Bybit REST API JavaScript example.
  • Uses the Siebly Bybit SDK package bybit-api instead of hand-written HTTP request plumbing.
  • Source path: Bybit/Rest/rest-v5-private.ts.
  • Imports SDK symbols including RestClientV5.
  • Calls SDK methods such as getPositionInfo(), submitOrder().

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 { RestClientV5 } from 'bybit-api'; const key = process.env.API_KEY_COM;const secret = process.env.API_SECRET_COM; const client = new RestClientV5({  key: key,  secret: secret,}); (async () => {  try {    /** Simple examples for private REST API calls with bybit's V5 REST APIs */    const response = await client.getPositionInfo({      category: 'linear',      symbol: 'BTCUSDT',    });     console.log('response:', response);     // Trade USDT linear perps    const buyOrderResult = await client.submitOrder({      category: 'linear',      symbol: 'BTCUSDT',      orderType: 'Market',      qty: '1',      side: 'Buy',    });    console.log('buyOrderResult:', buyOrderResult);     const sellOrderResult = await client.submitOrder({      category: 'linear',      symbol: 'BTCUSDT',      orderType: 'Market',      qty: '1',      side: 'Sell',    });    console.log('sellOrderResult:', sellOrderResult);  } 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.