bybit-api 2.3.2 → 2.4.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +60 -152
  2. package/lib/account-asset-client.d.ts +42 -0
  3. package/lib/account-asset-client.js +104 -0
  4. package/lib/account-asset-client.js.map +1 -0
  5. package/lib/constants/enum.d.ts +18 -0
  6. package/lib/constants/enum.js +18 -0
  7. package/lib/constants/enum.js.map +1 -1
  8. package/lib/copy-trading-client.d.ts +54 -0
  9. package/lib/copy-trading-client.js +112 -0
  10. package/lib/copy-trading-client.js.map +1 -0
  11. package/lib/index.d.ts +7 -1
  12. package/lib/index.js +7 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib/inverse-client.d.ts +5 -13
  15. package/lib/inverse-client.js +6 -13
  16. package/lib/inverse-client.js.map +1 -1
  17. package/lib/inverse-futures-client.d.ts +4 -12
  18. package/lib/inverse-futures-client.js +5 -12
  19. package/lib/inverse-futures-client.js.map +1 -1
  20. package/lib/linear-client.d.ts +4 -12
  21. package/lib/linear-client.js +5 -12
  22. package/lib/linear-client.js.map +1 -1
  23. package/lib/spot-client-v3.d.ts +105 -0
  24. package/lib/spot-client-v3.js +222 -0
  25. package/lib/spot-client-v3.js.map +1 -0
  26. package/lib/spot-client.d.ts +5 -12
  27. package/lib/spot-client.js +6 -12
  28. package/lib/spot-client.js.map +1 -1
  29. package/lib/types/index.d.ts +1 -1
  30. package/lib/types/index.js +1 -1
  31. package/lib/types/index.js.map +1 -1
  32. package/lib/types/request/account-asset.d.ts +76 -0
  33. package/lib/types/request/account-asset.js +3 -0
  34. package/lib/types/request/account-asset.js.map +1 -0
  35. package/lib/types/request/copy-trading.d.ts +47 -0
  36. package/lib/types/request/copy-trading.js +3 -0
  37. package/lib/types/request/copy-trading.js.map +1 -0
  38. package/lib/types/request/index.d.ts +7 -0
  39. package/lib/types/request/index.js +7 -0
  40. package/lib/types/request/index.js.map +1 -1
  41. package/lib/types/request/spot.d.ts +72 -0
  42. package/lib/types/{spot.js → request/spot.js} +0 -0
  43. package/lib/types/{spot.js.map → request/spot.js.map} +1 -1
  44. package/lib/types/request/unified-margin.d.ts +223 -0
  45. package/lib/types/request/unified-margin.js +3 -0
  46. package/lib/types/request/unified-margin.js.map +1 -0
  47. package/lib/types/request/usdc-options.d.ts +119 -0
  48. package/lib/types/request/usdc-options.js +3 -0
  49. package/lib/types/request/usdc-options.js.map +1 -0
  50. package/lib/types/request/usdc-perp.d.ts +86 -0
  51. package/lib/types/request/usdc-perp.js +3 -0
  52. package/lib/types/request/usdc-perp.js.map +1 -0
  53. package/lib/types/request/usdc-shared.d.ts +29 -0
  54. package/lib/types/request/usdc-shared.js +3 -0
  55. package/lib/types/request/usdc-shared.js.map +1 -0
  56. package/lib/types/shared.d.ts +16 -5
  57. package/lib/types/websockets.d.ts +40 -0
  58. package/lib/types/websockets.js +3 -0
  59. package/lib/types/websockets.js.map +1 -0
  60. package/lib/unified-margin-client.d.ts +137 -0
  61. package/lib/unified-margin-client.js +269 -0
  62. package/lib/unified-margin-client.js.map +1 -0
  63. package/lib/usdc-option-client.d.ts +100 -0
  64. package/lib/usdc-option-client.js +186 -0
  65. package/lib/usdc-option-client.js.map +1 -0
  66. package/lib/usdc-perpetual-client.d.ts +88 -0
  67. package/lib/usdc-perpetual-client.js +181 -0
  68. package/lib/usdc-perpetual-client.js.map +1 -0
  69. package/lib/util/BaseRestClient.d.ts +15 -2
  70. package/lib/util/BaseRestClient.js +93 -29
  71. package/lib/util/BaseRestClient.js.map +1 -1
  72. package/lib/util/WsStore.d.ts +28 -8
  73. package/lib/util/WsStore.js +11 -3
  74. package/lib/util/WsStore.js.map +1 -1
  75. package/lib/util/index.d.ts +5 -0
  76. package/lib/util/index.js +18 -0
  77. package/lib/util/index.js.map +1 -0
  78. package/lib/{logger.d.ts → util/logger.d.ts} +0 -0
  79. package/lib/{logger.js → util/logger.js} +0 -0
  80. package/lib/util/logger.js.map +1 -0
  81. package/lib/util/requestUtils.d.ts +5 -1
  82. package/lib/util/requestUtils.js +9 -20
  83. package/lib/util/requestUtils.js.map +1 -1
  84. package/lib/util/websocket-util.d.ts +8 -0
  85. package/lib/util/websocket-util.js +39 -0
  86. package/lib/util/websocket-util.js.map +1 -0
  87. package/lib/websocket-client.d.ts +6 -58
  88. package/lib/websocket-client.js +63 -114
  89. package/lib/websocket-client.js.map +1 -1
  90. package/package.json +1 -1
  91. package/lib/logger.js.map +0 -1
  92. package/lib/types/spot.d.ts +0 -30
