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 uses a simple, pluggable logger interface. By default, info and error messages are printed to the console via console.info and console.error. Trace-level messages — such as raw ping/pong frames and internal reconnect events — are silenced by default but can be enabled for debugging. You can replace the logger entirely, selectively override methods, or suppress all output.
The DefaultLogger
The SDK exports aDefaultLogger object with three methods that match the full logger interface:
trace— verbose internal events: ping/pong heartbeats, raw WebSocket frames, subscription bookkeeping. Silent by default.info— connection lifecycle messages: connections opened, subscriptions confirmed, reconnects completed.error— errors and unexpected states that require attention.
Passing a Custom Logger
BothRestClientV5 and WebsocketClient accept a logger as a constructor argument. The logger must implement trace, info, and error methods.
WebsocketClient
Pass the logger as the second argument toWebsocketClient:
RestClientV5
The REST client uses the same logger interface but receives it inside the first options object (there is no dedicated logger parameter — use theBYBITTRACE env var for HTTP-level debugging instead). For WebSocket-level logging, the WebsocketClient constructor is the primary place to inject a logger.
Enabling Trace-Level Logging
The most common customisation is enablingtrace output to see what the WebSocket client is doing internally. Spread DefaultLogger and override the trace method:
trace enabled you will see:
- Heartbeat ping/pong frames
- Subscription request/response cycles
- Raw message parsing
- Reconnect timing and state transitions
Suppressing All Logs
To run the SDK silently — for example in test suites — provide no-op functions for all three methods:Routing Logs to a Structured Logger
You can route SDK output to any structured logging library such aspino or winston by mapping the three methods:
Debugging Raw HTTP Requests with BYBITTRACE
For situations where you need to inspect the exact HTTP request the REST client is sending — including headers, signed parameters, and the raw response body — set theBYBITTRACE environment variable before running your process:
BYBITTRACE is set, the SDK installs an axios response interceptor that logs the following for every HTTP response:
- Request URL, method, headers, and body/params
- Response status code, headers, and data
Production Logging Recommendations
Keep trace disabled
Leave
trace as a no-op in production. The volume of ping/pong and frame events will flood your log pipeline and obscure meaningful signals.Always log errors
Ensure
error is routed to a durable log destination or alerting system. WebSocket exceptions and API errors surfaced at the error level indicate conditions that may require intervention.Add context to log entries
When building multi-account or multi-symbol systems, include an account or connection identifier in each log call so you can correlate events across connections.
Never enable BYBITTRACE in production
The
BYBITTRACE interceptor logs raw API keys and secrets. Restrict its use to local debugging only.Configuration
Full reference for RestClientV5 and WebsocketClient options
Error Handling
Handle API errors and interpret response codes