Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions sdks/bybit/docs/guides/orders.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Query the same order:
node --env-file=.env first-order.ts status
```

The status command reads [`getActiveOrders()`](/api/classes/RestClientV5#getactiveorders), then [`getHistoricOrders()`](/api/classes/RestClientV5#gethistoricorders) if the order is absent. Inspect `orderStatus`, `cumExecQty` and `leavesQty`. A `New` or `PartiallyFilled` order can have remaining quantity to cancel:
The status command makes one [`getActiveOrders()`](/api/classes/RestClientV5#getactiveorders) request using the returned order ID. Despite the method name, this also returns recent closed orders. Inspect `orderStatus`, `cumExecQty` and `leavesQty`. A `New` or `PartiallyFilled` order can have remaining quantity to cancel:

```sh
node --env-file=.env first-order.ts cancel
Expand All @@ -73,7 +73,9 @@ A timeout or lost response can happen after Bybit accepts a request. The example

If you received an `orderId`, query `status` with that ID and the same account. If submission timed out before returning an ID, inspect realtime orders and order history for BTCUSDT, and reconcile executions and positions using the request time, side, price and quantity. Avoid resubmitting until the outcome is resolved.

An empty result is inconclusive: recent closed orders can disappear from the realtime endpoint after a service restart, and history can lag. See [open and closed orders](https://bybit-exchange.github.io/docs/v5/order/open-order).
For older records, or closed orders no longer available after a service restart, use [`getHistoricOrders()`](/api/classes/RestClientV5#gethistoricorders). Set `orderStatus: 'Cancelled'` when looking for a cancelled order; from 3 December 2026, unfiltered recent history excludes `Cancelled`, `Rejected` and `Deactivated`.

An empty result is inconclusive, and history can lag behind order updates. See [open and closed orders](https://bybit-exchange.github.io/docs/v5/order/open-order).

Stopping the process or closing a WebSocket does not cancel an open order.

Expand Down
2 changes: 1 addition & 1 deletion sdks/bybit/docs/guides/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ description: "Diagnose Bybit installation, authentication, response and WebSocke
| Promise resolves, but the operation failed | Inspect `retCode` and `retMsg`; default REST behaviour does not throw on nonzero `retCode`. |
| Empty ticker list | Check the symbol and `category`. Verify the instrument exists in that market and environment. |
| API key or permission error | Match the key to live, Testnet or demo; check account permissions and IP restrictions. |
| Timestamp or receive-window error | Synchronize the host clock, check network latency, and review `recv_window`. |
| Timestamp or receive-window error | Synchronize the host clock, check network latency, and review `recv_window` for REST or `recvWindow` for WebSocket authentication. |
| HTTP or rate-limit rejection | Inspect HTTP status and exchange code separately; slow down using the current endpoint limits. |
| No WebSocket market data | Register an `update` listener before subscribing; inspect `exception`, topic and category. |
| Old data after a reconnect | Reconcile application state and apply the topic's snapshot/delta rules. |
Expand Down
2 changes: 1 addition & 1 deletion sdks/bybit/docs/guides/websockets.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Save this as `stream.ts` in a TypeScript project. It prints updates for 30 secon

## Subscription results and messages

Await the subscription promise and catch failures. Market data arrives on `update`; `response` carries subscription replies.
`subscribeV5()` returns an array of promises, so use `Promise.all()` to await them. With the default settings, completion does not mean Bybit accepted the subscription. Successful subscription replies arrive on `response`; rejected requests arrive on `exception`. Market data arrives on `update`.

## Recover after a disconnect

Expand Down
10 changes: 2 additions & 8 deletions sdks/bybit/examples/first-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,11 @@ function requiredEnvVar(name: string): string {

async function printOrderStatus(client: RestClientV5, orderId: string) {
const query = { category: 'linear' as const, symbol: 'BTCUSDT', orderId };
// Realtime results include recent closed orders; use history if absent.
// Realtime results include recent closed orders.
const activeResponse = await client.getActiveOrders(query);
let order = activeResponse.result.list.find(
const order = activeResponse.result.list.find(
(item) => item.orderId === orderId,
);
if (!order) {
const historyResponse = await client.getHistoricOrders(query);
order = historyResponse.result.list.find(
(item) => item.orderId === orderId,
);
}
if (!order) {
throw new Error(
'Order not found. Check Testnet order history before placing another order.',
Expand Down
6 changes: 2 additions & 4 deletions sdks/bybit/examples/private-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ function main() {
if (stopped) {
return;
}
if (message.op !== 'subscribe') {
console.log('Private stream response:', message);
} else if (message.success === true) {
if (message.op === 'subscribe' && message.success === true) {
console.log('Subscribed to order.linear. Waiting for order changes.');
} else {
console.error('Private subscription rejected:', message);
console.log('Private stream response:', message);
}
});
ws.on('update', (message) => {
Expand Down
18 changes: 11 additions & 7 deletions sdks/bybit/examples/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ const ws = new WebsocketClient({});
let stopped = false;
let timer: ReturnType<typeof setTimeout> | undefined;
function stop() {
if (stopped) return;
if (stopped) {
return;
}
stopped = true;
clearTimeout(timer);
ws.closeAll();
}
process.once('SIGINT', stop);
process.once('SIGTERM', stop);
ws.on('update', (message) => console.log(message));
ws.on('exception', () => {
console.error('WebSocket exception. Check the topic, environment and connection.');
});
ws.on('response', (message) => console.log('Subscription response:', message));
ws.on('exception', (error) => console.error('WebSocket exception:', error));
async function main() {
// Subscription acceptance is reported by response, and rejection by exception.
await Promise.all(ws.subscribeV5('tickers.BTCUSDT', 'spot'));
if (!stopped) timer = setTimeout(stop, 30000);
if (!stopped) {
timer = setTimeout(stop, 30000);
}
}
main().catch(() => {
console.error('Subscription failed.');
main().catch((error) => {
console.error('Could not start the stream:', error);
process.exitCode = 1;
stop();
});
Loading