package/README.md CHANGED
@@ -4,9 +4,16 @@
4
4
  [![last commit](https://img.shields.io/github/last-commit/tiagosiebler/bybit-api)][1]
5
5
  [![CodeFactor](https://www.codefactor.io/repository/github/tiagosiebler/bybit-api/badge)](https://www.codefactor.io/repository/github/tiagosiebler/bybit-api)
6
6
 
7
+ [![connector logo](https://cdn.builder.io/api/v1/image/assets%2Ffddee401a9284ab792b271538c28932d%2F5190c99403ac474699a1959fdee1ab6c?format=webp&width=2000)][1]
8
+
7
9
  [1]: https://www.npmjs.com/package/bybit-api
8
10
 
9
- Node.js connector for the Bybit APIs and WebSockets, with TypeScript & browser support.
11
+ Node.js connector for the Bybit APIs and WebSockets:
12
+ - Complete integration with all bybit APIs.
13
+ - TypeScript support (with type declarations for most API requests & responses).
14
+ - Over 200 integration tests making real API calls, validating any changes before they reach npm.
15
+ - Robust WebSocket integration with connection heartbeats & automatic reconnection.
16
+ - Browser support (via webpack bundle - see "Browser Usage" below).
10
17
 
11
18
  ## Installation
12
19
  `npm install --save bybit-api`
@@ -21,43 +28,70 @@ Check out my related projects:
21
28
  - [ftx-api](https://www.npmjs.com/package/ftx-api)
22
29
  - [bybit-api](https://www.npmjs.com/package/bybit-api)
23
30
  - [binance](https://www.npmjs.com/package/binance)
31
+ - [okx-api](https://www.npmjs.com/package/okx-api)
24
32
  - Try my misc utilities:
25
33
  - [orderbooks](https://www.npmjs.com/package/orderbooks)
26
34
  - Check out my examples:
27
35
  - [awesome-crypto-examples](https://github.com/tiagosiebler/awesome-crypto-examples)
28
36
 
29
37
  ## Documentation
30
- Most methods accept JS objects. These can be populated using parameters specified by Bybit's API documentation.
31
- - [Bybit API Inverse Documentation](https://bybit-exchange.github.io/docs/inverse/#t-introduction).
32
- - [Bybit API Inverse Futures Documentation](https://bybit-exchange.github.io/docs/inverse_futures/#t-introduction).
33
- - [Bybit API Linear Documentation](https://bybit-exchange.github.io/docs/linear/#t-introduction)
38
+ Most methods accept JS objects. These can be populated using parameters specified by Bybit's API documentation, or check the type definition in each class within this repository (see table below for convenient links to each class).
39
+ - [Bybit API Docs (choose API category from the tabs at the top)](https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-introduction).
34
40
 
35
41
  ## Structure
36
- This project uses typescript. Resources are stored in 3 key structures:
37
- - [src](./src) - the whole connector written in typescript
38
- - [lib](./lib) - the javascript version of the project (compiled from typescript). This should not be edited directly, as it will be overwritten with each release.
42
+ The connector is written in TypeScript. A pure JavaScript version can be built using `npm run build`, which is also the version published to [npm](https://www.npmjs.com/package/bybit-api).
43
+
44
+ This connector is fully compatible with both TypeScript and pure JavaScript projects. The version on npm is the output from the `build` command and can be used in projects without TypeScript (although TypeScript is definitely recommended).
45
+
46
+ - [src](./src) - the whole connector written in TypeScript
47
+ - [lib](./lib) - the JavaScript version of the project (built from TypeScript). This should not be edited directly, as it will be overwritten with each release.
39
48
  - [dist](./dist) - the packed bundle of the project for use in browser environments.
40
49
  - [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
41
50
 
42
51
  ---
43
-
44
- # Usage
45
- Create API credentials at Bybit
52
+ ## REST API Clients
53
+ Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups:
54
+ | Class | Description |
55
+ |:------------------------------------------------------------------: |:----------------------------------------------------------------------------------------------------------------------------: |
56
+ | [InverseClient](src/inverse-client.ts) | [Inverse Perpetual Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/inverse/) |
57
+ | [LinearClient](src/linear-client.ts) | [USDT Perpetual Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/linear/#t-introduction) |
58
+ | [InverseFuturesClient](src/inverse-futures-client.ts) | [Inverse Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/inverse_futures/#t-introduction) |
59
+ | [USDCPerpetualClient](src/usdc-perpetual-client.ts) | [USDC Perpetual APIs](https://bybit-exchange.github.io/docs/usdc/option/?console#t-querydeliverylog) |
60
+ | [UnifiedMarginClient](src/unified-margin-client.ts) | [Derivatives (v3) unified margin APIs](https://bybit-exchange.github.io/docs/derivativesV3/unified_margin/#t-introduction) |
61
+ | [USDCOptionClient](src/usdc-option-client.ts) | [USDC Option APIs](https://bybit-exchange.github.io/docs/usdc/option/#t-introduction) |
62
+ | [SpotClientV3](src/spot-client-v3.ts) | [Spot Market (v3) APIs](https://bybit-exchange.github.io/docs/spot/v3/#t-introduction) |
63
+ | [~SpotClient~](src/spot-client.ts) (deprecated, v3 client recommended)| [Spot Market (v1) APIs](https://bybit-exchange.github.io/docs/spot/v1/#t-introduction) |
64
+ | [AccountAssetClient](src/account-asset-client.ts) | [Account Asset APIs](https://bybit-exchange.github.io/docs/account_asset/#t-introduction) |
65
+ | [CopyTradingClient](src/copy-trading-client.ts) | [Copy Trading APIs](https://bybit-exchange.github.io/docs/copy_trading/#t-introduction) |
66
+ | [WebsocketClient](src/websocket-client.ts) | All WebSocket Events (Public & Private for all API categories) |
67
+
68
+ Examples for using each client can be found in:
69
+ - the [examples](./examples) folder.
70
+ - the [awesome-crypto-examples](https://github.com/tiagosiebler/awesome-crypto-examples) repository.
71
+
72
+ If you're missing an example, you're welcome to request one. Priority will be given to [github sponsors](https://github.com/sponsors/tiagosiebler).
73
+
74
+ ### Usage
75
+ Create API credentials on Bybit's website:
46
76
  - [Livenet](https://bybit.com/app/user/api-management?affiliate_id=9410&language=en-US&group_id=0&group_type=1)
47
77
  - [Testnet](https://testnet.bybit.com/app/user/api-management)
48
78
 
49
- ## REST API Clients
50
-
51
- There are three REST API modules as there are some differences in each contract type.
52
- 1. `InverseClient` for inverse perpetual
53
- 2. `InverseFuturesClient` for inverse futures
54
- 3. `LinearClient` for linear perpetual
79
+ All REST clients have can be used in a similar way. However, method names, parameters and responses may vary depending on the API category you're using!
55
80
 
56
- ### REST Inverse
57
- To use the inverse REST APIs, import the `InverseClient`:
81
+ Not sure which function to call or which parameters to use? Click the class name in the table above to look at all the function names (they are in the same order as the official API docs), and check the API docs for a list of endpoints/paramters/responses.
58
82
 
59
83
  ```javascript
60
- const { InverseClient } = require('bybit-api');
84
+ const {
85
+ InverseClient,
86
+ LinearClient,
87
+ InverseFuturesClient,
88
+ SpotClient,
89
+ SpotClient3,
90
+ USDCOptionClient,
91
+ USDCPerpetualClient,
92
+ CopyTradingClient,
93
+ AccountAssetClient,
94
+ } = require('bybit-api');
61
95
 
62
96
  const restClientOptions = {
63
97
  // override the max size of the request window (in ms)
@@ -97,146 +131,23 @@ const client = new InverseClient(
97
131
 
98
132
  client.getApiKeyInfo()
99
133
  .then(result => {
100
- console.log("apiKey result: ", result);
134
+ console.log("getApiKeyInfo result: ", result);
101
135
  })
102
136
  .catch(err => {
103
- console.error("apiKey error: ", err);
137
+ console.error("getApiKeyInfo error: ", err);
104
138
  });
105
139
 
106
140
  client.getOrderBook({ symbol: 'BTCUSD' })
107
141
  .then(result => {
108
- console.log("getOrderBook inverse result: ", result);
109
- })
110
- .catch(err => {
111
- console.error("getOrderBook inverse error: ", err);
112
- });
113
- ```
114
-
115
-
116
- See [inverse-client.ts](./src/inverse-client.ts) for further information.
117
-
118
- ### REST Inverse Futures
119
- To use the inverse futures REST APIs, import the `InverseFuturesClient`:
120
-
121
- ```javascript
122
- const { InverseFuturesClient } = require('bybit-api');
123
-
124
- const API_KEY = 'xxx';
125
- const PRIVATE_KEY = 'yyy';
126
- const useLivenet = false;
127
-
128
- const client = new InverseFuturesClient(
129
- API_KEY,
130
- PRIVATE_KEY,
131
-
132
- // optional, uses testnet by default. Set to 'true' to use livenet.
133
- useLivenet,
134
-
135
- // restClientOptions,
136
- // requestLibraryOptions
137
- );
138
-
139
- client.getApiKeyInfo()
140
- .then(result => {
141
- console.log("apiKey result: ", result);
142
- })
143
- .catch(err => {
144
- console.error("apiKey error: ", err);
145
- });
146
-
147
- client.getOrderBook({ symbol: 'BTCUSDH21' })
148
- .then(result => {
149
- console.log("getOrderBook inverse futures result: ", result);
150
- })
151
- .catch(err => {
152
- console.error("getOrderBook inverse futures error: ", err);
153
- });
154
- ```
155
-
156
- See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further information.
157
-
158
- ### REST Linear
159
- To use the Linear (USDT) REST APIs, import the `LinearClient`:
160
-
161
- ```javascript
162
- const { LinearClient } = require('bybit-api');
163
-
164
- const API_KEY = 'xxx';
165
- const PRIVATE_KEY = 'yyy';
166
- const useLivenet = false;
167
-
168
- const client = new LinearClient(
169
- API_KEY,
170
- PRIVATE_KEY,
171
-
172
- // optional, uses testnet by default. Set to 'true' to use livenet.
173
- useLivenet,
174
-
175
- // restClientOptions,
176
- // requestLibraryOptions
177
- );
178
-
179
- client.getApiKeyInfo()
180
- .then(result => {
181
- console.log(result);
182
- })
183
- .catch(err => {
184
- console.error(err);
185
- });
186
-
187
- client.getOrderBook({ symbol: 'BTCUSDT' })
188
- .then(result => {
189
- console.log("getOrderBook linear result: ", result);
190
- })
191
- .catch(err => {
192
- console.error("getOrderBook linear error: ", err);
193
- });
194
- ```
195
-
196
- See [linear-client.ts](./src/linear-client.ts) for further information.
197
-
198
- ### REST Spot
199
- To use the Spot REST APIs, import the `SpotClient`:
200
-
201
- ```javascript
202
- const { SpotClient } = require('bybit-api');
203
-
204
- const API_KEY = 'xxx';
205
- const PRIVATE_KEY = 'yyy';
206
- const useLivenet = false;
207
-
208
- const client = new SpotClient(
209
- API_KEY,
210
- PRIVATE_KEY,
211
-
212
- // optional, uses testnet by default. Set to 'true' to use livenet.
213
- useLivenet,
214
-
215
- // restClientOptions,
216
- // requestLibraryOptions
217
- );
218
-
219
- client.getSymbols()
220
- .then(result => {
221
- console.log(result);
222
- })
223
- .catch(err => {
224
- console.error(err);
225
- });
226
-
227
- client.getBalances()
228
- .then(result => {
229
- console.log("getBalances result: ", result);
142
+ console.log("getOrderBook result: ", result);
230
143
  })
231
144
  .catch(err => {
232
- console.error("getBalances error: ", err);
145
+ console.error("getOrderBook error: ", err);
233
146
  });
234
147
  ```
235
148
 
236
- See [spot-client.ts](./src/spot-client.ts) for further information.
237
-
238
149
  ## WebSockets
239
- Inverse, linear & spot WebSockets can be used via a shared `WebsocketClient`. However, make sure to make one instance of WebsocketClient per market type (spot vs inverse vs linear vs linearfutures):
150
+ All API groups can be used via a shared `WebsocketClient`. However, make sure to make one instance of the WebsocketClient per API group (spot vs inverse vs linear vs linearfutures etc):
240
151
 
241
152
  ```javascript
242
153
  const { WebsocketClient } = require('bybit-api');
@@ -316,11 +227,8 @@ ws.on('error', err => {
316
227
  });
317
228
  ```
318
229
 
319
-
320
230
  See [websocket-client.ts](./src/websocket-client.ts) for further information.
321
231
 
322
- Note: for linear websockets, pass `linear: true` in the constructor options when instancing the `WebsocketClient`. To connect to both linear and inverse websockets, make two instances of the WebsocketClient.
323
-
324
232
  ---
325
233
 
326
234
  ## Customise Logging
@@ -362,7 +270,7 @@ Or buy me a coffee using any of these:
362
270
  - ETH (ERC20): `0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da`
363
271
 
364
272
  #### pixtron
365
- The original library was started by @pixtron. If this library helps you to trade better on bybit, feel free to donate a coffee to @pixtron:
273
+ An early generation of this library was started by @pixtron. If this library helps you to trade better on bybit, feel free to donate a coffee to @pixtron:
366
274
  - BTC `1Fh1158pXXudfM6ZrPJJMR7Y5SgZUz4EdF`
367
275
  - ETH `0x21aEdeC53ab7593b77C9558942f0c9E78131e8d7`
368
276
  - LTC `LNdHSVtG6UWsriMYLJR3qLdfVNKwJ6GSLF`
@@ -0,0 +1,42 @@
1
+ import { AccountAssetInformationRequest, APIResponseWithTime, DepositRecordsRequest, EnableUniversalTransferRequest, InternalTransferRequest, SubAccountTransferRequest, SupportedDepositListRequest, TransferQueryRequest, UniversalTransferRequest, WithdrawalRecordsRequest, WithdrawalRequest } from './types';
2
+ import BaseRestClient from './util/BaseRestClient';
3
+ /**
4
+ * REST API client for Account Asset APIs
5
+ */
6
+ export declare class AccountAssetClient extends BaseRestClient {
7
+ getClientType(): "accountAsset";
8
+ fetchServerTime(): Promise<number>;
9
+ /**
10
+ *
11
+ * Transfer Data Endpoints
12
+ *
13
+ */
14
+ createInternalTransfer(params: InternalTransferRequest): Promise<APIResponseWithTime<any>>;
15
+ createSubAccountTransfer(params: SubAccountTransferRequest): Promise<APIResponseWithTime<any>>;
16
+ getInternalTransfers(params?: TransferQueryRequest): Promise<APIResponseWithTime<any>>;
17
+ getSubAccountTransfers(params?: TransferQueryRequest): Promise<APIResponseWithTime<any>>;
18
+ getSubAccounts(): Promise<APIResponseWithTime<any>>;
19
+ enableUniversalTransfer(params?: EnableUniversalTransferRequest): Promise<APIResponseWithTime<any>>;
20
+ createUniversalTransfer(params: UniversalTransferRequest): Promise<APIResponseWithTime<any>>;
21
+ getUniversalTransfers(params?: TransferQueryRequest): Promise<APIResponseWithTime<any>>;
22
+ /**
23
+ *
24
+ * Wallet & Deposit Endpoints
25
+ *
26
+ */
27
+ getSupportedDepositList(params?: SupportedDepositListRequest): Promise<APIResponseWithTime<any>>;
28
+ getDepositRecords(params?: DepositRecordsRequest): Promise<APIResponseWithTime<any>>;
29
+ getWithdrawRecords(params?: WithdrawalRecordsRequest): Promise<APIResponseWithTime<any>>;
30
+ getCoinInformation(coin?: string): Promise<APIResponseWithTime<any>>;
31
+ getAssetInformation(params?: AccountAssetInformationRequest): Promise<APIResponseWithTime<any>>;
32
+ submitWithdrawal(params: WithdrawalRequest): Promise<APIResponseWithTime<any>>;
33
+ cancelWithdrawal(withdrawalId: number): Promise<APIResponseWithTime<any>>;
34
+ getDepositAddress(coin: string): Promise<APIResponseWithTime<any>>;
35
+ /**
36
+ *
37
+ * API Data Endpoints
38
+ *
39
+ */
40
+ getServerTime(): Promise<APIResponseWithTime>;
41
+ getApiAnnouncements(): Promise<APIResponseWithTime<any[]>>;
42
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.AccountAssetClient = void 0;
16
+ const util_1 = require("./util");
17
+ const BaseRestClient_1 = __importDefault(require("./util/BaseRestClient"));
18
+ /**
19
+ * REST API client for Account Asset APIs
20
+ */
21
+ class AccountAssetClient extends BaseRestClient_1.default {
22
+ getClientType() {
23
+ return util_1.REST_CLIENT_TYPE_ENUM.accountAsset;
24
+ }
25
+ fetchServerTime() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const res = yield this.getServerTime();
28
+ return Number(res.time_now);
29
+ });
30
+ }
31
+ /**
32
+ *
33
+ * Transfer Data Endpoints
34
+ *
35
+ */
36
+ createInternalTransfer(params) {
37
+ return this.postPrivate('/asset/v1/private/transfer', params);
38
+ }
39
+ createSubAccountTransfer(params) {
40
+ return this.postPrivate('/asset/v1/private/sub-member/transfer', params);
41
+ }
42
+ getInternalTransfers(params) {
43
+ return this.getPrivate('/asset/v1/private/transfer/list', params);
44
+ }
45
+ getSubAccountTransfers(params) {
46
+ return this.getPrivate('/asset/v1/private/sub-member/transfer/list', params);
47
+ }
48
+ getSubAccounts() {
49
+ return this.getPrivate('/asset/v1/private/sub-member/member-ids');
50
+ }
51
+ enableUniversalTransfer(params) {
52
+ return this.postPrivate('/asset/v1/private/transferable-subs/save', params);
53
+ }
54
+ createUniversalTransfer(params) {
55
+ return this.postPrivate('/asset/v1/private/universal/transfer', params);
56
+ }
57
+ getUniversalTransfers(params) {
58
+ return this.getPrivate('/asset/v1/private/universal/transfer/list', params);
59
+ }
60
+ /**
61
+ *
62
+ * Wallet & Deposit Endpoints
63
+ *
64
+ */
65
+ getSupportedDepositList(params) {
66
+ return this.get('/asset/v1/public/deposit/allowed-deposit-list', params);
67
+ }
68
+ getDepositRecords(params) {
69
+ return this.getPrivate('/asset/v1/private/deposit/record/query', params);
70
+ }
71
+ getWithdrawRecords(params) {
72
+ return this.getPrivate('/asset/v1/private/withdraw/record/query', params);
73
+ }
74
+ getCoinInformation(coin) {
75
+ return this.getPrivate('/asset/v1/private/coin-info/query', { coin });
76
+ }
77
+ getAssetInformation(params) {
78
+ return this.getPrivate('/asset/v1/private/asset-info/query', params);
79
+ }
80
+ submitWithdrawal(params) {
81
+ return this.postPrivate('/asset/v1/private/withdraw', params);
82
+ }
83
+ cancelWithdrawal(withdrawalId) {
84
+ return this.postPrivate('/asset/v1/private/withdraw/cancel', {
85
+ id: withdrawalId,
86
+ });
87
+ }
88
+ getDepositAddress(coin) {
89
+ return this.getPrivate('/asset/v1/private/deposit/address', { coin });
90
+ }
91
+ /**
92
+ *
93
+ * API Data Endpoints
94
+ *
95
+ */
96
+ getServerTime() {
97
+ return this.get('/v2/public/time');
98
+ }
99
+ getApiAnnouncements() {
100
+ return this.get('/v2/public/announcement');
101
+ }
102
+ }
103
+ exports.AccountAssetClient = AccountAssetClient;
104
+ //# sourceMappingURL=account-asset-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account-asset-client.js","sourceRoot":"","sources":["../src/account-asset-client.ts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O,IAAI,CAAC,GAAG,CAAC,+CAA+C,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC;IAED,iBAAiB,CACf,MAA8B;QAE9B,OAAO,IAAI,CAAC,UAAU,CAAC,wCAAwC,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC;IAED,kBAAkB,CAChB,MAAiC;QAEjC,OAAO,IAAI,CAAC,UAAU,CAAC,yCAAyC,EAAE,MAAM,CAAC,CAAC;IAC5E,CAAC;IAED,kBAAkB,CAAC,IAAa;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,mCAAmC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,mBAAmB,CACjB,MAAuC;QAEvC,OAAO,IAAI,CAAC,UAAU,CAAC,oCAAoC,EAAE,MAAM,CAAC,CAAC;IACvE,CAAC;IAED,gBAAgB,CACd,MAAyB;QAEzB,OAAO,IAAI,CAAC,WAAW,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IAED,gBAAgB,CAAC,YAAoB;QACnC,OAAO,IAAI,CAAC,WAAW,CAAC,mCAAmC,EAAE;YAC3D,EAAE,EAAE,YAAY;SACjB,CAAC,CAAC;IACL,CAAC;IAED,iBAAiB,CAAC,IAAY;QAC5B,OAAO,IAAI,CAAC,UAAU,CAAC,mCAAmC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACxE,CAAC;IAED;;;;OAIG;IAEH,aAAa;QACX,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;CACF;AAhID,gDAgIC"}
@@ -11,8 +11,20 @@ export declare const positionTpSlModeEnum: {
11
11
  export declare const API_ERROR_CODE: {
12
12
  readonly BALANCE_INSUFFICIENT_SPOT: -1131;
13
13
  readonly ORDER_NOT_FOUND_OR_TOO_LATE_SPOT: -2013;
14
+ readonly SUCCESS: 0;
14
15
  /** This could mean bad request, incorrect value types or even incorrect/missing values */
15
16
  readonly PARAMS_MISSING_OR_WRONG: 10001;
17
+ readonly INVALID_API_KEY_OR_PERMISSIONS: 10003;
18
+ readonly INCORRECT_API_KEY_PERMISSIONS: 10005;
19
+ /** Account not unified margin, update required */
20
+ readonly ACCOUNT_NOT_UNIFIED: 10020;
21
+ readonly BALANCE_INSUFFICIENT_SPOT_V3: 12131;
22
+ readonly ORDER_NOT_FOUND_SPOT_V3: 12213;
23
+ readonly ORDER_NOT_FOUND_LEVERAGED_TOKEN: 12407;
24
+ readonly EXCEEDED_UPPER_LIMIT_LEVERAGED_TOKEN: 12409;
25
+ readonly QUERY_ACCOUNT_INFO_ERROR: 12602;
26
+ readonly CROSS_MARGIN_USER_NOT_FOUND: 12607;
27
+ readonly CROSS_MARGIN_REPAYMENT_NOT_REQUIRED: 12616;
16
28
  readonly ORDER_NOT_FOUND_OR_TOO_LATE: 20001;
17
29
  readonly POSITION_STATUS_NOT_NORMAL: 30013;
18
30
  readonly CANNOT_SET_TRADING_STOP_FOR_ZERO_POS: 30024;
@@ -37,6 +49,12 @@ export declare const API_ERROR_CODE: {
37
49
  readonly INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR: 130080;
38
50
  readonly SAME_SLTP_MODE_LINEAR: 130150;
39
51
  readonly RISK_ID_NOT_MODIFIED: 134026;
52
+ readonly ORDER_NOT_EXIST: 3100136;
53
+ readonly NO_ACTIVE_ORDER: 3100205;
54
+ /** E.g. USDC Options trading when the account hasn't been opened for USDC Options yet */
55
+ readonly ACCOUNT_NOT_EXIST: 3200200;
56
+ readonly INCORRECT_MMP_PARAMETERS: 3500712;
57
+ readonly INSTITION_MMP_PROFILE_NOT_FOUND: 3500713;
40
58
  };
41
59
  /**
42
60
  * Position idx, used to identify positions in different position modes.
@@ -14,8 +14,20 @@ exports.positionTpSlModeEnum = {
14
14
  exports.API_ERROR_CODE = {
15
15
  BALANCE_INSUFFICIENT_SPOT: -1131,
16
16
  ORDER_NOT_FOUND_OR_TOO_LATE_SPOT: -2013,
17
+ SUCCESS: 0,
17
18
  /** This could mean bad request, incorrect value types or even incorrect/missing values */
18
19
  PARAMS_MISSING_OR_WRONG: 10001,
20
+ INVALID_API_KEY_OR_PERMISSIONS: 10003,
21
+ INCORRECT_API_KEY_PERMISSIONS: 10005,
22
+ /** Account not unified margin, update required */
23
+ ACCOUNT_NOT_UNIFIED: 10020,
24
+ BALANCE_INSUFFICIENT_SPOT_V3: 12131,
25
+ ORDER_NOT_FOUND_SPOT_V3: 12213,
26
+ ORDER_NOT_FOUND_LEVERAGED_TOKEN: 12407,
27
+ EXCEEDED_UPPER_LIMIT_LEVERAGED_TOKEN: 12409,
28
+ QUERY_ACCOUNT_INFO_ERROR: 12602,
29
+ CROSS_MARGIN_USER_NOT_FOUND: 12607,
30
+ CROSS_MARGIN_REPAYMENT_NOT_REQUIRED: 12616,
19
31
  ORDER_NOT_FOUND_OR_TOO_LATE: 20001,
20
32
  POSITION_STATUS_NOT_NORMAL: 30013,
21
33
  CANNOT_SET_TRADING_STOP_FOR_ZERO_POS: 30024,
@@ -40,6 +52,12 @@ exports.API_ERROR_CODE = {
40
52
  INSUFFICIENT_BALANCE_FOR_ORDER_COST_LINEAR: 130080,
41
53
  SAME_SLTP_MODE_LINEAR: 130150,
42
54
  RISK_ID_NOT_MODIFIED: 134026,
55
+ ORDER_NOT_EXIST: 3100136,
56
+ NO_ACTIVE_ORDER: 3100205,
57
+ /** E.g. USDC Options trading when the account hasn't been opened for USDC Options yet */
58
+ ACCOUNT_NOT_EXIST: 3200200,
59
+ INCORRECT_MMP_PARAMETERS: 3500712,
60
+ INSTITION_MMP_PROFILE_NOT_FOUND: 3500713,
43
61
  };
44
62
  /**
45
63
  * Position idx, used to identify positions in different position modes.
@@ -1 +1 @@
1
- {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/constants/enum.ts"],"names":[],"mappings":";;;AAAa,QAAA,sB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AE,OAAO;IACxB,eAAe,EAAE,OAAO;IACxB,yFAAyF;IACzF,iBAAiB,EAAE,OAAO;IAC1B,wBAAwB,EAAE,OAAO;IACjC,+BAA+B,EAAE,OAAO;CAChC,CAAC;AAEX;;;GAGG;AACH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,qEAAc,CAAA;IACd,+DAAW,CAAA;IACX,iEAAY,CAAA;AACd,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B"}
@@ -0,0 +1,54 @@
1
+ import { APIResponseWithTime, CopyTradingCancelOrderRequest, CopyTradingCloseOrderRequest, CopyTradingOrderListRequest, CopyTradingOrderRequest, CopyTradingTradingStopRequest, CopyTradingTransferRequest, APIResponseV3 } from './types';
2
+ import BaseRestClient from './util/BaseRestClient';
3
+ /**
4
+ * REST API client for USDC Perpetual APIs
5
+ */
6
+ export declare class CopyTradingClient extends BaseRestClient {
7
+ getClientType(): "v3";
8
+ fetchServerTime(): Promise<number>;
9
+ /**
10
+ *
11
+ * Market Data Endpoints
12
+ *
13
+ */
14
+ getSymbols(): Promise<APIResponseV3<any>>;
15
+ /**
16
+ *
17
+ * Account Data Endpoints
18
+ *
19
+ */
20
+ /** -> Order API */
21
+ /** Create order */
22
+ submitOrder(params: CopyTradingOrderRequest): Promise<APIResponseV3<any>>;
23
+ /** Set Trading Stop */
24
+ setTradingStop(params: CopyTradingTradingStopRequest): Promise<APIResponseV3<any>>;
25
+ /** Query Order List */
26
+ getActiveOrders(params?: CopyTradingOrderListRequest): Promise<APIResponseV3<any>>;
27
+ /** Cancel order */
28
+ cancelOrder(params: CopyTradingCancelOrderRequest): Promise<APIResponseV3<any>>;
29
+ /** 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. */
30
+ closeOrder(params: CopyTradingCloseOrderRequest): Promise<APIResponseV3<any>>;
31
+ /** -> Positions API */
32
+ /** Position List */
33
+ getPositions(symbol?: string): Promise<APIResponseV3<any>>;
34
+ /** Close Position */
35
+ closePosition(symbol: string, positionIdx: string): Promise<APIResponseV3<any>>;
36
+ /** Only integers can be set to set the leverage */
37
+ setLeverage(symbol: string, buyLeverage: string, sellLeverage: string): Promise<APIResponseV3<any>>;
38
+ /**
39
+ *
40
+ * Wallet Data Endpoints
41
+ *
42
+ */
43
+ /** Get Wallet Balance */
44
+ getBalances(): Promise<APIResponseV3<any>>;
45
+ /** Transfer */
46
+ transfer(params: CopyTradingTransferRequest): Promise<APIResponseV3<any>>;
47
+ /**
48
+ *
49
+ * API Data Endpoints
50
+ *
51
+ */
52
+ getServerTime(): Promise<APIResponseWithTime>;
53
+ getAnnouncements(): Promise<APIResponseWithTime<any[]>>;
54
+ }