bybit-api
Advanced tools
Comparing version 3.7.8 to 3.8.0
@@ -114,5 +114,13 @@ import { AccountTypeV5, CategoryV5 } from '../v5-shared'; | ||
username: string; | ||
password?: string; | ||
/** | ||
* 1: normal, 6: custodial | ||
*/ | ||
memberType: 1 | 6; | ||
/** | ||
* 0: quick login disabled (default), 1: quick login enabled | ||
*/ | ||
switch?: 0 | 1; | ||
isUta?: boolean; | ||
note?: string; | ||
} |
@@ -0,1 +1,2 @@ | ||
import WebSocket from 'isomorphic-ws'; | ||
import { APIMarket, CategoryV5, WsKey } from '../types'; | ||
@@ -61,2 +62,8 @@ import { DefaultLogger } from './logger'; | ||
export declare function neverGuard(x: never, msg: string): Error; | ||
/** | ||
* #305: ws.terminate() is undefined in browsers. | ||
* This only works in node.js, not in browsers. | ||
* Does nothing if `ws` is undefined. | ||
*/ | ||
export declare function safeTerminateWs(ws?: WebSocket | unknown): void; | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.neverGuard = exports.WS_ERROR_ENUM = exports.getUsdcWsKeyForTopic = exports.getMaxTopicsPerSubscribeEvent = exports.getWsUrl = exports.getWsKeyForTopic = exports.isPrivateWsTopic = exports.PUBLIC_WS_KEYS = exports.WS_AUTH_ON_CONNECT_KEYS = exports.WS_KEY_MAP = exports.WS_BASE_URL_MAP = void 0; | ||
exports.safeTerminateWs = exports.neverGuard = exports.WS_ERROR_ENUM = exports.getUsdcWsKeyForTopic = exports.getMaxTopicsPerSubscribeEvent = exports.getWsUrl = exports.getWsKeyForTopic = exports.isPrivateWsTopic = exports.PUBLIC_WS_KEYS = exports.WS_AUTH_ON_CONNECT_KEYS = exports.WS_KEY_MAP = exports.WS_BASE_URL_MAP = void 0; | ||
exports.WS_BASE_URL_MAP = { | ||
@@ -487,2 +487,14 @@ inverse: { | ||
exports.neverGuard = neverGuard; | ||
/** | ||
* #305: ws.terminate() is undefined in browsers. | ||
* This only works in node.js, not in browsers. | ||
* Does nothing if `ws` is undefined. | ||
*/ | ||
function safeTerminateWs(ws) { | ||
// #305: ws.terminate() undefined in browsers | ||
if (ws && typeof ws['terminate'] === 'function') { | ||
ws.terminate(); | ||
} | ||
} | ||
exports.safeTerminateWs = safeTerminateWs; | ||
//# sourceMappingURL=websocket-util.js.map |
@@ -247,3 +247,3 @@ "use strict"; | ||
if (force) { | ||
ws === null || ws === void 0 ? void 0 : ws.terminate(); | ||
util_1.safeTerminateWs(ws); | ||
} | ||
@@ -509,10 +509,12 @@ } | ||
executeReconnectableClose(wsKey, reason) { | ||
var _a; | ||
this.logger.info(`${reason} - closing socket to reconnect`, Object.assign(Object.assign({}, loggerCategory), { wsKey, | ||
reason })); | ||
const wasOpen = this.wsStore.isWsOpen(wsKey); | ||
(_a = this.getWs(wsKey)) === null || _a === void 0 ? void 0 : _a.terminate(); | ||
delete this.wsStore.get(wsKey, true).activePongTimer; | ||
this.clearPingTimer(wsKey); | ||
this.clearPongTimer(wsKey); | ||
const ws = this.getWs(wsKey); | ||
if (ws) { | ||
ws.close(); | ||
util_1.safeTerminateWs(ws); | ||
} | ||
if (!wasOpen) { | ||
@@ -519,0 +521,0 @@ this.logger.info(`${reason} - socket already closed - trigger immediate reconnect`, Object.assign(Object.assign({}, loggerCategory), { wsKey, |
{ | ||
"name": "bybit-api", | ||
"version": "3.7.8", | ||
"version": "3.8.0", | ||
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
129
README.md
@@ -34,4 +34,4 @@ # Node.js & JavaScript SDK for Bybit REST API & WebSockets | ||
- Try my connectors: | ||
- [bybit-api](https://www.npmjs.com/package/bybit-api) | ||
- [binance](https://www.npmjs.com/package/binance) | ||
- [bybit-api](https://www.npmjs.com/package/bybit-api) | ||
- [okx-api](https://www.npmjs.com/package/okx-api) | ||
@@ -48,3 +48,4 @@ - [bitget-api](https://www.npmjs.com/package/bitget-api) | ||
- [Bybit API Docs (choose API category from the tabs at the top)](https://bybit-exchange.github.io/docs/v5/intro). | ||
- [Bybit API Docs](https://bybit-exchange.github.io/docs/v5/intro) | ||
- [TSDoc Documentation (generated using typedoc via npm module)](https://tsdocs.dev/docs/bybit-api) | ||
@@ -71,26 +72,41 @@ ## Structure | ||
| Class | Description | | ||
| :------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | ||
| [ **V5 API** ] | The new unified V5 APIs (successor to previously fragmented APIs for all API groups). To learn more about the V5 API, please read the [V5 upgrade guideline](https://bybit-exchange.github.io/docs/v5/upgrade-guide). | | ||
| [RestClientV5](src/rest-client-v5.ts) | Unified V5 all-in-one REST client for all [V5 REST APIs](https://bybit-exchange.github.io/docs/v5/intro) | | ||
| [ **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 | | ||
| Deprecated! RestClientV5 recommended | Please read the [V5 interface mapping page](https://bybit-exchange.github.io/docs/v5/intro#v5-and-v3-interface-mapping-list) | | ||
| [~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) | | ||
| [ **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) | | ||
| [~AccountAssetClient~](src/account-asset-client.ts) (deprecated, AccountAssetClientV3 recommended) | [Account Asset V1 APIs](https://bybit-exchange.github.io/docs/account_asset/v1/#t-introduction) | | ||
| [WebsocketClient](src/websocket-client.ts) | All WebSocket Events (Public & Private for all API categories) | | ||
| Class | Description | | ||
| :----------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | ||
| [ **V5 API** ] | The new unified V5 APIs (successor to previously fragmented APIs for all API groups). To learn more about the V5 API, please read the [V5 upgrade guideline](https://bybit-exchange.github.io/docs/v5/upgrade-guide). | | ||
| [RestClientV5](src/rest-client-v5.ts) | Unified V5 all-in-one REST client for all [V5 REST APIs](https://bybit-exchange.github.io/docs/v5/intro) | | ||
| [WebsocketClient](src/websocket-client.ts) | All WebSocket Events (Public & Private for all API categories) | | ||
| [ **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). | | ||
| [ **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) | | ||
--- | ||
### Deprecated/Obsolete 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. | ||
<details> | ||
<summary>Click me to see the list of APIs</summary> | ||
| Class | Description | | ||
| :--------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------: | | ||
| [ **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) (deprecated, AccountAssetClientV3 recommended) | [Account Asset V1 APIs](https://bybit-exchange.github.io/docs/account_asset/v1/#t-introduction) | | ||
</details> | ||
--- | ||
Examples for using each client can be found in: | ||
@@ -143,8 +159,2 @@ | ||
/** Disabled by default. This can help on machines with consistent latency problems. */ | ||
enable_time_sync?: boolean; | ||
/** How often to sync time drift with bybit servers */ | ||
sync_interval_ms?: number | string; | ||
/** Default: false. If true, we'll throw errors if any params are undefined */ | ||
@@ -176,3 +186,5 @@ strict_param_validation?: boolean; | ||
secret: API_SECRET, | ||
testnet: useTestnet | ||
testnet: useTestnet, | ||
// Optional: enable to try parsing rate limit values from responses | ||
// parseAPIRateLimits: true | ||
}, | ||
@@ -209,18 +221,36 @@ // requestLibraryOptions | ||
|:----------------------------: |:-------------------: |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| 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) | | ||
| V5 Subscriptions | `market: 'v5'` | The [v5](https://bybit-exchange.github.io/docs/v5/ws/connect) websocket topics for all categories under one market. Use the subscribeV5 method when subscribing to v5 topics. | | ||
For more complete examples, look into the ws-\* examples in the [examples](./examples/) folder in the repo on GitHub. Here's a minimal example for using the websocket client: | ||
--- | ||
### 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: | ||
<details> | ||
<summary>Click me to see the table</summary> | ||
| 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) | | ||
</details | ||
--- | ||
### WebSocket Examples | ||
Here's a minimal example for using the websocket client. For more complete examples, look into the ws-\* examples in the [examples](./examples/) folder in the repo on GitHub. | ||
```javascript | ||
@@ -246,11 +276,2 @@ const { WebsocketClient } = require('bybit-api'); | ||
// The older generations of Bybit's websockets are still available under the previous markets: | ||
// market: 'linear', | ||
// market: 'inverse', | ||
// market: 'spotv3', | ||
// market: 'usdcOption', | ||
// market: 'usdcPerp', | ||
// market: 'unifiedPerp', | ||
// market: 'unifiedOption', | ||
// how long to wait (in ms) before deciding the connection should be terminated & reconnected | ||
@@ -257,0 +278,0 @@ // pongTimeout: 1000, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
583419
11631
432