diff --git a/sdks/bybit/docs/guides/orders.md b/sdks/bybit/docs/guides/orders.md index 27f24e5a..2442e7cb 100644 --- a/sdks/bybit/docs/guides/orders.md +++ b/sdks/bybit/docs/guides/orders.md @@ -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 @@ -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. diff --git a/sdks/bybit/docs/guides/troubleshooting.md b/sdks/bybit/docs/guides/troubleshooting.md index 1c00aa7e..b17b9e11 100644 --- a/sdks/bybit/docs/guides/troubleshooting.md +++ b/sdks/bybit/docs/guides/troubleshooting.md @@ -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. | diff --git a/sdks/bybit/docs/guides/websockets.md b/sdks/bybit/docs/guides/websockets.md index f6e41a23..9f785ddf 100644 --- a/sdks/bybit/docs/guides/websockets.md +++ b/sdks/bybit/docs/guides/websockets.md @@ -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 diff --git a/sdks/bybit/examples/first-order.ts b/sdks/bybit/examples/first-order.ts index f403c8de..c1e23fd3 100644 --- a/sdks/bybit/examples/first-order.ts +++ b/sdks/bybit/examples/first-order.ts @@ -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.', diff --git a/sdks/bybit/examples/private-stream.ts b/sdks/bybit/examples/private-stream.ts index 7c33125a..5734f7fd 100644 --- a/sdks/bybit/examples/private-stream.ts +++ b/sdks/bybit/examples/private-stream.ts @@ -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) => { diff --git a/sdks/bybit/examples/stream.ts b/sdks/bybit/examples/stream.ts index a3cd908f..f30efb01 100644 --- a/sdks/bybit/examples/stream.ts +++ b/sdks/bybit/examples/stream.ts @@ -4,7 +4,9 @@ const ws = new WebsocketClient({}); let stopped = false; let timer: ReturnType | undefined; function stop() { - if (stopped) return; + if (stopped) { + return; + } stopped = true; clearTimeout(timer); ws.closeAll(); @@ -12,15 +14,17 @@ function stop() { 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(); });