diff --git a/.github/workflows/e2etest.yml b/.github/workflows/e2etest.yml
index 38ef71c..e50548c 100644
--- a/.github/workflows/e2etest.yml
+++ b/.github/workflows/e2etest.yml
@@ -1,16 +1,20 @@
-name: 'Build & Test'
+name: E2ETests
-on: [push]
+on:
+ push:
+ pull_request:
+ workflow_dispatch:
+
+env:
+ PROXY_ENABLED: ${{ secrets.PROXY_ENABLED }}
+ PROXY_HOST: ${{ secrets.PROXY_HOST }}
+ PROXY_PASS: ${{ secrets.PROXY_PASS }}
+ PROXY_PORT: ${{ secrets.PROXY_PORT }}
+ PROXY_USER: ${{ secrets.PROXY_USER }}
-# on:
-# # pull_request:
-# # branches:
-# # - "master"
-# push:
-# branches:
jobs:
- build:
+ E2ETests:
name: 'Build & Test'
runs-on: ubuntu-latest
@@ -30,13 +34,20 @@ jobs:
- name: Build
run: npm run build
- - name: Test
- run: npm run test
+ - name: Test Public Read API Calls
+ run: npm run test -- public.read.test.ts
+
+ - name: Test Private Read API Calls
+ run: npm run test -- private.read.test.ts
env:
API_KEY_COM: ${{ secrets.API_KEY_COM }}
API_SECRET_COM: ${{ secrets.API_SECRET_COM }}
- PROXY_ENABLED: ${{ secrets.PROXY_ENABLED }}
- PROXY_HOST: ${{ secrets.PROXY_HOST }}
- PROXY_PASS: ${{ secrets.PROXY_PASS }}
- PROXY_PORT: ${{ secrets.PROXY_PORT }}
- PROXY_USER: ${{ secrets.PROXY_USER }}
+
+ - name: Test Private Write API Calls
+ run: npm run test -- private.write.test.ts
+ env:
+ API_KEY_COM: ${{ secrets.API_KEY_COM }}
+ API_SECRET_COM: ${{ secrets.API_SECRET_COM }}
+
+ - name: Test Public WS
+ run: npm run test -- public.ws.test.ts
diff --git a/README.md b/README.md
index 7e23d64..8f94d49 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,38 @@ Node.js, JavaScript & TypeScript SDK for the Bybit REST APIs and WebSockets:
- See example for more details: [examples/ws-api-events.ts](./examples/ws-api-events.ts)
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
+# Table of Contents
+
+## Overview
+- [Installation](#installation)
+- [Issues & Discussion](#issues--discussion)
+- [Related Projects](#related-projects)
+- [Documentation](#documentation)
+
+## Structure & Usage
+- [Structure](#structure)
+- [API Clients](#api-clients)
+- [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)
+- [Consumer Load Balancing](#balancing-load-across-multiple-connections)
+
+## Additional Features
+- [Logging](#logging)
+ - [Customise Logging](#customise-logging)
+ - [Debug HTTP Requests](#debug-http-requests)
+- [Browser Usage](#browser-usage)
+ - [Import](#import)
+ - [Webpack](#webpack)
+
+## Contributing
+- [Contributions & Thanks](#contributions--thanks)
+
+------
+
## Installation
`npm install --save bybit-api`
@@ -120,7 +152,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:
@@ -223,38 +255,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.
@@ -283,15 +283,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!
@@ -493,14 +484,6 @@ See the [examples/ws-api-promises.ts](./examples/ws-api-promises.ts) example for
---
-### Specifying other markets
-
-The WebsocketClient can be configured to a specific API group using the market parameter. These are the currently available API groups:
-| API Category | Market | Description |
-|:----------------------------: |:-------------------: |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| 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. |
-
-
### Balancing load across multiple connections
The WebsocketClient will automatically prepare one connection per API group, for all topics in that API group. Any topics that you subscribe to on that WebSocket client will automatically be added to the same connection.
@@ -519,32 +502,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) |
-
- {
- console.log(response);
+ console.log('Market order result', response);
})
.catch((error) => {
- console.error(error);
+ console.error('Market order error', error);
+ });
+
+// Submit a limit order
+client
+ .submitOrder({
+ category: 'spot',
+ symbol: 'BTCUSDT',
+ side: 'Buy',
+ orderType: 'Limit',
+ qty: '1',
+ price: '55000',
+ })
+ .then((response) => {
+ console.log('Limit order result', response);
+ })
+ .catch((error) => {
+ console.error('Limit order error', error);
});
diff --git a/examples/demo-trading.ts b/examples/demo-trading.ts
index 36a0aaa..b4002a0 100644
--- a/examples/demo-trading.ts
+++ b/examples/demo-trading.ts
@@ -29,14 +29,14 @@ const restClient = new RestClientV5({
// Optional, uncomment the "silly" override to log a lot more info about what the WS client is doing
const customLogger = {
...DefaultLogger,
- // silly: (...params) => console.log('trace', ...params),
+ // trace: (...params) => console.log('trace', ...params),
};
const wsClient = new WebsocketClient(
{
key: key,
secret: secret,
- market: 'v5',
+
/**
* Set this to true to enable demo trading for the private account data WS
* Topics: order,execution,position,wallet,greeks
@@ -91,7 +91,7 @@ function setWsClientEventListeners(
websocketClient.on('reconnected', (data) => {
console.log(new Date(), accountRef, 'ws has reconnected ', data?.wsKey);
});
- websocketClient.on('error', (data) => {
+ websocketClient.on('exception', (data) => {
console.error(new Date(), accountRef, 'ws exception: ', data);
});
});
diff --git a/examples/deprecated/rest-contract-private.ts b/examples/deprecated/rest-contract-private.ts
deleted file mode 100644
index 59e1484..0000000
--- a/examples/deprecated/rest-contract-private.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { ContractClient } from '../../src/index';
-
-// or
-// import { ContractClient } from 'bybit-api';
-
-const key = process.env.API_KEY_COM;
-const secret = process.env.API_SECRET_COM;
-
-const client = new ContractClient({
- key,
- secret,
- strict_param_validation: true,
-});
-
-(async () => {
- try {
- const getPositions = await client.getPositions({
- settleCoin: 'USDT',
- });
- console.log('getPositions:', getPositions);
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/rest-contract-public.js b/examples/deprecated/rest-contract-public.js
deleted file mode 100644
index d973b47..0000000
--- a/examples/deprecated/rest-contract-public.js
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * This is the pure javascript version of the `rest-contract-public.ts` sample
- */
-
-// To use a local build (testing with the repo directly), make sure to `npm run build` first from the repo root
-// const { ContractClient } = require('../dist');
-
-// or, use the version installed with npm
-const { ContractClient } = require('bybit-api');
-
-(async () => {
- const client = new ContractClient();
-
- try {
- const orderbookResult = await client.getOrderBook('BTCUSDT', 'linear');
- console.log('orderbook result: ', orderbookResult);
- } catch (e) {
- console.error('request failed: ', e);
- }
-
-})();
diff --git a/examples/deprecated/rest-contract-public.ts b/examples/deprecated/rest-contract-public.ts
deleted file mode 100644
index 1fecb0b..0000000
--- a/examples/deprecated/rest-contract-public.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * This is the TypeScript version of the `rest-contract-public.js` sample.
- */
-
-// For testing with the repo directly, import from the src folder
-import { ContractClient } from '../../src';
-
-// or, use the version installed with npm
-// import { ContractClient } from 'bybit-api';
-
-(async () => {
- const client = new ContractClient();
-
- try {
- const orderbookResult = await client.getOrderBook('BTCUSDT', 'linear');
- console.log('orderbook result: ', orderbookResult);
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/rest-copy-private.ts b/examples/deprecated/rest-copy-private.ts
deleted file mode 100644
index ebced30..0000000
--- a/examples/deprecated/rest-copy-private.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { CopyTradingClient } from '../../src/index';
-
-// or
-// import { CopyTradingClient } from 'bybit-api';
-
-const key = process.env.API_KEY_COM;
-const secret = process.env.API_SECRET_COM;
-
-const client = new CopyTradingClient({
- key,
- secret,
- strict_param_validation: true,
-});
-
-(async () => {
- try {
- const res = await client.closeOrder({
- symbol: 'BTCUSDT',
- parentOrderId: '419190fe-016c-469a-810e-936bef2f1234',
- });
- console.log('res:', res);
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/rest-linear-public.ts b/examples/deprecated/rest-linear-public.ts
deleted file mode 100644
index d241ee6..0000000
--- a/examples/deprecated/rest-linear-public.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { LinearClient } from '../../src/index';
-
-// or
-// import { LinearClient } from 'bybit-api';
-
-const client = new LinearClient();
-
-(async () => {
- try {
- // console.log('getSymbols: ', await client.getSymbols());
- // console.log('getOrderBook: ', await client.getOrderBook(symbol));
- console.log(
- 'getKline: ',
- await client.getKline({
- symbol: 'ETHUSDT',
- interval: 'D',
- from: 1,
- }),
- );
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/rest-raw-v3sign.ts b/examples/deprecated/rest-raw-v3sign.ts
deleted file mode 100644
index 35308a3..0000000
--- a/examples/deprecated/rest-raw-v3sign.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import { ContractClient } from '../../src/index';
-
-// or
-// import { ContractClient } from 'bybit-api';
-
-const key = process.env.API_KEY_COM;
-const secret = process.env.API_SECRET_COM;
-
-const client = new ContractClient({
- key,
- secret,
- strict_param_validation: true,
-});
-
-(async () => {
- try {
- /**
- * You can make raw HTTP requests without the per-endpoint abstraction.
- *
- * The REST ContractClient uses bybit's v3 signature mechanism,
- * so it can be used for raw calls to any v3-supporting endpoints (incl the V5 APIs).
- * e.g. if an endpoint is missing and you desperately need it (but please raise an issue or PR if you're missing an endpoint)
- */
- const rawCall = await client.getPrivate('/v5/order/realtime', {
- category: 'linear',
- symbol: 'BTCUSDT',
- });
-
- console.log('rawCall:', rawCall);
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/rest-spot-public.ts b/examples/deprecated/rest-spot-public.ts
deleted file mode 100644
index 0574365..0000000
--- a/examples/deprecated/rest-spot-public.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { SpotClientV3 } from '../../src/index';
-
-// or
-// import { SpotClientV3 } from 'bybit-api';
-
-const client = new SpotClientV3();
-
-const symbol = 'BTCUSDT';
-
-(async () => {
- try {
- // console.log('getSymbols: ', await client.getSymbols());
- // console.log('getOrderBook: ', await client.getOrderBook(symbol));
- console.log('getOrderBook: ', await client.getOrderBook(symbol));
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/rest-spot-tpsl.ts b/examples/deprecated/rest-spot-tpsl.ts
deleted file mode 100644
index d296d6b..0000000
--- a/examples/deprecated/rest-spot-tpsl.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-import { SpotClientV3 } from '../../src/index';
-
-// or
-// import { SpotClientV3 } from 'bybit-api';
-
-const symbol = 'BTCUSDT';
-const key = process.env.API_KEY_COM;
-const secret = process.env.API_SECRET_COM;
-
-const client = new SpotClientV3({
- key,
- secret,
- strict_param_validation: true,
-});
-
-(async () => {
- try {
- const orderId = undefined;
- const ordersPerPage = undefined;
-
- const orders = await client.getOpenOrders(symbol);
- console.log('orders 1:', orders);
-
- const normalOrders = await client.getOpenOrders(
- symbol,
- orderId,
- ordersPerPage,
- 0,
- );
- console.log('normal orders:', normalOrders);
-
- const tpSlOrders = await client.getOpenOrders(
- symbol,
- orderId,
- ordersPerPage,
- 1,
- );
- console.log('tpSlOrders:', tpSlOrders);
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/rest-unified-margin-private-cursor.ts b/examples/deprecated/rest-unified-margin-private-cursor.ts
deleted file mode 100644
index 0bde7cb..0000000
--- a/examples/deprecated/rest-unified-margin-private-cursor.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-import { UnifiedMarginClient } from '../../src/index';
-
-// or
-// import { UnifiedMarginClient } from 'bybit-api';
-
-const key = process.env.API_KEY_COM;
-const secret = process.env.API_SECRET_COM;
-
-const client = new UnifiedMarginClient({
- key,
- secret,
- strict_param_validation: true,
-});
-
-(async () => {
- try {
- // page 1
- const historicOrders1 = await client.getHistoricOrders({
- category: 'linear',
- limit: 1,
- // cursor,
- });
- console.log('page 1:', JSON.stringify(historicOrders1, null, 2));
-
- // page 2
- const historicOrders2 = await client.getHistoricOrders({
- category: 'linear',
- limit: 1,
- cursor: historicOrders1.result.nextPageCursor,
- });
- console.log('page 2:', JSON.stringify(historicOrders2, null, 2));
-
- const historicOrdersBoth = await client.getHistoricOrders({
- category: 'linear',
- limit: 2,
- });
- console.log(
- 'both to compare:',
- JSON.stringify(historicOrdersBoth, null, 2),
- );
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/rest-unified-margin-public-cursor.ts b/examples/deprecated/rest-unified-margin-public-cursor.ts
deleted file mode 100644
index 224ed1a..0000000
--- a/examples/deprecated/rest-unified-margin-public-cursor.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import { UnifiedMarginClient } from '../../src/index';
-
-// or
-// import { UnifiedMarginClient } from 'bybit-api';
-
-const client = new UnifiedMarginClient({
- strict_param_validation: true,
-});
-
-(async () => {
- try {
- // page 1
- const historicOrders1 = await client.getInstrumentInfo({
- category: 'linear',
- limit: '2',
- });
- console.log('page 1:', JSON.stringify(historicOrders1, null, 2));
-
- // page 2
- const historicOrders2 = await client.getInstrumentInfo({
- category: 'linear',
- limit: '2',
- cursor: historicOrders1.result.nextPageCursor,
- });
- console.log('page 2:', JSON.stringify(historicOrders2, null, 2));
-
- // page 1 & 2 in one request (for comparison)
- const historicOrdersBoth = await client.getInstrumentInfo({
- category: 'linear',
- limit: '4',
- });
- console.log('both pages', JSON.stringify(historicOrdersBoth, null, 2));
- } catch (e) {
- console.error('request failed: ', e);
- }
-})();
diff --git a/examples/deprecated/ws-private-copytrading-v3.ts b/examples/deprecated/ws-private-copytrading-v3.ts
deleted file mode 100644
index 17e445d..0000000
--- a/examples/deprecated/ws-private-copytrading-v3.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-/* eslint-disable no-unused-vars */
-/* eslint-disable @typescript-eslint/no-unused-vars */
-/* eslint-disable @typescript-eslint/no-empty-function */
-import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../../src';
-
-// or
-// import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from 'bybit-api';
-
-const logger = {
- ...DefaultLogger,
- silly: (...params) => {
- // console.log(params);
- },
-};
-
-const key = process.env.API_KEY;
-const secret = process.env.API_SECRET;
-
-/**
- * Copy trading api docs say that private topics should connect to: wss://stream.bybit.com/realtime_private
- *
- * Within this SDK, only the market `linear` uses this endpoint for private topics:
- */
-const market = 'linear';
-
-const wsClient = new WebsocketClient(
- {
- key: key,
- secret: secret,
- market: market,
- },
- logger,
-);
-
-wsClient.on('update', (data) => {
- console.log('raw message received ', JSON.stringify(data, null, 2));
-});
-
-wsClient.on('open', (data) => {
- console.log('connection opened open:', data.wsKey);
-});
-wsClient.on('response', (data) => {
- console.log('ws response: ', JSON.stringify(data, null, 2));
-});
-wsClient.on('reconnect', ({ wsKey }) => {
- console.log('ws automatically reconnecting.... ', wsKey);
-});
-wsClient.on('reconnected', (data) => {
- console.log('ws has reconnected ', data?.wsKey);
-});
-wsClient.on('error', (data) => {
- console.error('ws exception: ', data);
-});
-
-// copy trading topics from api docs: https://bybit-exchange.github.io/docs/copy-trade/ws-private/position
-wsClient.subscribe([
- 'copyTradePosition',
- 'copyTradeOrder',
- 'copyTradeExecution',
- 'copyTradeWallet',
-]);
diff --git a/examples/deprecated/ws-private.ts b/examples/deprecated/ws-private.ts
deleted file mode 100644
index 2ee6faf..0000000
--- a/examples/deprecated/ws-private.ts
+++ /dev/null
@@ -1,69 +0,0 @@
-/* eslint-disable no-unused-vars */
-/* eslint-disable @typescript-eslint/no-unused-vars */
-/* eslint-disable @typescript-eslint/no-empty-function */
-import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../../src';
-
-// or
-// import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from 'bybit-api';
-
-const logger = {
- ...DefaultLogger,
- silly: () => {},
-};
-
-const key = process.env.API_KEY;
-const secret = process.env.API_SECRET;
-
-// USDT Perps:
-// const market = 'linear';
-// Inverse Perp
-// const market = 'inverse';
-// const market = 'spotv3';
-// Contract v3
-const market = 'contractUSDT';
-// const market = 'contractInverse';
-
-const wsClient = new WebsocketClient(
- {
- key: key,
- secret: secret,
- market: market,
- // testnet: true,
- restOptions: {
- // enable_time_sync: true,
- },
- },
- logger,
-);
-
-wsClient.on('update', (data) => {
- console.log('raw message received ', JSON.stringify(data, null, 2));
-});
-
-wsClient.on('open', (data) => {
- console.log('connection opened open:', data.wsKey);
-});
-wsClient.on('response', (data) => {
- console.log('ws response: ', JSON.stringify(data, null, 2));
-});
-wsClient.on('reconnect', ({ wsKey }) => {
- console.log('ws automatically reconnecting.... ', wsKey);
-});
-wsClient.on('reconnected', (data) => {
- console.log('ws has reconnected ', data?.wsKey);
-});
-wsClient.on('error', (data) => {
- console.error('ws exception: ', data);
-});
-
-// subscribe to private endpoints
-// check the api docs in your api category to see the available topics
-// wsClient.subscribe(['position', 'execution', 'order', 'wallet']);
-
-// Contract v3
-wsClient.subscribe([
- 'user.position.contractAccount',
- 'user.execution.contractAccount',
- 'user.order.contractAccount',
- 'user.wallet.contractAccount',
-]);
diff --git a/examples/deprecated/ws-public.ts b/examples/deprecated/ws-public.ts
deleted file mode 100644
index e1cdb0a..0000000
--- a/examples/deprecated/ws-public.ts
+++ /dev/null
@@ -1,172 +0,0 @@
-import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../../src';
-
-// or
-// import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from 'bybit-api';
-
-const logger = {
- ...DefaultLogger,
- silly: (...params) => console.log('silly', ...params),
-};
-
-const wsClient = new WebsocketClient(
- {
- // key: key,
- // secret: secret,
- // market: 'linear',
- // market: 'inverse',
- // market: 'spot',
- // market: 'spotv3',
- // market: 'usdcOption',
- // market: 'usdcPerp',
- // market: 'unifiedPerp',
- // market: 'unifiedOption',
- market: 'contractUSDT',
- },
- logger,
-);
-
-wsClient.on('update', (data) => {
- console.log('raw message received ', JSON.stringify(data));
- // console.log('raw message received ', JSON.stringify(data, null, 2));
-});
-
-wsClient.on('open', (data) => {
- console.log('connection opened open:', data.wsKey);
-
- // if (data.wsKey === WS_KEY_MAP.spotPublic) {
- // // Spot public, but not recommended - use spotv3 client instead
- // // The old spot websockets dont automatically resubscribe if they disconnect
- // // wsClient.subscribePublicSpotTrades('BTCUSDT');
- // // wsClient.subscribePublicSpotTradingPair('BTCUSDT');
- // // wsClient.subscribePublicSpotV1Kline('BTCUSDT', '1m');
- // // wsClient.subscribePublicSpotOrderbook('BTCUSDT', 'full');
- // }
-});
-wsClient.on('response', (data) => {
- console.log('log response: ', JSON.stringify(data, null, 2));
-});
-wsClient.on('reconnect', ({ wsKey }) => {
- console.log('ws automatically reconnecting.... ', wsKey);
-});
-wsClient.on('reconnected', (data) => {
- console.log('ws has reconnected ', data?.wsKey);
-});
-// wsClient.on('error', (data) => {
-// console.error('ws exception: ', data);
-// });
-
-// Inverse
-// wsClient.subscribe('trade');
-
-// Linear
-// wsClient.subscribe('trade.BTCUSDT');
-
-// Spot V3
-// wsClient.subscribe('trade.BTCUSDT');
-// Or an array of topics
-// wsClient.subscribe([
-// 'orderbook.40.BTCUSDT',
-// 'orderbook.40.BTCUSDC',
-// 'orderbook.40.USDCUSDT',
-// 'orderbook.40.BTCDAI',
-// 'orderbook.40.DAIUSDT',
-// 'orderbook.40.ETHUSDT',
-// 'orderbook.40.ETHUSDC',
-// 'orderbook.40.ETHDAI',
-// 'orderbook.40.XRPUSDT',
-// 'orderbook.40.XRPUSDC',
-// 'orderbook.40.EOSUSDT',
-// 'orderbook.40.EOSUSDC',
-// 'orderbook.40.DOTUSDT',
-// 'orderbook.40.DOTUSDC',
-// 'orderbook.40.XLMUSDT',
-// 'orderbook.40.XLMUSDC',
-// 'orderbook.40.LTCUSDT',
-// 'orderbook.40.LTCUSDC',
-// 'orderbook.40.DOGEUSDT',
-// 'orderbook.40.DOGEUSDC',
-// 'orderbook.40.BITUSDT',
-// 'orderbook.40.BITUSDC',
-// 'orderbook.40.BITDAI',
-// 'orderbook.40.CHZUSDT',
-// 'orderbook.40.CHZUSDC',
-// 'orderbook.40.MANAUSDT',
-// 'orderbook.40.MANAUSDC',
-// 'orderbook.40.LINKUSDT',
-// 'orderbook.40.LINKUSDC',
-// 'orderbook.40.ICPUSDT',
-// 'orderbook.40.ICPUSDC',
-// 'orderbook.40.ADAUSDT',
-// 'orderbook.40.ADAUSDC',
-// 'orderbook.40.SOLUSDC',
-// 'orderbook.40.SOLUSDT',
-// 'orderbook.40.MATICUSDC',
-// 'orderbook.40.MATICUSDT',
-// 'orderbook.40.SANDUSDC',
-// 'orderbook.40.SANDUSDT',
-// 'orderbook.40.LUNCUSDC',
-// 'orderbook.40.LUNCUSDT',
-// 'orderbook.40.SLGUSDC',
-// 'orderbook.40.SLGUSDT',
-// 'orderbook.40.AVAXUSDC',
-// 'orderbook.40.AVAXUSDT',
-// 'orderbook.40.OPUSDC',
-// 'orderbook.40.OPUSDT',
-// 'orderbook.40.OKSEUSDC',
-// 'orderbook.40.OKSEUSDT',
-// 'orderbook.40.APEXUSDC',
-// 'orderbook.40.APEXUSDT',
-// 'orderbook.40.TRXUSDC',
-// 'orderbook.40.TRXUSDT',
-// 'orderbook.40.GMTUSDC',
-// 'orderbook.40.GMTUSDT',
-// 'orderbook.40.SHIBUSDC',
-// 'orderbook.40.SHIBUSDT',
-// 'orderbook.40.LDOUSDC',
-// 'orderbook.40.LDOUSDT',
-// 'orderbook.40.APEUSDC',
-// 'orderbook.40.APEUSDT',
-// 'orderbook.40.FILUSDC',
-// 'orderbook.40.FILUSDT',
-// ]);
-
-// usdc options
-// wsClient.subscribe([
-// `recenttrades.BTC`,
-// `recenttrades.ETH`,
-// `recenttrades.SOL`,
-// ]);
-
-// usdc perps (note: the syntax is different for the unified perp market)
-// (market: 'usdcPerp')
-// wsClient.subscribe('trade.BTCUSDC');
-// wsClient.subscribe('instrument_info.100ms.BTCPERP');
-
-// unified perps
-// wsClient.subscribe('publicTrade.BTCUSDT');
-// wsClient.subscribe('publicTrade.BTCPERP');
-
-// For spot v1 (the old, deprecated client), request public connection first then send required topics on 'open'
-// Not necessary for spot v3
-// wsClient.connectPublic();
-
-// To unsubscribe from topics (after a 5 second delay, in this example):
-// setTimeout(() => {
-// console.log('unsubscribing');
-// wsClient.unsubscribe('trade.BTCUSDT');
-// }, 5 * 1000);
-
-// Topics are tracked per websocket type
-// Get a list of subscribed topics (e.g. for public v3 spot topics) (after a 5 second delay)
-setTimeout(() => {
- const publicSpotTopics = wsClient
- .getWsStore()
- .getTopics(WS_KEY_MAP.spotV3Public);
-
- console.log('public spot topics: ', publicSpotTopics);
-
- const privateSpotTopics = wsClient
- .getWsStore()
- .getTopics(WS_KEY_MAP.spotV3Private);
- console.log('private spot topics: ', privateSpotTopics);
-}, 5 * 1000);
diff --git a/examples/fasterHmacSign.ts b/examples/fasterHmacSign.ts
index 818087d..99b3f4f 100644
--- a/examples/fasterHmacSign.ts
+++ b/examples/fasterHmacSign.ts
@@ -46,10 +46,10 @@ const restClient = new RestClientV5({
},
});
-// Optional, uncomment the "silly" override to log a lot more info about what the WS client is doing
+// Optional, uncomment the "trace" override to log a lot more info about what the WS client is doing
const customLogger = {
...DefaultLogger,
- // silly: (...params) => console.log('trace', ...params),
+ // trace: (...params) => console.log('trace', ...params),
};
const wsClient = new WebsocketClient(
@@ -117,7 +117,7 @@ function setWsClientEventListeners(
websocketClient.on('reconnected', (data) => {
console.log(new Date(), accountRef, 'ws has reconnected ', data?.wsKey);
});
- websocketClient.on('error', (data) => {
+ websocketClient.on('exception', (data) => {
console.error(new Date(), accountRef, 'ws exception: ', data);
});
});
diff --git a/examples/ws-api-promises.ts b/examples/ws-api-promises.ts
index 5be77d9..4ccf41e 100644
--- a/examples/ws-api-promises.ts
+++ b/examples/ws-api-promises.ts
@@ -40,8 +40,8 @@ wsClient.on('reconnected', (data) => {
wsClient.on('authenticated', (data) => {
console.log('ws has authenticated ', data?.wsKey);
});
-wsClient.on('error', (data) => {
- console.error('ws error: ', data);
+wsClient.on('exception', (data) => {
+ console.error('ws exception: ', data);
});
async function main() {
diff --git a/examples/ws-private-v5.ts b/examples/ws-private-v5.ts
index e4bb3f1..f9a4f1a 100644
--- a/examples/ws-private-v5.ts
+++ b/examples/ws-private-v5.ts
@@ -4,10 +4,10 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// or
// import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from 'bybit-api';
-// Create & inject a custom logger to disable the silly logging level (empty function)
+// Create & inject a custom logger to enable the trace logging level (empty function)
const logger = {
...DefaultLogger,
- silly: () => {},
+ // trace: (...params) => console.log('trace', ...params),
};
const key = process.env.API_KEY;
diff --git a/examples/ws-public-v5.ts b/examples/ws-public-v5.ts
index 6f3e7ca..99d37db 100644
--- a/examples/ws-public-v5.ts
+++ b/examples/ws-public-v5.ts
@@ -5,7 +5,7 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
const logger = {
...DefaultLogger,
- silly: (...params) => console.log('silly', ...params),
+ trace: (...params) => console.log('trace', ...params),
};
/**
@@ -17,13 +17,8 @@ const logger = {
* - Heartbeats/ping/pong/reconnects are all handled automatically.
* If a connection drops, the client will clean it up, respawn a fresh connection and resubscribe for you.
*/
-const wsClient = new WebsocketClient(
- {
- // Previously required, this parameter is now optional:
- // market: 'v5',
- },
- logger,
-);
+
+const wsClient = new WebsocketClient({}, logger);
wsClient.on('update', (data) => {
console.log('raw message received ', JSON.stringify(data));
@@ -41,9 +36,10 @@ wsClient.on('reconnect', ({ wsKey }) => {
wsClient.on('reconnected', (data) => {
console.log('ws has reconnected ', data?.wsKey);
});
-// wsClient.on('error', (data) => {
-// console.error('ws exception: ', data);
-// });
+
+wsClient.on('exception', (data) => {
+ console.error('ws exception: ', data);
+});
/**
* For public V5 topics, use the subscribeV5 method and include the API category this topic is for.
diff --git a/package-lock.json b/package-lock.json
index db075f5..1210de8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "bybit-api",
- "version": "3.10.29",
+ "version": "4.0.0-beta.6",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "bybit-api",
- "version": "3.10.29",
+ "version": "4.0.0-beta.6",
"license": "MIT",
"dependencies": {
"axios": "^1.7.9",
@@ -2720,6 +2720,7 @@
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
"devOptional": true,
+ "license": "MIT",
"dependencies": {
"path-key": "^3.1.0",
"shebang-command": "^2.0.0",
diff --git a/package.json b/package.json
index 6318778..343e974 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "bybit-api",
- "version": "3.10.29",
+ "version": "4.0.0-beta.6",
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
diff --git a/src/account-asset-client-v3.ts b/src/account-asset-client-v3.ts
deleted file mode 100644
index 9b1adb1..0000000
--- a/src/account-asset-client-v3.ts
+++ /dev/null
@@ -1,314 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-import {
- APIKeyInfoV3,
- APIResponseV3WithTime,
- APIResponseWithTime,
- AccountCoinBalanceResponseV3,
- AccountCoinBalancesRequestV3,
- AccountCoinBalancesResponseV3,
- AssetInfoRequestV3,
- AssetInfoResponseV3,
- CoinInfoQueryResponseV3,
- CreateSubAPIKeyRequestV3,
- CreateSubAPIKeyResponseV3,
- CreateSubMemberRequestV3,
- CreateSubMemberResponseV3,
- DepositAddressResponseV3,
- DepositRecordQueryRequestV3,
- DepositRecordQueryResponseV3,
- InternalTransferRequestV3,
- ModifyAPIKeyRequestV3,
- QueryDepositAddressRequestV3,
- QueryInternalTransferSResponseV3,
- QueryInternalTransfersRequestV3,
- QuerySubAccountDepositAddressRequestV3,
- SingleAccountCoinBalanceRequestV3,
- SubAccountTransferRequestV3,
- SubAccountTransferResponseV3,
- SubDepositRecordQueryRequestV3,
- SubMemberResponseV3,
- SupportedDepositListRequestV3,
- SupportedDepositListResponseV3,
- TransferCoinListRequestV3,
- UniversalTransferCreateResponse,
- UniversalTransferListRequestV3,
- UniversalTransferListResponseV3,
- UniversalTransferRequestV3,
- WithdrawCreateRequestV3,
- WithdrawRecordQueryRequestV3,
- WithdrawRecordsQueryResponseV3,
-} from './types';
-import { REST_CLIENT_TYPE_ENUM } from './util';
-import BaseRestClient from './util/BaseRestClient';
-
-/**
- * REST API client for Account Asset V3 APIs
- * @deprecated WARNING
- * These endpoints are being switched off gradually and are expected to be completely turned off by the end of 2024.
- * They may stop working at any point before then.
- * Please update your code as soon as possible to use the V5 APIs instead.
- */
-export class AccountAssetClientV3 extends BaseRestClient {
- getClientType() {
- return REST_CLIENT_TYPE_ENUM.v3;
- }
-
- async fetchServerTime(): Promise {
- const res = await this.getServerTime();
- return Number(res.time);
- }
-
- getServerTime(): Promise<
- APIResponseV3WithTime<{ timeSecond: string; timeNano: string }>
- > {
- return this.get('/v3/public/time');
- }
-
- /**
- *
- * Transfer Data Endpoints
- *
- */
-
- createInternalTransfer(
- params: InternalTransferRequestV3,
- ): Promise> {
- return this.postPrivate(
- '/asset/v3/private/transfer/inter-transfer',
- params,
- );
- }
-
- getInternalTransfers(
- params: QueryInternalTransfersRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/transfer/inter-transfer/list/query',
- params,
- );
- }
-
- createSubAccountTransfer(params: {
- transferId: string;
- coin: string;
- amount: string;
- subMemberId: number;
- type: 'IN' | 'OUT';
- }): Promise> {
- return this.postPrivate(
- '/asset/v3/private/transfer/sub-member-transfer',
- params,
- );
- }
-
- getSubAccountTransfers(
- params?: SubAccountTransferRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/transfer/sub-member-transfer/list/query',
- params,
- );
- }
-
- getSubAccounts(): Promise<
- APIResponseWithTime<{
- subMemberIds: string[];
- transferableSubMemberIds: string[];
- }>
- > {
- return this.getPrivate('/asset/v3/private/transfer/sub-member/list/query');
- }
-
- enableUniversalTransfer(params?: {
- subMemberIds?: string;
- }): Promise> {
- return this.postPrivate(
- '/asset/v3/private/transfer/transfer-sub-member-save',
- params,
- );
- }
-
- createUniversalTransfer(
- params: UniversalTransferRequestV3,
- ): Promise> {
- return this.postPrivate(
- '/asset/v3/private/transfer/universal-transfer',
- params,
- );
- }
-
- getUniversalTransfers(
- params: UniversalTransferListRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/transfer/universal-transfer/list/query',
- params,
- );
- }
-
- getTransferableCoinList(
- params: TransferCoinListRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/transfer/transfer-coin/list/query',
- params,
- );
- }
-
- getAccountCoinBalance(
- params: SingleAccountCoinBalanceRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/transfer/account-coin/balance/query',
- params,
- );
- }
-
- getAccountCoinBalances(
- params: AccountCoinBalancesRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/transfer/account-coins/balance/query',
- params,
- );
- }
-
- getAssetInfo(
- params?: AssetInfoRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/transfer/asset-info/query',
- params,
- );
- }
-
- /**
- *
- * Wallet & Deposit Endpoints
- *
- */
-
- /** Get Deposit Spec */
- getSupportedDepositList(
- params?: SupportedDepositListRequestV3,
- ): Promise> {
- return this.get(
- '/asset/v3/public/deposit/allowed-deposit-list/query',
- params,
- );
- }
-
- getDepositRecords(
- params?: DepositRecordQueryRequestV3,
- ): Promise> {
- return this.getPrivate('/asset/v3/private/deposit/record/query', params);
- }
-
- getSubDepositRecords(
- params: SubDepositRecordQueryRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/deposit/sub-member-record/query',
- params,
- );
- }
-
- getWithdrawRecords(
- params?: WithdrawRecordQueryRequestV3,
- ): Promise> {
- return this.getPrivate('/asset/v3/private/withdraw/record/query', params);
- }
-
- getCoinInformation(
- coin?: string,
- ): Promise> {
- return this.getPrivate('/asset/v3/private/coin-info/query', { coin });
- }
-
- submitWithdrawal(
- params: WithdrawCreateRequestV3,
- ): Promise> {
- return this.postPrivate('/asset/v3/private/withdraw/create', params);
- }
-
- cancelWithdrawal(
- withdrawalId: number,
- ): Promise> {
- return this.postPrivate('/asset/v3/private/withdraw/create', {
- withdrawalId,
- });
- }
-
- getMasterAccountDepositAddress(
- params?: QueryDepositAddressRequestV3,
- ): Promise> {
- return this.getPrivate('/asset/v3/private/deposit/address/query', params);
- }
-
- getSubAccountDepositAddress(
- params: QuerySubAccountDepositAddressRequestV3,
- ): Promise> {
- return this.getPrivate(
- '/asset/v3/private/deposit/sub-member-address/query',
- params,
- );
- }
-
- createSubMember(
- params: CreateSubMemberRequestV3,
- ): Promise> {
- return this.postPrivate('/user/v3/private/create-sub-member', params);
- }
-
- createSubAPIKey(
- params: CreateSubAPIKeyRequestV3,
- ): Promise> {
- return this.postPrivate('/user/v3/private/create-sub-api', params);
- }
-
- /**
- * Get Sub UID List
- */
- getSubMembers(): Promise> {
- return this.getPrivate('/user/v3/private/query-sub-members');
- }
-
- /**
- * Froze Sub UID
- */
- freezeSubMember(
- subuid: number,
- frozenStatus: 0 | 1,
- ): Promise> {
- return this.postPrivate('/user/v3/private/frozen-sub-member', {
- subuid,
- frozen: frozenStatus,
- });
- }
-
- getAPIKeyInformation(): Promise> {
- return this.getPrivate('/user/v3/private/query-api');
- }
-
- modifyMasterAPIKey(
- params: ModifyAPIKeyRequestV3,
- ): Promise> {
- return this.postPrivate('/user/v3/private/update-api', params);
- }
-
- modifySubAPIKey(
- params: ModifyAPIKeyRequestV3,
- ): Promise> {
- return this.postPrivate('/user/v3/private/update-sub-api', params);
- }
-
- /** WARNING: BE CAREFUL! The API key used to call this interface will be invalid immediately. */
- deleteMasterAPIKey(): Promise> {
- return this.postPrivate('/user/v3/private/delete-api');
- }
-
- /** WARNING: BE CAREFUL! The API key used to call this interface will be invalid immediately. */
- deleteSubAPIKey(): Promise> {
- return this.postPrivate('/user/v3/private/delete-sub-api');
- }
-}
diff --git a/src/account-asset-client.ts b/src/account-asset-client.ts
deleted file mode 100644
index cd30af0..0000000
--- a/src/account-asset-client.ts
+++ /dev/null
@@ -1,153 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-import {
- APIResponseWithTime,
- AccountAssetInformationRequest,
- DepositRecordsRequest,
- EnableUniversalTransferRequest,
- InternalTransferRequest,
- SubAccountTransferRequest,
- SupportedDepositListRequest,
- TransferQueryRequest,
- UniversalTransferRequest,
- WithdrawalRecordsRequest,
- WithdrawalRequest,
-} from './types';
-import { REST_CLIENT_TYPE_ENUM } from './util';
-import BaseRestClient from './util/BaseRestClient';
-
-/**
- * REST API client for Account Asset APIs
- *
- * @deprecated WARNING: V1/V2 private endpoints (Rest API & Websocket Stream) for mainnet
- * will be switched off gradually from 30 Oct 2023 UTC, so they are not promised a stability.
- * Please note that you are at your own risk of using old endpoints going forward, and please move to V5 ASAP.
- */
-export class AccountAssetClient extends BaseRestClient {
- getClientType() {
- return REST_CLIENT_TYPE_ENUM.accountAsset;
- }
-
- async fetchServerTime(): Promise {
- const res = await this.getServerTime();
- return Number(res.time_now);
- }
-
- /**
- *
- * Transfer Data Endpoints
- *
- */
-
- createInternalTransfer(
- params: InternalTransferRequest,
- ): Promise> {
- return this.postPrivate('/asset/v1/private/transfer', params);
- }
-
- createSubAccountTransfer(
- params: SubAccountTransferRequest,
- ): Promise> {
- return this.postPrivate('/asset/v1/private/sub-member/transfer', params);
- }
-
- getInternalTransfers(
- params?: TransferQueryRequest,
- ): Promise> {
- return this.getPrivate('/asset/v1/private/transfer/list', params);
- }
-
- getSubAccountTransfers(
- params?: TransferQueryRequest,
- ): Promise> {
- return this.getPrivate(
- '/asset/v1/private/sub-member/transfer/list',
- params,
- );
- }
-
- getSubAccounts(): Promise> {
- return this.getPrivate('/asset/v1/private/sub-member/member-ids');
- }
-
- enableUniversalTransfer(
- params?: EnableUniversalTransferRequest,
- ): Promise> {
- return this.postPrivate('/asset/v1/private/transferable-subs/save', params);
- }
-
- createUniversalTransfer(
- params: UniversalTransferRequest,
- ): Promise> {
- return this.postPrivate('/asset/v1/private/universal/transfer', params);
- }
-
- getUniversalTransfers(
- params?: TransferQueryRequest,
- ): Promise> {
- return this.getPrivate('/asset/v1/private/universal/transfer/list', params);
- }
-
- /**
- *
- * Wallet & Deposit Endpoints
- *
- */
-
- getSupportedDepositList(
- params?: SupportedDepositListRequest,
- ): Promise> {
- return this.get('/asset/v1/public/deposit/allowed-deposit-list', params);
- }
-
- getDepositRecords(
- params?: DepositRecordsRequest,
- ): Promise> {
- return this.getPrivate('/asset/v1/private/deposit/record/query', params);
- }
-
- getWithdrawRecords(
- params?: WithdrawalRecordsRequest,
- ): Promise> {
- return this.getPrivate('/asset/v1/private/withdraw/record/query', params);
- }
-
- getCoinInformation(coin?: string): Promise> {
- return this.getPrivate('/asset/v1/private/coin-info/query', { coin });
- }
-
- getAssetInformation(
- params?: AccountAssetInformationRequest,
- ): Promise> {
- return this.getPrivate('/asset/v1/private/asset-info/query', params);
- }
-
- submitWithdrawal(
- params: WithdrawalRequest,
- ): Promise> {
- return this.postPrivate('/asset/v1/private/withdraw', params);
- }
-
- cancelWithdrawal(withdrawalId: number): Promise> {
- return this.postPrivate('/asset/v1/private/withdraw/cancel', {
- id: withdrawalId,
- });
- }
-
- getDepositAddress(coin: string): Promise> {
- return this.getPrivate('/asset/v1/private/deposit/address', { coin });
- }
-
- /**
- *
- * API Data Endpoints
- *
- */
-
- getServerTime(): Promise {
- return this.get('/v2/public/time');
- }
-
- getApiAnnouncements(): Promise> {
- return this.get('/v2/public/announcement');
- }
-}
diff --git a/src/contract-client.ts b/src/contract-client.ts
deleted file mode 100644
index fb31fbd..0000000
--- a/src/contract-client.ts
+++ /dev/null
@@ -1,364 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-import {
- APIResponseV3,
- APIResponseWithTime,
- ContractActiveOrdersRequest,
- ContractCancelOrderRequest,
- ContractClosedPNLRequest,
- ContractHistoricOrder,
- ContractHistoricOrdersRequest,
- ContractListResult,
- ContractModifyOrderRequest,
- ContractOrderRequest,
- ContractPositionsRequest,
- ContractSetAutoAddMarginRequest,
- ContractSetMarginSwitchRequest,
- ContractSetPositionModeRequest,
- ContractSetTPSLRequest,
- ContractSymbolTicker,
- ContractUserExecutionHistoryRequest,
- ContractWalletFundRecordRequest,
- PaginatedResult,
- UMCandlesRequest,
- UMCategory,
- UMFundingRateHistoryRequest,
- UMInstrumentInfoRequest,
- UMOpenInterestRequest,
- UMOptionDeliveryPriceRequest,
- UMPublicTradesRequest,
-} from './types';
-import { REST_CLIENT_TYPE_ENUM } from './util';
-import BaseRestClient from './util/BaseRestClient';
-
-/**
- * REST API client for Derivatives V3 Contract APIs
- * @deprecated WARNING
- * These endpoints are being switched off gradually and are expected to be completely turned off by the end of 2024.
- * They may stop working at any point before then.
- * Please update your code as soon as possible to use the V5 APIs instead.
- */
-export class ContractClient extends BaseRestClient {
- getClientType() {
- // Follows the same authentication mechanism as other v3 APIs (e.g. USDC)
- return REST_CLIENT_TYPE_ENUM.v3;
- }
-
- async fetchServerTime(): Promise {
- const res = await this.getServerTime();
- return Number(res.time_now);
- }
-
- /**
- *
- * Market Data Endpoints : these seem exactly the same as the unified margin market data endpoints
- *
- */
-
- /** Query order book info. Each side has a depth of 25 orders. */
- getOrderBook(
- symbol: string,
- category?: string,
- limit?: number,
- ): Promise> {
- return this.get('/derivatives/v3/public/order-book/L2', {
- category,
- symbol,
- limit,
- });
- }
-
- /** Get candles/klines */
- getCandles(params: UMCandlesRequest): Promise> {
- return this.get('/derivatives/v3/public/kline', params);
- }
-
- /** Get a symbol price/statistics ticker */
- getSymbolTicker(
- category: UMCategory | '',
- symbol?: string,
- ): Promise>> {
- return this.get('/derivatives/v3/public/tickers', { category, symbol });
- }
-
- /** Get trading rules per symbol/contract, incl price/amount/value/leverage filters */
- getInstrumentInfo(
- params: UMInstrumentInfoRequest,
- ): Promise> {
- return this.get('/derivatives/v3/public/instruments-info', params);
- }
-
- /** Query mark price kline (like getCandles() but for mark price). */
- getMarkPriceCandles(params: UMCandlesRequest): Promise> {
- return this.get('/derivatives/v3/public/mark-price-kline', params);
- }
-
- /** Query Index Price Kline */
- getIndexPriceCandles(params: UMCandlesRequest): Promise> {
- return this.get('/derivatives/v3/public/index-price-kline', params);
- }
-
- /**
- * The funding rate is generated every 8 hours at 00:00 UTC, 08:00 UTC and 16:00 UTC.
- * For example, if a request is sent at 12:00 UTC, the funding rate generated earlier that day at 08:00 UTC will be sent.
- */
- getFundingRateHistory(
- params: UMFundingRateHistoryRequest,
- ): Promise> {
- return this.get(
- '/derivatives/v3/public/funding/history-funding-rate',
- params,
- );
- }
-
- /** Get Risk Limit */
- getRiskLimit(
- category: UMCategory,
- symbol: string,
- ): Promise> {
- return this.get('/derivatives/v3/public/risk-limit/list', {
- category,
- symbol,
- });
- }
-
- /** Get option delivery price */
- getOptionDeliveryPrice(
- params: UMOptionDeliveryPriceRequest,
- ): Promise> {
- return this.get('/derivatives/v3/public/delivery-price', params);
- }
-
- /** Get public trading history */
- getTrades(params: UMPublicTradesRequest): Promise> {
- return this.get('/derivatives/v3/public/recent-trade', params);
- }
-
- /**
- * Gets the total amount of unsettled contracts.
- * In other words, the total number of contracts held in open positions.
- */
- getOpenInterest(params: UMOpenInterestRequest): Promise> {
- return this.get('/derivatives/v3/public/open-interest', params);
- }
-
- /**
- *
- * Contract Account Endpoints
- *
- */
-
- /** -> Order API */
-
- /** Place an order */
- submitOrder(params: ContractOrderRequest): Promise> {
- return this.postPrivate('/contract/v3/private/order/create', params);
- }
-
- /**
- * Query order history.
- *
- * As order creation/cancellation is asynchronous, the data returned from the interface may be delayed.
- * To access order information in real-time, call getActiveOrders().
- */
- getHistoricOrders(
- params: ContractHistoricOrdersRequest,
- ): Promise>> {
- return this.getPrivate('/contract/v3/private/order/list', params);
- }
-
- /** Cancel order */
- cancelOrder(params: ContractCancelOrderRequest): Promise> {
- return this.postPrivate('/contract/v3/private/order/cancel', params);
- }
-
- /** Cancel all orders */
- cancelAllOrders(symbol: string): Promise> {
- return this.postPrivate('/contract/v3/private/order/cancel-all', {
- symbol,
- });
- }
-
- /**
- * Replace order
- *
- * Active order parameters (such as quantity, price) and stop order parameters
- * cannot be modified in one request at the same time.
- *
- * Please request modification separately.
- */
- modifyOrder(params: ContractModifyOrderRequest): Promise> {
- return this.postPrivate('/contract/v3/private/order/replace', params);
- }
-
- /** Query Open Order(s) (real-time) */
- getActiveOrders(
- params: ContractActiveOrdersRequest,
- ): Promise> {
- return this.getPrivate(
- '/contract/v3/private/order/unfilled-orders',
- params,
- );
- }
-
- /** -> Positions API */
-
- /**
- * Query my positions real-time. Accessing personal list of positions.
- * Either symbol or settleCoin is required.
- * Users can access their position holding information through this interface, such as the number of position holdings and wallet balance.
- */
- getPositions(params?: ContractPositionsRequest): Promise> {
- return this.getPrivate('/contract/v3/private/position/list', params);
- }
-
- /** Set auto add margin, or Auto-Margin Replenishment. */
- setAutoAddMargin(
- params: ContractSetAutoAddMarginRequest,
- ): Promise> {
- return this.postPrivate(
- '/contract/v3/private/position/set-auto-add-margin',
- params,
- );
- }
-
- /** Switch cross margin mode/isolated margin mode */
- setMarginSwitch(
- params: ContractSetMarginSwitchRequest,
- ): Promise> {
- return this.postPrivate(
- '/contract/v3/private/position/switch-isolated',
- params,
- );
- }
-
- /** Supports switching between One-Way Mode and Hedge Mode at the coin level. */
- setPositionMode(
- params: ContractSetPositionModeRequest,
- ): Promise> {
- return this.postPrivate(
- '/contract/v3/private/position/switch-mode',
- params,
- );
- }
-
- /**
- * Switch mode between Full or Partial
- */
- setTPSLMode(
- symbol: string,
- tpSlMode: 'Full' | 'Partial',
- ): Promise> {
- return this.postPrivate('/contract/v3/private/position/switch-tpsl-mode', {
- symbol,
- tpSlMode,
- });
- }
-
- /** Leverage setting. */
- setLeverage(
- symbol: string,
- buyLeverage: string,
- sellLeverage: string,
- ): Promise> {
- return this.postPrivate('/contract/v3/private/position/set-leverage', {
- symbol,
- buyLeverage,
- sellLeverage,
- });
- }
-
- /**
- * Set take profit, stop loss, and trailing stop for your open position.
- * If using partial mode, TP/SL/TS orders will not close your entire position.
- */
- setTPSL(params: ContractSetTPSLRequest): Promise> {
- return this.postPrivate(
- '/contract/v3/private/position/trading-stop',
- params,
- );
- }
-
- /** Set risk limit */
- setRiskLimit(
- symbol: string,
- riskId: number,
- /** 0-one-way, 1-buy side, 2-sell side */
- positionIdx: 0 | 1 | 2,
- ): Promise> {
- return this.postPrivate('/contract/v3/private/position/set-risk-limit', {
- symbol,
- riskId,
- positionIdx,
- });
- }
-
- /**
- * Get user's trading records.
- * The results are ordered in descending order (the first item is the latest). Returns records up to 2 years old.
- */
- getUserExecutionHistory(
- params: ContractUserExecutionHistoryRequest,
- ): Promise> {
- return this.getPrivate('/contract/v3/private/execution/list', params);
- }
-
- /**
- * Get user's closed profit and loss records.
- * The results are ordered in descending order (the first item is the latest).
- */
- getClosedProfitAndLoss(
- params: ContractClosedPNLRequest,
- ): Promise> {
- return this.getPrivate('/contract/v3/private/position/closed-pnl', params);
- }
-
- /** Get the information of open interest limit. */
- getOpenInterestLimitInfo(symbol: string): Promise> {
- return this.getPrivate('/contract/v3/private/position/limit-info', {
- symbol,
- });
- }
-
- /** -> Account API */
-
- /** Query wallet balance */
- getBalances(coin?: string): Promise> {
- return this.getPrivate('/contract/v3/private/account/wallet/balance', {
- coin,
- });
- }
-
- /** Get user trading fee rate */
- getTradingFeeRate(symbol?: string): Promise> {
- return this.getPrivate('/contract/v3/private/account/fee-rate', {
- symbol,
- });
- }
-
- /**
- * Get wallet fund records.
- * This endpoint also shows exchanges from the Asset Exchange,
- * where the types for the exchange are ExchangeOrderWithdraw and ExchangeOrderDeposit.
- *
- * This endpoint returns incomplete information for transfers involving the derivatives wallet.
- * Use the account asset API for creating and querying internal transfers.
- */
- getWalletFundRecords(
- params?: ContractWalletFundRecordRequest,
- ): Promise> {
- return this.getPrivate(
- '/contract/v3/private/account/wallet/fund-records',
- params,
- );
- }
-
- /**
- *
- * API Data Endpoints
- *
- */
-
- getServerTime(): Promise {
- return this.get('/v2/public/time');
- }
-}
diff --git a/src/copy-trading-client.ts b/src/copy-trading-client.ts
deleted file mode 100644
index 1fa226f..0000000
--- a/src/copy-trading-client.ts
+++ /dev/null
@@ -1,162 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-import {
- APIResponseV3,
- APIResponseWithTime,
- CopyTradingCancelOrderRequest,
- CopyTradingCloseOrderRequest,
- CopyTradingOrderListRequest,
- CopyTradingOrderRequest,
- CopyTradingTradingStopRequest,
- CopyTradingTransferRequest,
-} from './types';
-import { REST_CLIENT_TYPE_ENUM } from './util';
-import BaseRestClient from './util/BaseRestClient';
-
-/**
- * REST API client for USDC Perpetual APIs
- * @deprecated WARNING
- * These endpoints are being switched off gradually and are expected to be completely turned off by the end of 2024.
- * They may stop working at any point before then.
- * Please update your code as soon as possible to use the V5 APIs instead.
- */
-export class CopyTradingClient extends BaseRestClient {
- getClientType() {
- // Follows the same authentication mechanism as USDC APIs
- return REST_CLIENT_TYPE_ENUM.v3;
- }
-
- async fetchServerTime(): Promise {
- const res = await this.getServerTime();
- return Number(res.time_now);
- }
-
- /**
- *
- * Market Data Endpoints
- *
- */
-
- getSymbols(): Promise> {
- return this.get('/contract/v3/public/copytrading/symbol/list');
- }
-
- /**
- *
- * Account Data Endpoints
- *
- */
-
- /** -> Order API */
-
- /** Create order */
- submitOrder(params: CopyTradingOrderRequest): Promise> {
- return this.postPrivate(
- '/contract/v3/private/copytrading/order/create',
- params,
- );
- }
-
- /** Set Trading Stop */
- setTradingStop(
- params: CopyTradingTradingStopRequest,
- ): Promise> {
- return this.postPrivate(
- '/contract/v3/private/copytrading/order/trading-stop',
- params,
- );
- }
-
- /** Query Order List */
- getActiveOrders(
- params?: CopyTradingOrderListRequest,
- ): Promise> {
- return this.getPrivate(
- '/contract/v3/private/copytrading/order/list',
- params,
- );
- }
-
- /** Cancel order */
- cancelOrder(
- params: CopyTradingCancelOrderRequest,
- ): Promise> {
- return this.postPrivate(
- '/contract/v3/private/copytrading/order/cancel',
- params,
- );
- }
-
- /** Close Order.
- * This endpoint's rate_limit will decrease by 10 per request;
- * ie, one request to this endpoint consumes 10 from the limit allowed per minute.
- */
- closeOrder(
- params: CopyTradingCloseOrderRequest,
- ): Promise> {
- return this.postPrivate(
- '/contract/v3/private/copytrading/order/close',
- params,
- );
- }
-
- /** -> Positions API */
-
- /** Position List */
- getPositions(symbol?: string): Promise> {
- return this.getPrivate('/contract/v3/private/copytrading/position/list', {
- symbol,
- });
- }
-
- /** Close Position */
- closePosition(
- symbol: string,
- positionIdx: string,
- ): Promise> {
- return this.postPrivate('/contract/v3/private/copytrading/position/close', {
- symbol,
- positionIdx,
- });
- }
-
- /** Only integers can be set to set the leverage */
- setLeverage(
- symbol: string,
- buyLeverage: string,
- sellLeverage: string,
- ): Promise> {
- return this.postPrivate(
- '/contract/v3/private/copytrading/position/set-leverage',
- { symbol, buyLeverage, sellLeverage },
- );
- }
-
- /**
- *
- * Wallet Data Endpoints
- *
- */
-
- /** Get Wallet Balance */
- getBalances(): Promise> {
- return this.getPrivate('/contract/v3/private/copytrading/wallet/balance');
- }
-
- /** Transfer */
- transfer(params: CopyTradingTransferRequest): Promise> {
- return this.postPrivate(
- '/contract/v3/private/copytrading/wallet/transfer',
- params,
- );
- }
-
- /**
- *
- * API Data Endpoints
- *
- */
-
- getServerTime(): Promise {
- return this.get('/v2/public/time');
- }
-}
diff --git a/src/index.ts b/src/index.ts
index c93f1d3..2a85c6d 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,16 +1,5 @@
-export * from './account-asset-client';
-export * from './account-asset-client-v3';
-export * from './copy-trading-client';
-export * from './inverse-client';
-export * from './inverse-futures-client';
-export * from './linear-client';
export * from './rest-client-v5';
-export * from './spot-client';
export * from './spot-client-v3';
-export * from './usdc-option-client';
-export * from './usdc-perpetual-client';
-export * from './unified-margin-client';
-export * from './contract-client';
export * from './websocket-client';
export * from './util/logger';
export * from './util';
diff --git a/src/inverse-client.ts b/src/inverse-client.ts
deleted file mode 100644
index b860e17..0000000
--- a/src/inverse-client.ts
+++ /dev/null
@@ -1,341 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-import { REST_CLIENT_TYPE_ENUM } from './util';
-import {
- APIResponseWithTime,
- AssetExchangeRecordsReq,
- CoinParam,
- InverseActiveConditionalOrderRequest,
- InverseActiveOrdersRequest,
- InverseCancelConditionalOrderRequest,
- InverseCancelOrderRequest,
- InverseChangePositionMarginRequest,
- InverseConditionalOrderRequest,
- InverseGetClosedPnlRequest,
- InverseGetOrderRequest,
- InverseGetTradeRecordsRequest,
- InverseOrderRequest,
- InverseReplaceConditionalOrderRequest,
- InverseReplaceOrderRequest,
- InverseSetLeverageRequest,
- InverseSetMarginTypeRequest,
- InverseSetSlTpPositionModeRequest,
- InverseSetTradingStopRequest,
- SymbolInfo,
- SymbolIntervalFromLimitParam,
- SymbolLimitParam,
- SymbolParam,
- SymbolPeriodLimitParam,
- WalletFundRecordsReq,
- WithdrawRecordsReq,
-} from './types';
-import BaseRestClient from './util/BaseRestClient';
-
-/**
- * REST API client for Inverse Perpetual Futures APIs (v2)
- *
- * @deprecated WARNING: V1/V2 private endpoints (Rest API & Websocket Stream) for mainnet
- * will be switched off gradually from 30 Oct 2023 UTC, so they are not promised a stability.
- * Please note that you are at your own risk of using old endpoints going forward, and please move to V5 ASAP.
- */
-export class InverseClient extends BaseRestClient {
- getClientType() {
- return REST_CLIENT_TYPE_ENUM.inverse;
- }
-
- async fetchServerTime(): Promise {
- const res = await this.getServerTime();
- return Number(res.time_now);
- }
-
- /**
- *
- * Market Data Endpoints
- *
- */
-
- getOrderBook(params: SymbolParam): Promise> {
- return this.get('v2/public/orderBook/L2', params);
- }
-
- getKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('v2/public/kline/list', params);
- }
-
- /**
- * Get latest information for symbol
- */
- getTickers(
- params?: Partial,
- ): Promise> {
- return this.get('v2/public/tickers', params);
- }
-
- getTrades(params: SymbolLimitParam): Promise> {
- return this.get('v2/public/trading-records', params);
- }
-
- getSymbols(): Promise> {
- return this.get('v2/public/symbols');
- }
-
- getMarkPriceKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('v2/public/mark-price-kline', params);
- }
-
- getIndexPriceKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('v2/public/index-price-kline', params);
- }
-
- getPremiumIndexKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('v2/public/premium-index-kline', params);
- }
-
- /**
- *
- * Market Data : Advanced
- *
- */
-
- getOpenInterest(
- params: SymbolPeriodLimitParam,
- ): Promise> {
- return this.get('v2/public/open-interest', params);
- }
-
- getLatestBigDeal(
- params: SymbolLimitParam,
- ): Promise> {
- return this.get('v2/public/big-deal', params);
- }
-
- getLongShortRatio(
- params: SymbolPeriodLimitParam,
- ): Promise> {
- return this.get('v2/public/account-ratio', params);
- }
-
- /**
- *
- * Account Data Endpoints
- *
- */
-
- getApiKeyInfo(): Promise> {
- return this.getPrivate('v2/private/account/api-key');
- }
-
- /**
- *
- * Wallet Data Endpoints
- *
- */
-
- getWalletBalance(
- params?: Partial,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/balance', params);
- }
-
- getWalletFundRecords(
- params?: WalletFundRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/fund/records', params);
- }
-
- getWithdrawRecords(
- params?: WithdrawRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/withdraw/list', params);
- }
-
- getAssetExchangeRecords(
- params?: AssetExchangeRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/exchange-order/list', params);
- }
-
- /**
- *
- * API Data Endpoints
- *
- */
-
- getServerTime(): Promise> {
- return this.get('v2/public/time');
- }
-
- getApiAnnouncements(): Promise> {
- return this.get('v2/public/announcement');
- }
-
- /**
- *
- * Account Data Endpoints
- *
- */
-
- /**
- * Active orders
- */
-
- placeActiveOrder(
- orderRequest: InverseOrderRequest,
- ): Promise> {
- return this.postPrivate('v2/private/order/create', orderRequest);
- }
-
- getActiveOrderList(
- params: InverseActiveOrdersRequest,
- ): Promise> {
- return this.getPrivate('v2/private/order/list', params);
- }
-
- cancelActiveOrder(
- params: InverseCancelOrderRequest,
- ): Promise> {
- return this.postPrivate('v2/private/order/cancel', params);
- }
-
- cancelAllActiveOrders(
- params: SymbolParam,
- ): Promise> {
- return this.postPrivate('v2/private/order/cancelAll', params);
- }
-
- replaceActiveOrder(
- params: InverseReplaceOrderRequest,
- ): Promise> {
- return this.postPrivate('v2/private/order/replace', params);
- }
-
- queryActiveOrder(
- params: InverseGetOrderRequest,
- ): Promise> {
- return this.getPrivate('v2/private/order', params);
- }
-
- /**
- * Conditional orders
- */
-
- placeConditionalOrder(
- params: InverseConditionalOrderRequest,
- ): Promise> {
- return this.postPrivate('v2/private/stop-order/create', params);
- }
-
- /** get conditional order list. This may see delays, use queryConditionalOrder() for real-time queries */
- getConditionalOrder(
- params: InverseActiveConditionalOrderRequest,
- ): Promise> {
- return this.getPrivate('v2/private/stop-order/list', params);
- }
-
- cancelConditionalOrder(
- params: InverseCancelConditionalOrderRequest,
- ): Promise> {
- return this.postPrivate('v2/private/stop-order/cancel', params);
- }
-
- cancelAllConditionalOrders(
- params: SymbolParam,
- ): Promise> {
- return this.postPrivate('v2/private/stop-order/cancelAll', params);
- }
-
- replaceConditionalOrder(
- params: InverseReplaceConditionalOrderRequest,
- ): Promise> {
- return this.postPrivate('v2/private/stop-order/replace', params);
- }
-
- queryConditionalOrder(
- params: InverseGetOrderRequest,
- ): Promise> {
- return this.getPrivate('v2/private/stop-order', params);
- }
-
- /**
- * Position
- */
-
- getPosition(
- params?: Partial,
- ): Promise> {
- return this.getPrivate('v2/private/position/list', params);
- }
-
- changePositionMargin(
- params: InverseChangePositionMarginRequest,
- ): Promise> {
- return this.postPrivate('position/change-position-margin', params);
- }
-
- setTradingStop(
- params: InverseSetTradingStopRequest,
- ): Promise> {
- return this.postPrivate('v2/private/position/trading-stop', params);
- }
-
- setUserLeverage(
- params: InverseSetLeverageRequest,
- ): Promise> {
- return this.postPrivate('v2/private/position/leverage/save', params);
- }
-
- getTradeRecords(
- params: InverseGetTradeRecordsRequest,
- ): Promise> {
- return this.getPrivate('v2/private/execution/list', params);
- }
-
- getClosedPnl(
- params: InverseGetClosedPnlRequest,
- ): Promise> {
- return this.getPrivate('v2/private/trade/closed-pnl/list', params);
- }
-
- setSlTpPositionMode(
- params: InverseSetSlTpPositionModeRequest,
- ): Promise> {
- return this.postPrivate('v2/private/tpsl/switch-mode', params);
- }
-
- setMarginType(
- params: InverseSetMarginTypeRequest,
- ): Promise> {
- return this.postPrivate('v2/private/position/switch-isolated', params);
- }
-
- /**
- * Funding
- */
-
- getLastFundingRate(params: SymbolParam): Promise> {
- return this.get('v2/public/funding/prev-funding-rate', params);
- }
-
- getMyLastFundingFee(params: SymbolParam): Promise> {
- return this.getPrivate('v2/private/funding/prev-funding', params);
- }
-
- getPredictedFunding(params: SymbolParam): Promise> {
- return this.getPrivate('v2/private/funding/predicted-funding', params);
- }
-
- /**
- * LCP Info
- */
-
- getLcpInfo(params: SymbolParam): Promise> {
- return this.getPrivate('v2/private/account/lcp', params);
- }
-}
diff --git a/src/inverse-futures-client.ts b/src/inverse-futures-client.ts
deleted file mode 100644
index eb8646b..0000000
--- a/src/inverse-futures-client.ts
+++ /dev/null
@@ -1,407 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
-import {
- APIResponseWithTime,
- AssetExchangeRecordsReq,
- CoinParam,
- SymbolInfo,
- SymbolIntervalFromLimitParam,
- SymbolLimitParam,
- SymbolParam,
- SymbolPeriodLimitParam,
- WalletFundRecordsReq,
- WithdrawRecordsReq,
-} from './types/shared';
-import BaseRestClient from './util/BaseRestClient';
-
-/**
- * REST API client for Inverse Futures APIs (e.g. quarterly futures) (v2)
- *
- * @deprecated WARNING: V1/V2 private endpoints (Rest API & Websocket Stream) for mainnet
- * will be switched off gradually from 30 Oct 2023 UTC, so they are not promised a stability.
- * Please note that you are at your own risk of using old endpoints going forward, and please move to V5 ASAP.
- */
-export class InverseFuturesClient extends BaseRestClient {
- getClientType() {
- return REST_CLIENT_TYPE_ENUM.inverseFutures;
- }
-
- async fetchServerTime(): Promise {
- const res = await this.getServerTime();
- return Number(res.time_now);
- }
-
- /**
- *
- * Market Data Endpoints
- *
- */
-
- getOrderBook(params: SymbolParam): Promise> {
- return this.get('v2/public/orderBook/L2', params);
- }
-
- getKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('v2/public/kline/list', params);
- }
-
- /**
- * Get latest information for symbol
- */
- getTickers(
- params?: Partial,
- ): Promise> {
- return this.get('v2/public/tickers', params);
- }
-
- /**
- * Public trading records
- */
- getTrades(params: SymbolLimitParam): Promise> {
- return this.get('v2/public/trading-records', params);
- }
-
- getSymbols(): Promise> {
- return this.get('v2/public/symbols');
- }
-
- getMarkPriceKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('v2/public/mark-price-kline', params);
- }
-
- getIndexPriceKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('v2/public/index-price-kline', params);
- }
-
- getPremiumIndexKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('v2/public/premium-index-kline', params);
- }
-
- /**
- *
- * Market Data : Advanced
- *
- */
-
- getOpenInterest(
- params: SymbolPeriodLimitParam,
- ): Promise> {
- return this.get('v2/public/open-interest', params);
- }
-
- getLatestBigDeal(
- params: SymbolLimitParam,
- ): Promise> {
- return this.get('v2/public/big-deal', params);
- }
-
- getLongShortRatio(
- params: SymbolPeriodLimitParam,
- ): Promise> {
- return this.get('v2/public/account-ratio', params);
- }
-
- /**
- *
- * Account Data Endpoints
- *
- */
-
- getApiKeyInfo(): Promise> {
- return this.getPrivate('v2/private/account/api-key');
- }
-
- /**
- *
- * Wallet Data Endpoints
- *
- */
-
- getWalletBalance(
- params?: Partial,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/balance', params);
- }
-
- getWalletFundRecords(
- params?: WalletFundRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/fund/records', params);
- }
-
- getWithdrawRecords(
- params?: WithdrawRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/withdraw/list', params);
- }
-
- getAssetExchangeRecords(
- params?: AssetExchangeRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/exchange-order/list', params);
- }
-
- /**
- *
- * API Data Endpoints
- *
- */
-
- getServerTime(): Promise> {
- return this.get('v2/public/time');
- }
-
- getApiAnnouncements(): Promise> {
- return this.get('v2/public/announcement');
- }
-
- /**
- *
- * Account Data Endpoints
- *
- */
-
- /**
- * Active orders
- */
-
- placeActiveOrder(orderRequest: {
- side: string;
- symbol: string;
- order_type: string;
- qty: number;
- price?: number;
- time_in_force: string;
- take_profit?: number;
- stop_loss?: number;
- reduce_only?: boolean;
- close_on_trigger?: boolean;
- order_link_id?: string;
- }): Promise> {
- return this.postPrivate('futures/private/order/create', orderRequest);
- }
-
- getActiveOrderList(params: {
- symbol: string;
- order_status?: string;
- direction?: string;
- limit?: number;
- cursor?: string;
- }): Promise> {
- return this.getPrivate('futures/private/order/list', params);
- }
-
- cancelActiveOrder(params: {
- symbol: string;
- order_id?: string;
- order_link_id?: string;
- }): Promise> {
- return this.postPrivate('futures/private/order/cancel', params);
- }
-
- cancelAllActiveOrders(
- params: SymbolParam,
- ): Promise> {
- return this.postPrivate('futures/private/order/cancelAll', params);
- }
-
- replaceActiveOrder(params: {
- order_id?: string;
- order_link_id?: string;
- symbol: string;
- p_r_qty?: string;
- p_r_price?: string;
- }): Promise> {
- return this.postPrivate('futures/private/order/replace', params);
- }
-
- queryActiveOrder(params: {
- order_id?: string;
- order_link_id?: string;
- symbol: string;
- }): Promise> {
- return this.getPrivate('futures/private/order', params);
- }
-
- /**
- * Conditional orders
- */
-
- placeConditionalOrder(params: {
- side: string;
- symbol: string;
- order_type: string;
- qty: string;
- price?: string;
- base_price: string;
- stop_px: string;
- time_in_force: string;
- trigger_by?: string;
- close_on_trigger?: boolean;
- order_link_id?: string;
- }): Promise> {
- return this.postPrivate('futures/private/stop-order/create', params);
- }
-
- getConditionalOrder(params: {
- symbol: string;
- stop_order_status?: string;
- direction?: string;
- limit?: number;
- cursor?: string;
- }): Promise> {
- return this.getPrivate('futures/private/stop-order/list', params);
- }
-
- cancelConditionalOrder(params: {
- symbol: string;
- stop_order_id?: string;
- order_link_id?: string;
- }): Promise> {
- return this.postPrivate('futures/private/stop-order/cancel', params);
- }
-
- cancelAllConditionalOrders(
- params: SymbolParam,
- ): Promise> {
- return this.postPrivate('futures/private/stop-order/cancelAll', params);
- }
-
- replaceConditionalOrder(params: {
- stop_order_id?: string;
- order_link_id?: string;
- symbol: string;
- p_r_qty?: number;
- p_r_price?: string;
- p_r_trigger_price?: string;
- }): Promise> {
- return this.postPrivate('futures/private/stop-order/replace', params);
- }
-
- queryConditionalOrder(params: {
- symbol: string;
- stop_order_id?: string;
- order_link_id?: string;
- }): Promise> {
- return this.getPrivate('futures/private/stop-order', params);
- }
-
- /**
- * Position
- */
-
- /**
- * Get position list
- */
- getPosition(
- params?: Partial,
- ): Promise> {
- return this.getPrivate('futures/private/position/list', params);
- }
-
- changePositionMargin(params: {
- symbol: string;
- margin: string;
- }): Promise> {
- return this.postPrivate(
- 'futures/private/position/change-position-margin',
- params,
- );
- }
-
- setTradingStop(params: {
- symbol: string;
- take_profit?: number;
- stop_loss?: number;
- trailing_stop?: number;
- tp_trigger_by?: string;
- sl_trigger_by?: string;
- new_trailing_active?: number;
- }): Promise> {
- return this.postPrivate('futures/private/position/trading-stop', params);
- }
-
- setUserLeverage(params: {
- symbol: string;
- buy_leverage: number;
- sell_leverage: number;
- }): Promise> {
- return this.postPrivate('futures/private/position/leverage/save', params);
- }
-
- /**
- * Position mode switch
- */
- setPositionMode(params: {
- symbol: string;
- mode: number;
- }): Promise> {
- return this.postPrivate('futures/private/position/switch-mode', params);
- }
-
- /**
- * Cross/Isolated margin switch. Must set leverage value when switching.
- */
- setMarginType(params: {
- symbol: string;
- is_isolated: boolean;
- buy_leverage: number;
- sell_leverage: number;
- }): Promise> {
- return this.postPrivate('futures/private/position/switch-isolated', params);
- }
-
- getTradeRecords(params: {
- order_id?: string;
- symbol: string;
- start_time?: number;
- page?: number;
- limit?: number;
- order?: string;
- }): Promise> {
- return this.getPrivate('futures/private/execution/list', params);
- }
-
- getClosedPnl(params: {
- symbol: string;
- start_time?: number;
- end_time?: number;
- exec_type?: string;
- page?: number;
- limit?: number;
- }): Promise> {
- return this.getPrivate('futures/private/trade/closed-pnl/list', params);
- }
-
- /**
- * Funding
- */
-
- getLastFundingRate(params: SymbolParam): Promise> {
- return this.get('v2/public/funding/prev-funding-rate', params);
- }
-
- getMyLastFundingFee(params: SymbolParam): Promise> {
- return this.getPrivate('v2/private/funding/prev-funding', params);
- }
-
- getPredictedFunding(params: SymbolParam): Promise> {
- return this.getPrivate('v2/private/funding/predicted-funding', params);
- }
-
- /**
- * LCP Info
- */
-
- getLcpInfo(params: SymbolParam): Promise> {
- return this.getPrivate('v2/private/account/lcp', params);
- }
-}
diff --git a/src/linear-client.ts b/src/linear-client.ts
deleted file mode 100644
index 2e6a637..0000000
--- a/src/linear-client.ts
+++ /dev/null
@@ -1,391 +0,0 @@
-/* eslint-disable @typescript-eslint/no-explicit-any */
-import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils';
-import {
- APIResponse,
- APIResponseWithTime,
- AssetExchangeRecordsReq,
- CoinParam,
- LinearCancelConditionalOrderRequest,
- LinearCancelOrderRequest,
- LinearConditionalOrderRequest,
- LinearGetClosedPnlRequest,
- LinearGetConditionalOrderRequest,
- LinearGetHistoryTradeRecordsRequest,
- LinearGetOrderRequest,
- LinearGetOrdersRequest,
- LinearGetTradeRecordsRequest,
- LinearOrder,
- LinearQueryConditionalOrderRequest,
- LinearReplaceConditionalOrderRequest,
- LinearReplaceOrderRequest,
- LinearSetAddReduceMarginRequest,
- LinearSetAutoAddMarginRequest,
- LinearSetMarginSwitchRequest,
- LinearSetPositionModeRequest,
- LinearSetPositionTpSlModeRequest,
- LinearSetRiskLimitRequest,
- LinearSetTradingStopRequest,
- LinearSetUserLeverageRequest,
- NewLinearOrder,
- PerpPosition,
- PerpPositionRoot,
- SymbolInfo,
- SymbolIntervalFromLimitParam,
- SymbolLimitParam,
- SymbolParam,
- SymbolPeriodLimitParam,
- WalletBalances,
- WalletFundRecordsReq,
- WithdrawRecordsReq,
-} from './types';
-import BaseRestClient from './util/BaseRestClient';
-
-/**
- * REST API client for linear/USD perpetual futures APIs (v2)
- *
- * @deprecated WARNING: V1/V2 private endpoints (Rest API & Websocket Stream) for mainnet
- * will be switched off gradually from 30 Oct 2023 UTC, so they are not promised a stability.
- * Please note that you are at your own risk of using old endpoints going forward, and please move to V5 ASAP.
- */
-export class LinearClient extends BaseRestClient {
- getClientType() {
- return REST_CLIENT_TYPE_ENUM.linear;
- }
-
- async fetchServerTime(): Promise {
- const timeRes = await this.getServerTime();
- return Number(timeRes.time_now);
- }
-
- /**
- *
- * Market Data Endpoints
- *
- */
-
- getOrderBook(params: SymbolParam): Promise> {
- return this.get('v2/public/orderBook/L2', params);
- }
-
- getKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('public/linear/kline', params);
- }
-
- /**
- * Get latest information for symbol
- */
- getTickers(
- params?: Partial,
- ): Promise> {
- return this.get('v2/public/tickers', params);
- }
-
- getTrades(params: SymbolLimitParam): Promise> {
- return this.get('public/linear/recent-trading-records', params);
- }
-
- getSymbols(): Promise> {
- return this.get('v2/public/symbols');
- }
-
- getLastFundingRate(params: SymbolParam): Promise> {
- return this.get('public/linear/funding/prev-funding-rate', params);
- }
-
- getMarkPriceKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('public/linear/mark-price-kline', params);
- }
-
- getIndexPriceKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('public/linear/index-price-kline', params);
- }
-
- getPremiumIndexKline(
- params: SymbolIntervalFromLimitParam,
- ): Promise> {
- return this.get('public/linear/premium-index-kline', params);
- }
-
- /**
- *
- * Market Data : Advanced
- *
- */
-
- getOpenInterest(
- params: SymbolPeriodLimitParam,
- ): Promise> {
- return this.get('v2/public/open-interest', params);
- }
-
- getLatestBigDeal(
- params: SymbolLimitParam,
- ): Promise> {
- return this.get('v2/public/big-deal', params);
- }
-
- getLongShortRatio(
- params: SymbolPeriodLimitParam,
- ): Promise> {
- return this.get('v2/public/account-ratio', params);
- }
-
- /**
- *
- * Account Data Endpoints
- *
- */
-
- getApiKeyInfo(): Promise> {
- return this.getPrivate('v2/private/account/api-key');
- }
-
- /**
- *
- * Wallet Data Endpoints
- *
- */
-
- getWalletBalance(
- params?: Partial,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/balance', params);
- }
-
- getWalletFundRecords(
- params?: WalletFundRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/fund/records', params);
- }
-
- getWithdrawRecords(
- params?: WithdrawRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/wallet/withdraw/list', params);
- }
-
- getAssetExchangeRecords(
- params?: AssetExchangeRecordsReq,
- ): Promise> {
- return this.getPrivate('v2/private/exchange-order/list', params);
- }
-
- /**
- *
- * API Data Endpoints
- *
- */
-
- getServerTime(): Promise> {
- return this.get('v2/public/time');
- }
-
- getApiAnnouncements(): Promise> {
- return this.get('v2/public/announcement');
- }
-
- /**
- *
- * Account Data Endpoints
- *
- */
-
- placeActiveOrder(
- params: NewLinearOrder,
- ): Promise> {
- return this.postPrivate('private/linear/order/create', params);
- }
-
- getActiveOrderList(
- params: LinearGetOrdersRequest,
- ): Promise> {
- return this.getPrivate('private/linear/order/list', params);
- }
-
- cancelActiveOrder(
- params: LinearCancelOrderRequest,
- ): Promise> {
- return this.postPrivate('private/linear/order/cancel', params);
- }
-
- cancelAllActiveOrders(
- params: SymbolParam,
- ): Promise> {
- return this.postPrivate('private/linear/order/cancel-all', params);
- }
-
- replaceActiveOrder(
- params: LinearReplaceOrderRequest,
- ): Promise> {
- return this.postPrivate('private/linear/order/replace', params);
- }
-
- queryActiveOrder(
- params: LinearGetOrderRequest,
- ): Promise> {
- return this.getPrivate('private/linear/order/search', params);
- }
-
- /**
- * Conditional orders
- */
-
- placeConditionalOrder(
- params: LinearConditionalOrderRequest,
- ): Promise> {
- return this.postPrivate('private/linear/stop-order/create', params);
- }
-
- getConditionalOrder(
- params: LinearGetConditionalOrderRequest,
- ): Promise> {
- return this.getPrivate('private/linear/stop-order/list', params);
- }
-
- cancelConditionalOrder(
- params: LinearCancelConditionalOrderRequest,
- ): Promise> {
- return this.postPrivate('private/linear/stop-order/cancel', params);
- }
-
- cancelAllConditionalOrders(
- params: SymbolParam,
- ): Promise> {
- return this.postPrivate('private/linear/stop-order/cancel-all', params);
- }
-
- replaceConditionalOrder(
- params: LinearReplaceConditionalOrderRequest,
- ): Promise> {
- return this.postPrivate('private/linear/stop-order/replace', params);
- }
-
- queryConditionalOrder(
- params: LinearQueryConditionalOrderRequest,
- ): Promise> {
- return this.getPrivate('private/linear/stop-order/search', params);
- }
-
- /**
- * Position
- */
-
- getPosition(): Promise>;
-
- getPosition(
- params: Partial,
- ): Promise>;
-
- getPosition(
- params?: Partial,
- ): Promise> {
- return this.getPrivate('private/linear/position/list', params);
- }
-
- setAutoAddMargin(
- params?: LinearSetAutoAddMarginRequest,
- ): Promise> {
- return this.postPrivate(
- 'private/linear/position/set-auto-add-margin',
- params,
- );
- }
-
- setMarginSwitch(
- params?: LinearSetMarginSwitchRequest,
- ): Promise> {
- return this.postPrivate('private/linear/position/switch-isolated', params);
- }
-
- /**
- * Switch between one-way vs hedge mode. Use `linearPositionModeEnum` for the mode parameter.
- */
- setPositionMode(
- params: LinearSetPositionModeRequest,
- ): Promise> {
- return this.postPrivate('private/linear/position/switch-mode', params);
- }
-
- /**
- * Switch TP/SL mode between full or partial. When set to Partial, TP/SL orders may have a quantity less than the position size.
- * This is set with the setTradingStop() method. Use `positionTpSlModeEnum` for the tp_sl_mode parameter.
- */
- setPositionTpSlMode(
- params: LinearSetPositionTpSlModeRequest,
- ): Promise> {
- return this.postPrivate('private/linear/tpsl/switch-mode', params);
- }
-
- setAddReduceMargin(
- params?: LinearSetAddReduceMarginRequest,
- ): Promise> {
- return this.postPrivate('private/linear/position/add-margin', params);
- }
-
- setUserLeverage(
- params: LinearSetUserLeverageRequest,
- ): Promise> {
- return this.postPrivate('private/linear/position/set-leverage', params);
- }
-
- setTradingStop(
- params: LinearSetTradingStopRequest,
- ): Promise> {
- return this.postPrivate('private/linear/position/trading-stop', params);
- }
-
- getTradeRecords(
- params: LinearGetTradeRecordsRequest,
- ): Promise> {
- return this.getPrivate('private/linear/trade/execution/list', params);
- }
-
- getHistoryTradeRecords(
- params: LinearGetHistoryTradeRecordsRequest,
- ): Promise> {
- return this.getPrivate(
- '/private/linear/trade/execution/history-list',
- params,
- );
- }
-
- getClosedPnl(
- params: LinearGetClosedPnlRequest,
- ): Promise> {
- return this.getPrivate('private/linear/trade/closed-pnl/list', params);
- }
-
- /**
- * Risk Limit
- */
-
- getRiskLimitList(params: SymbolParam): Promise> {
- return this.getPrivate('public/linear/risk-limit', params);
- }
-
- setRiskLimit(
- params: LinearSetRiskLimitRequest,
- ): Promise> {
- return this.postPrivate('private/linear/position/set-risk', params);
- }
-
- /**
- * Funding
- */
-
- getPredictedFundingFee(
- params: SymbolParam,
- ): Promise> {
- return this.getPrivate('private/linear/funding/predicted-funding', params);
- }
-
- getLastFundingFee(params: SymbolParam): Promise> {
- return this.getPrivate('private/linear/funding/prev-funding', params);
- }
-}
diff --git a/src/rest-client-v5.ts b/src/rest-client-v5.ts
index 625f7a2..fc48402 100644
--- a/src/rest-client-v5.ts
+++ b/src/rest-client-v5.ts
@@ -57,7 +57,7 @@ import {
DeleteSubMemberParamsV5,
DeliveryPriceV5,
DeliveryRecordV5,
- DepositAddressResultV5,
+ DepositAddressChainV5,
DepositRecordV5,
ExchangeBrokerAccountInfoV5,
ExchangeBrokerEarningResultV5,
@@ -272,7 +272,7 @@ export class RestClientV5 extends BaseRestClient {
*/
getClientType() {
- return REST_CLIENT_TYPE_ENUM.v3;
+ return REST_CLIENT_TYPE_ENUM.v5;
}
async fetchServerTime(): Promise {
@@ -1489,7 +1489,12 @@ export class RestClientV5 extends BaseRestClient {
getMasterDepositAddress(
coin: string,
chainType?: string,
- ): Promise> {
+ ): Promise<
+ APIResponseV3WithTime<{
+ coin: string;
+ chains: DepositAddressChainV5[];
+ }>
+ > {
return this.getPrivate('/v5/asset/deposit/query-address', {
coin,
chainType,
@@ -1503,7 +1508,12 @@ export class RestClientV5 extends BaseRestClient {
coin: string,
chainType: string,
subMemberId: string,
- ): Promise> {
+ ): Promise<
+ APIResponseV3WithTime<{
+ coin: string;
+ chains: DepositAddressChainV5;
+ }>
+ > {
return this.getPrivate('/v5/asset/deposit/query-sub-member-address', {
coin,
chainType,
@@ -1514,6 +1524,7 @@ export class RestClientV5 extends BaseRestClient {
/**
* @deprecated - duplicate function, use getSubDepositAddress() instead
* Query the deposit address information of SUB account.
+ * @deprecated Duplicate endpoint - Use getSubDepositAddress() instead
*
* CAUTION
* Can use master UID's api key only
@@ -1522,7 +1533,12 @@ export class RestClientV5 extends BaseRestClient {
coin: string,
chainType: string,
subMemberId: string,
- ): Promise> {
+ ): Promise<
+ APIResponseV3<{
+ coin: string;
+ chains: DepositAddressChainV5;
+ }>
+ > {
return this.getPrivate('/v5/asset/deposit/query-sub-member-address', {
coin,
chainType,
diff --git a/src/spot-client-v3.ts b/src/spot-client-v3.ts
index 4bc1e8f..0ccf887 100644
--- a/src/spot-client-v3.ts
+++ b/src/spot-client-v3.ts
@@ -1,17 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
-import {
- APIResponseV3,
- APIResponseWithTime,
- KlineInterval,
- NewSpotOrderV3,
- SpotBalances,
- SpotCancelOrderBatchRequest,
- SpotCrossMarginBorrowingInfoRequest,
- SpotCrossMarginRepaymentHistoryRequest,
- SpotLeveragedTokenPRHistoryRequest,
- SpotMyTradesRequest,
- SpotOrderQueryById,
-} from './types';
+import { APIResponseV3, numberInString } from './types';
import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient';
@@ -24,8 +12,8 @@ import BaseRestClient from './util/BaseRestClient';
*/
export class SpotClientV3 extends BaseRestClient {
getClientType() {
- // Follows the same authentication mechanism as other v3 APIs (e.g. USDC)
- return REST_CLIENT_TYPE_ENUM.v3;
+ // Doesn't really matter here, since the only remaining endpoint does not require auth.
+ return REST_CLIENT_TYPE_ENUM.v5;
}
async fetchServerTime(): Promise {
@@ -39,17 +27,11 @@ export class SpotClientV3 extends BaseRestClient {
*
*/
- /** Get all symbols */
- getSymbols(): Promise> {
- return this.get('/spot/v3/public/symbols');
- }
-
- /** Get orderbook for symbol */
- getOrderBook(symbol: string, limit?: number): Promise> {
- return this.get('/spot/v3/public/quote/depth', { symbol, limit });
- }
-
- /** Get merged orderbook for symbol */
+ /**
+ * Get merged orderbook for symbol
+ *
+ * This is the only known pre-V5 endpoint to still be online.
+ */
getMergedOrderBook(
symbol: string,
scale?: number,
@@ -62,246 +44,13 @@ export class SpotClientV3 extends BaseRestClient {
});
}
- /** Get public trading records (raw trades) */
- getTrades(symbol: string, limit?: number): Promise> {
- return this.get('/spot/v3/public/quote/trades', { symbol, limit });
- }
-
- /** Get candles/klines */
- getCandles(
- symbol: string,
- interval: KlineInterval,
- limit?: number,
- startTime?: number,
- endTime?: number,
- ): Promise> {
- return this.get('/spot/v3/public/quote/kline', {
- symbol,
- interval,
- limit,
- startTime,
- endTime,
- });
- }
-
- /** Get latest information for symbol (24hr ticker) */
- get24hrTicker(symbol?: string): Promise> {
- return this.get('/spot/v3/public/quote/ticker/24hr', { symbol });
- }
-
- /** Get last traded price */
- getLastTradedPrice(symbol?: string): Promise> {
- return this.get('/spot/v3/public/quote/ticker/price', { symbol });
- }
-
- /** Get best bid/ask price */
- getBestBidAskPrice(symbol?: string): Promise> {
- return this.get('/spot/v3/public/quote/ticker/bookTicker', { symbol });
- }
-
- /**
- *
- * Account Data Endpoints
- *
- */
-
- /** -> Order API */
-
- /** Create order */
- submitOrder(params: NewSpotOrderV3): Promise> {
- return this.postPrivate('/spot/v3/private/order', params);
- }
-
- /** Get active order state */
- getOrder(params: SpotOrderQueryById): Promise> {
- return this.getPrivate('/spot/v3/private/order', params);
- }
-
- /** Cancel order */
- cancelOrder(params: SpotOrderQueryById): Promise