TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/bybit-api/llms.txt
Use this file to discover all available pages before exploring further.
bybit-api SDK is primarily designed for Node.js, but it can be used in browser-based projects through two approaches. The direct import method is the modern approach, suitable for TypeScript and React projects that use a bundler such as Vite or webpack 5. The webpack bundle method produces a pre-built UMD file you can include with a <script> tag on any webpage.
Approach 1: Direct Import (Modern)
This approach lets you importbybit-api directly into a TypeScript or JavaScript frontend project. A Node.js stream polyfill is required because the SDK has a transitive dependency on the Node.js stream module, which is not available natively in browsers.
Add a
paths entry to your tsconfig.json so the TypeScript compiler and your bundler resolve stream to the browser-compatible polyfill:Browsers do not define a
global variable the way Node.js does. Declare it in your application’s entry point or polyfills file (for example polyfills.ts in Angular, or the top of main.ts/index.ts in other frameworks):The
https.Agent-based keep-alive feature (keepAlive: true) is Node.js-only and is automatically excluded from browser builds via the webpack fallback configuration in the SDK. Browser connection pooling is handled natively by the browser.Approach 2: Webpack Bundle (Legacy)
This is the traditional way to usebybit-api on a webpage without a module bundler in the frontend project. The SDK repository includes a webpack configuration that produces a minified UMD bundle.
The output file
bybitapi.js (and its source map) will be written to the dist/ directory at the root of the repository.<script src="dist/bybitapi.js"></script>
<script>
// The UMD bundle exposes the library under the global 'bybitapi' name
const client = new bybitapi.RestClientV5();
client.getOrderbook({ category: 'linear', symbol: 'BTCUSDT' })
.then(result => console.log('Orderbook:', result))
.catch(err => console.error('Error:', err));
</script>
libraryTarget: 'umd'), which means the bundle works as a <script> tag include, a CommonJS require(), or an AMD define() module.
What the webpack config excludes
The SDK’s webpack configuration explicitly disables the Node.jshttp and https modules via the resolve.fallback option:
keepAlive option (which uses https.Agent) is not available in the webpack bundle. All other REST and WebSocket features work as normal.
Security Considerations
Use a proxy server for private endpoints
Route any request that requires API credentials through a backend server you control. Your server holds the API key and secret, signs the request, and forwards it to Bybit. The browser only ever communicates with your own server.
Public endpoints are safe to call directly
Endpoints that do not require authentication — such as market data, orderbooks, and klines — can be called directly from the browser without exposing credentials.
Restrict API key permissions and IPs
If you must use credentials in a browser context during development or testing, create a dedicated API key with minimal permissions and IP restrictions. Revoke it as soon as it is no longer needed.
Configuration
Full reference for RestClientV5 and WebsocketClient options
Environments
Use testnet or demo trading for development