From a4945d1cafe5ec8ca6f613ec7dc1a57621e3c9e4 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Fri, 24 Jan 2025 15:35:11 +0000 Subject: [PATCH] chore(): updates for pre-V5 deprecations --- README.md | 74 ++------------------------------------ src/util/BaseRestClient.ts | 38 +------------------- src/util/requestUtils.ts | 24 ------------- src/util/typeGuards.ts | 25 +++++++++++-- 4 files changed, 27 insertions(+), 134 deletions(-) diff --git a/README.md b/README.md index 598433c..52c7927 100644 --- a/README.md +++ b/README.md @@ -57,15 +57,14 @@ Node.js, JavaScript & TypeScript SDK for the Bybit REST APIs and WebSockets: ## Structure & Usage - [Structure](#structure) - [API Clients](#api-clients) -- [Usage](#usage) +- [REST API USAGE](#rest-api-usage) ## WebSocket Integration - [WebSockets](#websockets) - [WebSocket Subscriptions - Consuming Events](#websocket-subscriptions---consuming-events) - [Websocket API - Sending Orders via WebSockets](#websocket-api---sending-orders-via-websockets) - [Specifying Other Markets](#specifying-other-markets) -- [Load Balancing](#balancing-load-across-multiple-connections) -- [Older Websocket APIs](#older-websocket-apis) +- [Consumer Load Balancing](#balancing-load-across-multiple-connections) ## Additional Features - [Logging](#logging) @@ -154,7 +153,7 @@ Here are the available REST clients and the corresponding API groups described i | [WebsocketClient](src/websocket-client.ts) | All WebSocket Events (Public & Private for all API categories) | -### Usage +## REST API Usage Create API credentials on Bybit's website: @@ -257,38 +256,6 @@ client.getOrderbook({ category: 'linear', symbol: 'BTCUSDT' }) --- -### Deprecated/Obsolete REST APIs - -The following API clients are for previous generation REST APIs and will be removed in the next major release. Some have already stopped working (because bybit stopped supporting them). You should use the V5 APIs for all new development. - -
- Click me to read more - -Each generation is labelled with the version number (e.g. v1/v2/v3/v5). New projects & developments should use the newest available API generation (e.g. use the V5 APIs instead of V3). - - -| Class | Description | -| :--------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------: | -| [ **Derivatives v3** ] | The Derivatives v3 APIs (successor to the Futures V2 APIs) | -| [UnifiedMarginClient](src/unified-margin-client.ts) |[Derivatives (v3) Unified Margin APIs](https://bybit-exchange.github.io/docs/derivatives/unified/place-order) | -| [ContractClient](src/contract-client.ts) | [Derivatives (v3) Contract APIs](https://bybit-exchange.github.io/docs/derivatives/contract/place-order). | -| [ **Futures v2** ] | The Futures v2 APIs | -| [~~InverseClient~~](src/inverse-client.ts) | [Inverse Perpetual Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/inverse/) | -| [~~LinearClient~~](src/linear-client.ts) | [USDT Perpetual Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/linear/#t-introduction) | -| [~~InverseFuturesClient~~](src/inverse-futures-client.ts) | [Inverse Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/inverse_futures/#t-introduction) | -| [ **Spot** ] | The spot APIs | -| [SpotClientV3](src/spot-client-v3.ts) | [Spot Market (v3) APIs](https://bybit-exchange.github.io/docs/spot/public/instrument) | -| [~~SpotClient~~](src/spot-client.ts) (deprecated, SpotClientV3 recommended) | [Spot Market (v1) APIs](https://bybit-exchange.github.io/docs/spot/v1/#t-introduction) | -| [ **USDC Contract** ] | The USDC Contract APIs | -| [USDCPerpetualClient](src/usdc-perpetual-client.ts) | [USDC Perpetual APIs](https://bybit-exchange.github.io/docs/usdc/option/?console#t-querydeliverylog) | -| [USDCOptionClient](src/usdc-option-client.ts) | [USDC Option APIs](https://bybit-exchange.github.io/docs/usdc/option/#t-introduction) | -| [~~AccountAssetClient~~](src/account-asset-client.ts) | [Account Asset V1 APIs](https://bybit-exchange.github.io/docs/account_asset/v1/#t-introduction) | -| [ **Other** ] | Other standalone API groups | -| [CopyTradingClient](src/copy-trading-client.ts) | [Copy Trading APIs](https://bybit-exchange.github.io/docs/category/copy-trade) | -| [AccountAssetClientV3](src/account-asset-client-v3.ts) | [Account Asset V3 APIs](https://bybit-exchange.github.io/docs/account-asset/internal-transfer) | - -
- ## WebSockets The WebsocketClient will automatically use the latest V5 WebSocket endpoints by default. To use a different endpoint, use the `market` parameter. Except for the WebSocket API - this can be accessed without any special configuration. @@ -317,15 +284,6 @@ const wsConfig = { The following parameters are optional: */ - /** - * The API group this client should connect to. The V5 market is currently used by default. - * - * For the V3 APIs use `v3` as the market (spot/unified margin/usdc/account - * asset/copy trading). - * Note that older API groups are deprecated and may stop working soon. - */ - // market: 'v5', - /** * Set to `true` to connect to Bybit's testnet environment. * - If demo trading, `testnet` should be set to false! @@ -553,32 +511,6 @@ Important: do not subscribe to the same topics on both clients or you will recei --- -### Older Websocket APIs - -The following API groups are still available in the WebsocketClient but are deprecated and may no longer work. They will be removed in the next major release: - -
- Click me to see the table - -| API Category | Market | Description | -| :------------------------------: | :-------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| ~~Unified Margin - Options~~ | `market: 'unifiedOption'` | The [derivatives v3](https://bybit-exchange.github.io/docs/derivativesV3/unified_margin/#t-websocket) category for unified margin. Note: public topics only support options topics. If you need USDC/USDT perps, use `unifiedPerp` instead. | -| ~~Unified Margin - Perps~~ | `market: 'unifiedPerp'` | The [derivatives v3](https://bybit-exchange.github.io/docs/derivativesV3/unified_margin/#t-websocket) category for unified margin. Note: public topics only support USDT/USDC perpetual topics - use `unifiedOption` if you need public options topics. | -| ~~Futures v2 - Inverse Perps~~ | `market: 'inverse'` | The [inverse v2 perps](https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-websocket) category. | -| ~~Futures v2 - USDT Perps~~ | `market: 'linear'` | The [USDT/linear v2 perps](https://bybit-exchange.github.io/docs/futuresV2/linear/#t-websocket) category. | -| ~~Futures v2 - Inverse Futures~~ | `market: 'inverse'` | The [inverse futures v2](https://bybit-exchange.github.io/docs/futuresV2/inverse_futures/#t-websocket) category uses the same market as inverse perps. | -| ~~Spot v3~~ | `market: 'spotv3'` | The [spot v3](https://bybit-exchange.github.io/docs/spot/v3/#t-websocket) category. | -| ~~Spot v1~~ | `market: 'spot'` | The older [spot v1](https://bybit-exchange.github.io/docs/spot/v1/#t-websocket) category. Use the `spotv3` market if possible, as the v1 category does not have automatic re-subscribe if reconnected. | -| ~~Copy Trading~~ | `market: 'linear'` | The [copy trading](https://bybit-exchange.github.io/docs/copy_trading/#t-websocket) category. Use the linear market to listen to all copy trading topics. | -| ~~USDC Perps~~ | `market: 'usdcPerp` | The [USDC perps](https://bybit-exchange.github.io/docs/usdc/perpetual/#t-websocket) category. | -| ~~USDC Options~~ | `market: 'usdcOption'` | The [USDC options](https://bybit-exchange.github.io/docs/usdc/option/#t-websocket) category. | -| ~~Contract v3 USDT~~ | `market: 'contractUSDT'` | The [Contract V3](https://bybit-exchange.github.io/docs/derivativesV3/contract/#t-websocket) category (USDT perps) | -| ~~Contract v3 Inverse~~ | `market: 'contractInverse'` | The [Contract V3](https://bybit-exchange.github.io/docs/derivativesV3/contract/#t-websocket) category (inverse perps) | - -
{ @@ -72,7 +70,7 @@ interface UnsignedRequest { recvWindow?: number; } -type SignMethod = 'v2auth' | 'v5auth'; +type SignMethod = 'v5auth'; export default abstract class BaseRestClient { private timeOffset: number | null = null; @@ -443,40 +441,6 @@ export default abstract class BaseRestClient { return res; } - // spot/v2 derivatives - if (signMethod === 'v2auth') { - res.originalParams.api_key = key; - res.originalParams.timestamp = timestamp; - - // Optional, set to 5000 by default. Increase if timestamp/recv_window errors are seen. - if (recvWindow) { - res.originalParams.recv_window = recvWindow; - } - const sortProperties = true; - const encodeValues = false; - - res.serializedParams = serializeParams( - res.originalParams, - strictParamValidation, - sortProperties, - encodeValues, - ); - res.sign = await this.signMessage( - res.serializedParams, - this.secret, - 'hex', - 'SHA-256', - ); - - // @ts-ignore - res.paramsWithSign = { - ...res.originalParams, - sign: res.sign, - }; - - return res; - } - return res; } diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index 751482b..b067c6d 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -1,10 +1,5 @@ import { AxiosResponse } from 'axios'; import { APIRateLimit } from '../types'; -import { - WebsocketSucceededTopicSubscriptionConfirmationEvent, - WebsocketTopicSubscriptionConfirmationEvent, -} from '../types/websockets/ws-confirmations'; -import { WSAPIResponse, WS_API_Operations } from '../types/websockets/ws-api'; export interface RestClientOptions { /** Your API key */ @@ -188,25 +183,6 @@ export function isWsPong(msg: any): boolean { ); } -export function isTopicSubscriptionConfirmation( - msg: unknown, -): msg is WebsocketTopicSubscriptionConfirmationEvent { - if (typeof msg !== 'object') { - return false; - } - if (!msg) { - return false; - } - if (typeof msg['op'] !== 'string') { - return false; - } - if (msg['op'] !== 'subscribe') { - return false; - } - - return true; -} - export const APIID = 'bybitapinode'; /** diff --git a/src/util/typeGuards.ts b/src/util/typeGuards.ts index f4bcc67..f721f99 100644 --- a/src/util/typeGuards.ts +++ b/src/util/typeGuards.ts @@ -2,7 +2,10 @@ * Use type guards to narrow down types with minimal efforts. */ -import { WebsocketSucceededTopicSubscriptionConfirmationEvent } from '../types'; +import { + WebsocketSucceededTopicSubscriptionConfirmationEvent, + WebsocketTopicSubscriptionConfirmationEvent, +} from '../types'; import { WSAPIResponse, WS_API_Operations } from '../types/websockets/ws-api'; import { WSAccountOrderEventV5, @@ -10,7 +13,6 @@ import { WSOrderbookEventV5, WSPositionEventV5, } from '../types/websockets/ws-events'; -import { isTopicSubscriptionConfirmation } from './requestUtils'; /** * Type guard to detect a V5 orderbook event (delta & snapshots) @@ -120,3 +122,22 @@ export function isTopicSubscriptionSuccess( if (!isTopicSubscriptionConfirmation(msg)) return false; return msg.success === true; } + +export function isTopicSubscriptionConfirmation( + msg: unknown, +): msg is WebsocketTopicSubscriptionConfirmationEvent { + if (typeof msg !== 'object') { + return false; + } + if (!msg) { + return false; + } + if (typeof msg['op'] !== 'string') { + return false; + } + if (msg['op'] !== 'subscribe') { + return false; + } + + return true; +}