bitget-api 0.0.1 → 1.0.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 (89) hide show
  1. package/README.md +86 -141
  2. package/lib/broker-client.d.ts +46 -0
  3. package/lib/broker-client.js +113 -0
  4. package/lib/broker-client.js.map +1 -0
  5. package/lib/constants/enum.d.ts +17 -0
  6. package/lib/constants/enum.js +21 -0
  7. package/lib/constants/enum.js.map +1 -0
  8. package/lib/futures-client.d.ts +146 -0
  9. package/lib/futures-client.js +380 -0
  10. package/lib/futures-client.js.map +1 -0
  11. package/lib/index.d.ts +8 -1
  12. package/lib/index.js +22 -13
  13. package/lib/index.js.map +1 -1
  14. package/lib/spot-client.d.ts +109 -0
  15. package/lib/spot-client.js +201 -0
  16. package/lib/spot-client.js.map +1 -0
  17. package/lib/types/index.d.ts +4 -0
  18. package/lib/types/index.js +21 -0
  19. package/lib/types/index.js.map +1 -0
  20. package/lib/types/request/broker.d.ts +23 -0
  21. package/lib/types/request/broker.js +3 -0
  22. package/lib/types/request/broker.js.map +1 -0
  23. package/lib/types/request/futures.d.ts +114 -0
  24. package/lib/types/request/futures.js +3 -0
  25. package/lib/types/request/futures.js.map +1 -0
  26. package/lib/types/request/index.d.ts +4 -0
  27. package/lib/types/request/index.js +21 -0
  28. package/lib/types/request/index.js.map +1 -0
  29. package/lib/types/request/shared.d.ts +10 -0
  30. package/lib/types/request/shared.js +3 -0
  31. package/lib/types/request/shared.js.map +1 -0
  32. package/lib/types/request/spot.d.ts +19 -0
  33. package/lib/types/request/spot.js +3 -0
  34. package/lib/types/request/spot.js.map +1 -0
  35. package/lib/types/response/futures.d.ts +55 -0
  36. package/lib/types/response/futures.js +3 -0
  37. package/lib/types/response/futures.js.map +1 -0
  38. package/lib/types/response/index.d.ts +3 -0
  39. package/lib/types/response/index.js +20 -0
  40. package/lib/types/response/index.js.map +1 -0
  41. package/lib/types/response/shared.d.ts +6 -0
  42. package/lib/types/response/shared.js +3 -0
  43. package/lib/types/response/shared.js.map +1 -0
  44. package/lib/types/response/spot.d.ts +21 -0
  45. package/lib/types/response/spot.js +3 -0
  46. package/lib/types/response/spot.js.map +1 -0
  47. package/lib/types/shared.d.ts +5 -0
  48. package/lib/types/shared.js +3 -0
  49. package/lib/types/shared.js.map +1 -0
  50. package/lib/types/websockets/client.d.ts +37 -0
  51. package/lib/types/websockets/client.js +3 -0
  52. package/lib/types/websockets/client.js.map +1 -0
  53. package/lib/types/websockets/events.d.ts +75 -0
  54. package/lib/types/websockets/events.js +3 -0
  55. package/lib/types/websockets/events.js.map +1 -0
  56. package/lib/types/websockets/index.d.ts +2 -0
  57. package/lib/types/websockets/index.js +19 -0
  58. package/lib/types/websockets/index.js.map +1 -0
  59. package/lib/util/BaseRestClient.d.ts +40 -0
  60. package/lib/util/BaseRestClient.js +195 -0
  61. package/lib/util/BaseRestClient.js.map +1 -0
  62. package/lib/util/WsStore.d.ts +62 -0
  63. package/lib/util/WsStore.js +135 -0
  64. package/lib/util/WsStore.js.map +1 -0
  65. package/lib/util/browser-support.d.ts +1 -0
  66. package/lib/util/browser-support.js +44 -0
  67. package/lib/util/browser-support.js.map +1 -0
  68. package/lib/util/index.d.ts +6 -0
  69. package/lib/util/index.js +23 -0
  70. package/lib/util/index.js.map +1 -0
  71. package/lib/util/logger.d.ts +9 -0
  72. package/lib/util/logger.js +24 -0
  73. package/lib/util/logger.js.map +1 -0
  74. package/lib/util/node-support.d.ts +2 -0
  75. package/lib/util/node-support.js +33 -0
  76. package/lib/util/node-support.js.map +1 -0
  77. package/lib/util/requestUtils.d.ts +31 -0
  78. package/lib/util/requestUtils.js +53 -0
  79. package/lib/util/requestUtils.js.map +1 -0
  80. package/lib/util/type-guards.d.ts +9 -0
  81. package/lib/util/type-guards.js +50 -0
  82. package/lib/util/type-guards.js.map +1 -0
  83. package/lib/util/websocket-util.d.ts +38 -0
  84. package/lib/util/websocket-util.js +100 -0
  85. package/lib/util/websocket-util.js.map +1 -0
  86. package/lib/websocket-client.d.ts +121 -0
  87. package/lib/websocket-client.js +442 -0
  88. package/lib/websocket-client.js.map +1 -0
  89. package/package.json +16 -16
package/README.md CHANGED
@@ -1,14 +1,21 @@
1
- # bitget-api
2
- [![Tests](https://circleci.com/gh/tiagosiebler/bitget-api.svg?style=shield)](https://circleci.com/gh/tiagosiebler/bitget-api)
3
- [![npm version](https://img.shields.io/npm/v/bitget-api)][1] [![npm size](https://img.shields.io/bundlephobia/min/bitget-api/latest)][1] [![npm downloads](https://img.shields.io/npm/dt/bitget-api)][1]
1
+ # Node.js & Typescript Bitget API SDK
2
+
3
+ [![Build & Test](https://github.com/tiagosiebler/bitget-api/actions/workflows/e2etests.yml/badge.svg?branch=master)](https://github.com/tiagosiebler/bitget-api/actions/workflows/e2etests.yml) [![npm version](https://img.shields.io/npm/v/bitget-api)][1] [![npm size](https://img.shields.io/bundlephobia/min/bitget-api/latest)][1] [![npm downloads](https://img.shields.io/npm/dt/bitget-api)][1]
4
4
  [![last commit](https://img.shields.io/github/last-commit/tiagosiebler/bitget-api)][1]
5
- [![CodeFactor](https://www.codefactor.io/repository/github/tiagosiebler/bitget-api/badge)](https://www.codefactor.io/repository/github/tiagosiebler/bitget-api)
5
+ [![CodeFactor](https://www.codefactor.io/repository/github/tiagosiebler/bitget-api/badge)](https://www.codefactor.io/repository/github/tiagosiebler/bitget-api) [![Telegram](https://img.shields.io/badge/chat-on%20telegram-blue.svg)](https://t.me/nodetraders)
6
+
7
+
8
+ [![connector logo](https://github.com/tiagosiebler/bitget-api/blob/master/docs/images/logo1.png?raw=true)][1]
6
9
 
7
10
  [1]: https://www.npmjs.com/package/bitget-api
8
11
 
9
- WARNING: This package is still early beta, following the designs of my other connectors. If you want to stay informed when this may be ready for testing, please get in touch via telegram.
10
12
 
11
- Node.js connector for the bitget APIs and WebSockets, with TypeScript & browser support.
13
+ Node.js connector for the Bitget APIs and WebSockets:
14
+ - Complete integration with all Bitget APIs.
15
+ - TypeScript support (with type declarations for most API requests & responses).
16
+ - Over 100 integration tests making real API calls & WebSocket connections, validating any changes before they reach npm.
17
+ - Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
18
+ - Browser support (via webpack bundle - see "Browser Usage" below).
12
19
 
13
20
  ## Installation
14
21
  `npm install --save bitget-api`
@@ -17,171 +24,101 @@ Node.js connector for the bitget APIs and WebSockets, with TypeScript & browser
17
24
  - Issues? Check the [issues tab](https://github.com/tiagosiebler/bitget-api/issues).
18
25
  - Discuss & collaborate with other node devs? Join our [Node.js Algo Traders](https://t.me/nodetraders) engineering community on telegram.
19
26
 
27
+ ## Related projects
28
+ Check out my related projects:
29
+ - Try my connectors:
30
+ - [binance](https://www.npmjs.com/package/binance)
31
+ - [bybit-api](https://www.npmjs.com/package/bybit-api)
32
+ - [okx-api](https://www.npmjs.com/package/okx-api)
33
+ - [bitget-api](https://www.npmjs.com/package/bitget-api)
34
+ - [ftx-api](https://www.npmjs.com/package/ftx-api)
35
+ - Try my misc utilities:
36
+ - [orderbooks](https://www.npmjs.com/package/orderbooks)
37
+ - Check out my examples:
38
+ - [awesome-crypto-examples](https://github.com/tiagosiebler/awesome-crypto-examples)
39
+
20
40
  ## Documentation
21
- Most methods accept JS objects. These can be populated using parameters specified by bitget's API documentation.
22
- - [bitget API Documentation](https://www.bitget.com/docs-v5/en/#rest-api).
41
+ Most methods pass values as-is into HTTP requests. These can be populated using parameters specified by Bitget's API documentation, or check the type definition in each class within this repository (see table below for convenient links to each class).
42
+ - [Bitget API Documentation](https://www.bitget.com/docs-v5/en/#rest-api).
23
43
 
24
44
  ## Structure
25
- This project uses typescript. Resources are stored in 3 key structures:
26
- - [src](./src) - the whole connector written in typescript
27
- - [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.
28
- - [dist](./dist) - the packed bundle of the project for use in browser environments.
45
+ This connector is fully compatible with both TypeScript and pure JavaScript projects, while 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/bitget-api).
46
+
47
+ The version on npm is the output from the `build` command and can be used in projects without TypeScript (although TypeScript is definitely recommended).
48
+ - [src](./src) - the whole connector written in TypeScript
49
+ - [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.
50
+ - [dist](./dist) - the webpack bundle of the project for use in browser environments (see guidance on webpack below).
29
51
  - [examples](./examples) - some implementation examples & demonstrations. Contributions are welcome!
30
52
 
31
53
  ---
32
54
 
33
- # Usage
34
- Create API credentials at bitget
35
- - [bitget my-api](https://www.bitget.com/account/my-api)
55
+ ## REST API Clients
56
+ Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups:
57
+ | Class | Description |
58
+ |:------------------------------------: |:---------------------------------------------------------------------------------------------: |
59
+ | [SpotClient](src/spot-client.ts) | [Spot APIs](https://bitgetlimited.github.io/apidoc/en/spot/#introduction) |
60
+ | [FuturesClient](src/futures-client.ts) | [Futures APIs](https://bitgetlimited.github.io/apidoc/en/mix/#introduction) |
61
+ | [BrokerClient](src/broker-client.ts) | [Broker APIs](https://bitgetlimited.github.io/apidoc/en/broker/#introduction) |
62
+ | [WebsocketClient](src/websocket-client.ts) | Universal client for all Bitget's Websockets |
36
63
 
37
- <!--
38
- ### REST Inverse
39
- To use the inverse REST APIs, import the `InverseClient`:
64
+ Examples for using each client can be found in:
65
+ - the [examples](./examples) folder.
66
+ - the [awesome-crypto-examples](https://github.com/tiagosiebler/awesome-crypto-examples) repository.
40
67
 
41
- ```javascript
42
- const { InverseClient } = require('bitget-api');
68
+ If you're missing an example, you're welcome to request one. Priority will be given to [github sponsors](https://github.com/sponsors/tiagosiebler).
43
69
 
44
- const restClientOptions = {
45
- // override the max size of the request window (in ms)
46
- recv_window?: number;
47
70
 
48
- // how often to sync time drift with bitget servers
49
- sync_interval_ms?: number | string;
71
+ ### Usage
72
+ First, create API credentials on Bitget's website.
50
73
 
51
- // Default: false. Disable above sync mechanism if true.
52
- disable_time_sync?: boolean;
74
+ 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!
53
75
 
54
- // Default: false. If true, we'll throw errors if any params are undefined
55
- strict_param_validation?: boolean;
76
+ 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.
56
77
 
57
- // Optionally override API protocol + domain
58
- // e.g 'https://api.bytick.com'
59
- baseUrl?: string;
60
-
61
- // Default: true. whether to try and post-process request exceptions.
62
- parse_exceptions?: boolean;
63
- };
78
+ ```javascript
79
+ const {
80
+ SpotClient,
81
+ FuturesClient,
82
+ BrokerClient,
83
+ } = require('bitget-api');
64
84
 
65
85
  const API_KEY = 'xxx';
66
- const PRIVATE_KEY = 'yyy';
67
- const useLivenet = false;
68
-
69
- const client = new InverseClient(
70
- API_KEY,
71
- PRIVATE_KEY,
72
-
73
- // optional, uses testnet by default. Set to 'true' to use livenet.
74
- useLivenet,
75
-
76
- // restClientOptions,
86
+ const API_SECRET = 'yyy';
87
+ const API_PASS = 'zzz';
88
+
89
+ const client = new SpotClient({
90
+ apiKey: API_KEY,
91
+ apiSecret: API_SECRET,
92
+ apiPass: API_PASS,
93
+ },
77
94
  // requestLibraryOptions
78
95
  );
79
96
 
97
+ // For public-only API calls, simply don't provide a key & secret or set them to undefined
98
+ // const client = new SpotClient();
99
+
100
+
80
101
  client.getApiKeyInfo()
81
102
  .then(result => {
82
- console.log("apiKey result: ", result);
103
+ console.log("getApiKeyInfo result: ", result);
83
104
  })
84
105
  .catch(err => {
85
- console.error("apiKey error: ", err);
106
+ console.error("getApiKeyInfo error: ", err);
86
107
  });
87
108
 
88
- client.getOrderBook({ symbol: 'BTCUSD' })
109
+ const symbol = 'BTCUSDT_SPBL';
110
+ client.getCandles(symbol, '1min');
89
111
  .then(result => {
90
- console.log("getOrderBook inverse result: ", result);
112
+ console.log("getCandles result: ", result);
91
113
  })
92
114
  .catch(err => {
93
- console.error("getOrderBook inverse error: ", err);
115
+ console.error("getCandles error: ", err);
94
116
  });
95
117
  ```
96
118
 
119
+ #### WebSockets
97
120
 
98
- See [inverse-client.ts](./src/inverse-client.ts) for further information. -->
99
-
100
- ## WebSockets
101
- 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):
102
-
103
- ```javascript
104
- const { WebsocketClient } = require('bitget-api');
105
-
106
- const API_KEY = 'xxx';
107
- const PRIVATE_KEY = 'yyy';
108
-
109
- const wsConfig = {
110
- key: API_KEY,
111
- secret: PRIVATE_KEY,
112
-
113
- /*
114
- The following parameters are optional:
115
- */
116
-
117
- // defaults to false == testnet. Set to true for livenet.
118
- // livenet: true
119
-
120
- // NOTE: to listen to multiple markets (spot vs inverse vs linear vs linearfutures) at once, make one WebsocketClient instance per market
121
-
122
- // defaults to inverse:
123
- // market: 'inverse'
124
- // market: 'linear'
125
- // market: 'spot'
126
-
127
- // how long to wait (in ms) before deciding the connection should be terminated & reconnected
128
- // pongTimeout: 1000,
129
-
130
- // how often to check (in ms) that WS connection is still alive
131
- // pingInterval: 10000,
132
-
133
- // how long to wait before attempting to reconnect (in ms) after connection is closed
134
- // reconnectTimeout: 500,
135
-
136
- // config options sent to RestClient (used for time sync). See RestClient docs.
137
- // restOptions: { },
138
-
139
- // config for axios used for HTTP requests. E.g for proxy support
140
- // requestOptions: { }
141
-
142
- // override which URL to use for websocket connections
143
- // wsUrl: 'wss://stream.bytick.com/realtime'
144
- };
145
-
146
- const ws = new WebsocketClient(wsConfig);
147
-
148
- // subscribe to multiple topics at once
149
- ws.subscribe(['position', 'execution', 'trade']);
150
-
151
- // and/or subscribe to individual topics on demand
152
- ws.subscribe('kline.BTCUSD.1m');
153
-
154
- // Listen to events coming from websockets. This is the primary data source
155
- ws.on('update', data => {
156
- console.log('update', data);
157
- });
158
-
159
- // Optional: Listen to websocket connection open event (automatic after subscribing to one or more topics)
160
- ws.on('open', ({ wsKey, event }) => {
161
- console.log('connection open for websocket with ID: ' + wsKey);
162
- });
163
-
164
- // Optional: Listen to responses to websocket queries (e.g. the response after subscribing to a topic)
165
- ws.on('response', response => {
166
- console.log('response', response);
167
- });
168
-
169
- // Optional: Listen to connection close event. Unexpected connection closes are automatically reconnected.
170
- ws.on('close', () => {
171
- console.log('connection closed');
172
- });
173
-
174
- // Optional: Listen to raw error events.
175
- // Note: responses to invalid topics are currently only sent in the "response" event.
176
- ws.on('error', err => {
177
- console.error('ERR', err);
178
- });
179
- ```
180
-
181
-
182
- See [websocket-client.ts](./src/websocket-client.ts) for further information.
183
-
184
- 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.
121
+ For more examples, including how to use websockets with bitget, check the [examples](./examples/) and [test](./test/) folders.
185
122
 
186
123
  ---
187
124
 
@@ -195,7 +132,11 @@ const { WebsocketClient, DefaultLogger } = require('bitget-api');
195
132
  DefaultLogger.silly = () => {};
196
133
 
197
134
  const ws = new WebsocketClient(
198
- { key: 'xxx', secret: 'yyy' },
135
+ {
136
+ apiKey: 'API_KEY',
137
+ apiSecret: 'API_SECRET',
138
+ apiPass: 'API_PASS',
139
+ },
199
140
  DefaultLogger
200
141
  );
201
142
  ```
@@ -216,7 +157,7 @@ The bundle can be found in `dist/`. Altough usage should be largely consistent,
216
157
  Support my efforts to make algo trading accessible to all - register with my referral links:
217
158
  - [Bybit](https://www.bybit.com/en-US/register?affiliate_id=9410&language=en-US&group_id=0&group_type=1)
218
159
  - [Binance](https://www.binance.com/en/register?ref=20983262)
219
- - [bitget](https://www.bitget.com/join/18504944)
160
+ - [Bitget](https://www.bitget.com/join/18504944)
220
161
  - [FTX](https://ftx.com/referrals#a=ftxapigithub)
221
162
 
222
163
  Or buy me a coffee using any of these:
@@ -225,3 +166,7 @@ Or buy me a coffee using any of these:
225
166
 
226
167
  ### Contributions & Pull Requests
227
168
  Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
169
+
170
+ ## Star History
171
+
172
+ [![Star History Chart](https://api.star-history.com/svg?repos=tiagosiebler/bitget-api,tiagosiebler/bybit-api,tiagosiebler/binance,tiagosiebler/orderbooks,tiagosiebler/okx-api,tiagosiebler/awesome-crypto-examples,tiagosiebler/ftx-api&type=Date)](https://star-history.com/#tiagosiebler/bitget-api&tiagosiebler/bybit-api&tiagosiebler/binance&tiagosiebler/orderbooks&tiagosiebler/okx-api&tiagosiebler/awesome-crypto-examples&tiagosiebler/ftx-api&Date)
@@ -0,0 +1,46 @@
1
+ import { APIResponse, BrokerProductType, BrokerSubWithdrawalRequest, BrokerSubAPIKeyModifyRequest, BrokerSubListRequest } from './types';
2
+ import BaseRestClient from './util/BaseRestClient';
3
+ /**
4
+ * REST API client for broker APIs
5
+ */
6
+ export declare class BrokerClient extends BaseRestClient {
7
+ getClientType(): "broker";
8
+ /**
9
+ *
10
+ * Sub Account Interface
11
+ *
12
+ */
13
+ /** Get Broker Info */
14
+ getBrokerInfo(): Promise<APIResponse<any>>;
15
+ /** Create Sub Account */
16
+ createSubAccount(subName: string, remark?: string): Promise<APIResponse<any>>;
17
+ /** Get Sub List */
18
+ getSubAccounts(params?: BrokerSubListRequest): Promise<APIResponse<any>>;
19
+ /** Modify Sub Account */
20
+ modifySubAccount(subUid: string, perm: string, status: 'normal' | 'freeze' | 'del'): Promise<APIResponse<any>>;
21
+ /** Modify Sub Email */
22
+ modifySubEmail(subUid: string, subEmail: string): Promise<APIResponse<any>>;
23
+ /** Get Sub Email */
24
+ getSubEmail(subUid: string): Promise<APIResponse<any>>;
25
+ /** Get Sub Spot Assets */
26
+ getSubSpotAssets(subUid: string): Promise<APIResponse<any>>;
27
+ /** Get Sub Future Assets */
28
+ getSubFutureAssets(subUid: string, productType: BrokerProductType): Promise<APIResponse<any>>;
29
+ /** Get Sub Deposit Address (Only Broker) */
30
+ getSubDepositAddress(subUid: string, coin: string, chain?: string): Promise<APIResponse<any>>;
31
+ /** Sub Withdrawal (Only Broker) */
32
+ subWithdrawal(params: BrokerSubWithdrawalRequest): Promise<APIResponse<any>>;
33
+ /** Sub Deposit Auto Transfer (Only Broker) */
34
+ setSubDepositAutoTransfer(subUid: string, coin: string, toAccountType: 'spot' | 'mix_usdt' | 'mix_usd' | 'mix_usdc'): Promise<APIResponse<any>>;
35
+ /**
36
+ *
37
+ * Sub API Interface
38
+ *
39
+ */
40
+ /** Create Sub ApiKey (Only Broker) */
41
+ createSubAPIKey(subUid: string, passphrase: string, remark: string, ip: string, perm?: string): Promise<APIResponse<any>>;
42
+ /** Get Sub ApiKey List */
43
+ getSubAPIKeys(subUid: string): Promise<APIResponse<any>>;
44
+ /** Modify Sub ApiKey (Only Broker) */
45
+ modifySubAPIKey(params: BrokerSubAPIKeyModifyRequest): Promise<APIResponse<any>>;
46
+ }
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BrokerClient = void 0;
7
+ const util_1 = require("./util");
8
+ const BaseRestClient_1 = __importDefault(require("./util/BaseRestClient"));
9
+ /**
10
+ * REST API client for broker APIs
11
+ */
12
+ class BrokerClient extends BaseRestClient_1.default {
13
+ getClientType() {
14
+ return util_1.REST_CLIENT_TYPE_ENUM.broker;
15
+ }
16
+ /**
17
+ *
18
+ * Sub Account Interface
19
+ *
20
+ */
21
+ /** Get Broker Info */
22
+ getBrokerInfo() {
23
+ return this.getPrivate('/api/broker/v1/account/info');
24
+ }
25
+ /** Create Sub Account */
26
+ createSubAccount(subName, remark) {
27
+ return this.postPrivate('/api/broker/v1/account/sub-create', {
28
+ subName,
29
+ remark,
30
+ });
31
+ }
32
+ /** Get Sub List */
33
+ getSubAccounts(params) {
34
+ return this.getPrivate('/api/broker/v1/account/sub-list', params);
35
+ }
36
+ /** Modify Sub Account */
37
+ modifySubAccount(subUid, perm, status) {
38
+ return this.postPrivate('/api/broker/v1/account/sub-modify', {
39
+ subUid,
40
+ perm,
41
+ status,
42
+ });
43
+ }
44
+ /** Modify Sub Email */
45
+ modifySubEmail(subUid, subEmail) {
46
+ return this.postPrivate('/api/broker/v1/account/sub-modify-email', {
47
+ subUid,
48
+ subEmail,
49
+ });
50
+ }
51
+ /** Get Sub Email */
52
+ getSubEmail(subUid) {
53
+ return this.getPrivate('/api/broker/v1/account/sub-email', { subUid });
54
+ }
55
+ /** Get Sub Spot Assets */
56
+ getSubSpotAssets(subUid) {
57
+ return this.getPrivate('/api/broker/v1/account/sub-spot-assets', {
58
+ subUid,
59
+ });
60
+ }
61
+ /** Get Sub Future Assets */
62
+ getSubFutureAssets(subUid, productType) {
63
+ return this.getPrivate('/api/broker/v1/account/sub-future-assets', {
64
+ subUid,
65
+ productType,
66
+ });
67
+ }
68
+ /** Get Sub Deposit Address (Only Broker) */
69
+ getSubDepositAddress(subUid, coin, chain) {
70
+ return this.postPrivate('/api/broker/v1/account/sub-address', {
71
+ subUid,
72
+ coin,
73
+ chain,
74
+ });
75
+ }
76
+ /** Sub Withdrawal (Only Broker) */
77
+ subWithdrawal(params) {
78
+ return this.postPrivate('/api/broker/v1/account/sub-withdrawal', params);
79
+ }
80
+ /** Sub Deposit Auto Transfer (Only Broker) */
81
+ setSubDepositAutoTransfer(subUid, coin, toAccountType) {
82
+ return this.postPrivate('/api/broker/v1/account/sub-auto-transfer', {
83
+ subUid,
84
+ coin,
85
+ toAccountType,
86
+ });
87
+ }
88
+ /**
89
+ *
90
+ * Sub API Interface
91
+ *
92
+ */
93
+ /** Create Sub ApiKey (Only Broker) */
94
+ createSubAPIKey(subUid, passphrase, remark, ip, perm) {
95
+ return this.postPrivate('/api/broker/v1/manage/sub-api-create', {
96
+ subUid,
97
+ passphrase,
98
+ remark,
99
+ ip,
100
+ perm,
101
+ });
102
+ }
103
+ /** Get Sub ApiKey List */
104
+ getSubAPIKeys(subUid) {
105
+ return this.getPrivate('/api/broker/v1/manage/sub-api-list', { subUid });
106
+ }
107
+ /** Modify Sub ApiKey (Only Broker) */
108
+ modifySubAPIKey(params) {
109
+ return this.postPrivate('/api/broker/v1/manage/sub-api-modify', params);
110
+ }
111
+ }
112
+ exports.BrokerClient = BrokerClient;
113
+ //# sourceMappingURL=broker-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-client.js","sourceRoot":"","sources":["../src/broker-client.ts"],"names":[],"mappings":";;;;;;AAOA,iCAA+C;AAC/C,2EAAmD;AAEnD;;GAEG;AACH,MAAa,YAAa,SAAQ,wBAAc;IAC9C,aAAa;QACX,OAAO,4BAAqB,CAAC,MAAM,CAAC;IACtC,CAAC;IAED;;;;OAIG;IAEH,sBAAsB;IACtB,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,6BAA6B,CAAC,CAAC;IACxD,CAAC;IAED,yBAAyB;IACzB,gBAAgB,CACd,OAAe,EACf,MAAe;QAEf,OAAO,IAAI,CAAC,WAAW,CAAC,mCAAmC,EAAE;YAC3D,OAAO;YACP,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB;IACnB,cAAc,CAAC,MAA6B;QAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,iCAAiC,EAAE,MAAM,CAAC,CAAC;IACpE,CAAC;IAED,yBAAyB;IACzB,gBAAgB,CACd,MAAc,EACd,IAAY,EACZ,MAAmC;QAEnC,OAAO,IAAI,CAAC,WAAW,CAAC,mCAAmC,EAAE;YAC3D,MAAM;YACN,IAAI;YACJ,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,uBAAuB;IACvB,cAAc,CAAC,MAAc,EAAE,QAAgB;QAC7C,OAAO,IAAI,CAAC,WAAW,CAAC,yCAAyC,EAAE;YACjE,MAAM;YACN,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAED,oBAAoB;IACpB,WAAW,CAAC,MAAc;QACxB,OAAO,IAAI,CAAC,UAAU,CAAC,kCAAkC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,0BAA0B;IAC1B,gBAAgB,CAAC,MAAc;QAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,wCAAwC,EAAE;YAC/D,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,4BAA4B;IAC5B,kBAAkB,CAChB,MAAc,EACd,WAA8B;QAE9B,OAAO,IAAI,CAAC,UAAU,CAAC,0CAA0C,EAAE;YACjE,MAAM;YACN,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;IAED,4CAA4C;IAC5C,oBAAoB,CAClB,MAAc,EACd,IAAY,EACZ,KAAc;QAEd,OAAO,IAAI,CAAC,WAAW,CAAC,oCAAoC,EAAE;YAC5D,MAAM;YACN,IAAI;YACJ,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED,mCAAmC;IACnC,aAAa,CAAC,MAAkC;QAC9C,OAAO,IAAI,CAAC,WAAW,CAAC,uCAAuC,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC;IAED,8CAA8C;IAC9C,yBAAyB,CACvB,MAAc,EACd,IAAY,EACZ,aAA2D;QAE3D,OAAO,IAAI,CAAC,WAAW,CAAC,0CAA0C,EAAE;YAClE,MAAM;YACN,IAAI;YACJ,aAAa;SACd,CAAC,CAAC;IACL,CAAC;IAED;;;;OAIG;IAEH,sCAAsC;IACtC,eAAe,CACb,MAAc,EACd,UAAkB,EAClB,MAAc,EACd,EAAU,EACV,IAAa;QAEb,OAAO,IAAI,CAAC,WAAW,CAAC,sCAAsC,EAAE;YAC9D,MAAM;YACN,UAAU;YACV,MAAM;YACN,EAAE;YACF,IAAI;SACL,CAAC,CAAC;IACL,CAAC;IAED,0BAA0B;IAC1B,aAAa,CAAC,MAAc;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,oCAAoC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,sCAAsC;IACtC,eAAe,CACb,MAAoC;QAEpC,OAAO,IAAI,CAAC,WAAW,CAAC,sCAAsC,EAAE,MAAM,CAAC,CAAC;IAC1E,CAAC;CACF;AA7ID,oCA6IC"}
@@ -0,0 +1,17 @@
1
+ export declare const API_ERROR_CODE: {
2
+ readonly SUCCESS: "00000";
3
+ readonly INCORRECT_PERMISSIONS: "40014";
4
+ readonly ACCOUNT_NOT_COPY_TRADER: "40017";
5
+ readonly FUTURES_POSITION_DIRECTION_EMPTY: "40017";
6
+ readonly ACCOUNT_NOT_BROKER: "40029";
7
+ readonly FUTURES_ORDER_GET_NOT_FOUND: "40109";
8
+ readonly SERVICE_RETURNED_ERROR: "40725";
9
+ readonly INSUFFICIENT_BALANCE: "40754";
10
+ readonly FUTURES_ORDER_CANCEL_NOT_FOUND: "40768";
11
+ readonly QTY_LESS_THAN_MINIMUM: "43006";
12
+ /** Parameter verification exception margin mode == FIXED */
13
+ readonly PARAMETER_EXCEPTION: "40808";
14
+ readonly ORDER_NOT_FOUND: "43001";
15
+ readonly FUTURES_ORDER_TPSL_NOT_FOUND: "43020";
16
+ readonly PLAN_ORDER_NOT_FOUND: "43025";
17
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.API_ERROR_CODE = void 0;
4
+ exports.API_ERROR_CODE = {
5
+ SUCCESS: '00000',
6
+ INCORRECT_PERMISSIONS: '40014',
7
+ ACCOUNT_NOT_COPY_TRADER: '40017',
8
+ FUTURES_POSITION_DIRECTION_EMPTY: '40017',
9
+ ACCOUNT_NOT_BROKER: '40029',
10
+ FUTURES_ORDER_GET_NOT_FOUND: '40109',
11
+ SERVICE_RETURNED_ERROR: '40725',
12
+ INSUFFICIENT_BALANCE: '40754',
13
+ FUTURES_ORDER_CANCEL_NOT_FOUND: '40768',
14
+ QTY_LESS_THAN_MINIMUM: '43006',
15
+ /** Parameter verification exception margin mode == FIXED */
16
+ PARAMETER_EXCEPTION: '40808',
17
+ ORDER_NOT_FOUND: '43001',
18
+ FUTURES_ORDER_TPSL_NOT_FOUND: '43020',
19
+ PLAN_ORDER_NOT_FOUND: '43025',
20
+ };
21
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/constants/enum.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG;IAC5B,OAAO,EAAE,OAAO;IAChB,qBAAqB,EAAE,OAAO;IAC9B,uBAAuB,EAAE,OAAO;IAChC,gCAAgC,EAAE,OAAO;IACzC,kBAAkB,EAAE,OAAO;IAC3B,2BAA2B,EAAE,OAAO;IACpC,sBAAsB,EAAE,OAAO;IAC/B,oBAAoB,EAAE,OAAO;IAC7B,8BAA8B,EAAE,OAAO;IACvC,qBAAqB,EAAE,OAAO;IAC9B,4DAA4D;IAC5D,mBAAmB,EAAE,OAAO;IAC5B,eAAe,EAAE,OAAO;IACxB,4BAA4B,EAAE,OAAO;IACrC,oBAAoB,EAAE,OAAO;CACrB,CAAC"}
@@ -0,0 +1,146 @@
1
+ import { APIResponse, KlineInterval, FuturesProductType, FuturesAccountBillRequest, FuturesBusinessBillRequest, NewFuturesOrder, NewBatchFuturesOrder, FuturesPagination, NewFuturesPlanOrder, ModifyFuturesPlanOrder, ModifyFuturesPlanOrderTPSL, NewFuturesPlanPositionTPSL, ModifyFuturesPlanStopOrder, CancelFuturesPlanTPSL, HistoricPlanOrderTPSLRequest, NewFuturesPlanStopOrder, FuturesAccount, FuturesSymbolRule, FuturesMarginMode, FuturesPosition } from './types';
2
+ import BaseRestClient from './util/BaseRestClient';
3
+ /**
4
+ * REST API client
5
+ */
6
+ export declare class FuturesClient extends BaseRestClient {
7
+ getClientType(): "futures";
8
+ /**
9
+ *
10
+ * Market
11
+ *
12
+ */
13
+ /** Get Symbols : Get basic configuration information of all trading pairs (including rules) */
14
+ getSymbols(productType: FuturesProductType): Promise<APIResponse<FuturesSymbolRule[]>>;
15
+ /** Get Depth */
16
+ getDepth(symbol: string, limit?: string): Promise<APIResponse<any>>;
17
+ /** Get Single Symbol Ticker */
18
+ getTicker(symbol: string): Promise<APIResponse<any>>;
19
+ /** Get All Tickers */
20
+ getAllTickers(productType: FuturesProductType): Promise<APIResponse<any>>;
21
+ /** Get Market Trades */
22
+ getMarketTrades(symbol: string, limit?: string): Promise<APIResponse<any>>;
23
+ /** Get Candle Data */
24
+ getCandles(symbol: string, granularity: KlineInterval, startTime: string, endTime: string): Promise<any>;
25
+ /** Get symbol index price */
26
+ getIndexPrice(symbol: string): Promise<APIResponse<any>>;
27
+ /** Get symbol next funding time */
28
+ getNextFundingTime(symbol: string): Promise<APIResponse<any>>;
29
+ /** Get Withdraw List */
30
+ getHistoricFundingRate(symbol: string, pageSize?: string, pageNo?: string, nextPage?: boolean): Promise<APIResponse<any>>;
31
+ /** Get symbol current funding time */
32
+ getCurrentFundingRate(symbol: string): Promise<APIResponse<any>>;
33
+ /** Get symbol open interest */
34
+ getOpenInterest(symbol: string): Promise<APIResponse<any>>;
35
+ /** Get symbol mark price */
36
+ getMarkPrice(symbol: string): Promise<APIResponse<any>>;
37
+ /** Get symbol min/max leverage rules */
38
+ getLeverageMinMax(symbol: string): Promise<APIResponse<any>>;
39
+ /**
40
+ *
41
+ * Account Endpoints
42
+ *
43
+ */
44
+ /** Get Single Account */
45
+ getAccount(symbol: string, marginCoin: string): Promise<APIResponse<FuturesAccount>>;
46
+ /** Get Account List */
47
+ getAccounts(productType: FuturesProductType): Promise<APIResponse<any>>;
48
+ /**
49
+ * This interface is only used to calculate the maximum number of positions that can be opened when the user does not hold a position by default.
50
+ * The result does not represent the actual number of positions opened.
51
+ */
52
+ getOpenCount(symbol: string, marginCoin: string, openPrice: number, openAmount: number, leverage?: number): Promise<APIResponse<any>>;
53
+ /** Change Leverage */
54
+ setLeverage(symbol: string, marginCoin: string, leverage: string, holdSide?: string): Promise<APIResponse<any>>;
55
+ /** Change Margin */
56
+ setMargin(symbol: string, marginCoin: string, amount: string, holdSide?: string): Promise<APIResponse<any>>;
57
+ /** Change Margin Mode */
58
+ setMarginMode(symbol: string, marginCoin: string, marginMode: FuturesMarginMode): Promise<APIResponse<any>>;
59
+ /** Get Symbol Position */
60
+ getPosition(symbol: string, marginCoin?: string): Promise<APIResponse<FuturesPosition[]>>;
61
+ /** Get All Position */
62
+ getPositions(productType: FuturesProductType, marginCoin?: string): Promise<APIResponse<FuturesPosition[]>>;
63
+ /** Get Account Bill */
64
+ getAccountBill(params: FuturesAccountBillRequest): Promise<APIResponse<any>>;
65
+ /** Get Business Account Bill */
66
+ getBusinessBill(params: FuturesBusinessBillRequest): Promise<APIResponse<any>>;
67
+ /**
68
+ *
69
+ * Trade Endpoints
70
+ *
71
+ */
72
+ /** Place Order */
73
+ submitOrder(params: NewFuturesOrder): Promise<APIResponse<any>>;
74
+ /** Batch Order */
75
+ batchSubmitOrder(symbol: string, marginCoin: string, orders: NewBatchFuturesOrder[]): Promise<APIResponse<any>>;
76
+ /** Cancel Order */
77
+ cancelOrder(symbol: string, marginCoin: string, orderId: string): Promise<APIResponse<any>>;
78
+ /** Batch Cancel Order */
79
+ batchCancelOrder(symbol: string, marginCoin: string, orderIds: string[]): Promise<APIResponse<any>>;
80
+ /** Cancel All Order */
81
+ cancelAllOrders(productType: FuturesProductType, marginCoin: string): Promise<APIResponse<any>>;
82
+ /** Get Open Order */
83
+ getOpenSymbolOrders(symbol: string): Promise<APIResponse<any>>;
84
+ /** Get All Open Order */
85
+ getOpenOrders(productType: FuturesProductType, marginCoin: string): Promise<APIResponse<any>>;
86
+ /** Get History Orders */
87
+ getOrderHistory(symbol: string, startTime: string, endTime: string, pageSize: string, lastEndId?: string, isPre?: boolean): Promise<APIResponse<any>>;
88
+ /** Get ProductType History Orders */
89
+ getProductTypeOrderHistory(productType: FuturesProductType, startTime: string, endTime: string, pageSize: string, lastEndId?: string, isPre?: boolean): Promise<APIResponse<any>>;
90
+ /** Get order details */
91
+ getOrder(symbol: string, orderId?: string, clientOid?: string): Promise<APIResponse<any>>;
92
+ /** Get transaction details / history (fills) */
93
+ getOrderFills(symbol: string, orderId?: string, pagination?: FuturesPagination): Promise<APIResponse<any>>;
94
+ /** Get ProductType Order fill detail */
95
+ getProductTypeOrderFills(productType: FuturesProductType, pagination?: FuturesPagination): Promise<APIResponse<any>>;
96
+ /** Place Plan order */
97
+ submitPlanOrder(params: NewFuturesPlanOrder): Promise<APIResponse<any>>;
98
+ /** Modify Plan Order */
99
+ modifyPlanOrder(params: ModifyFuturesPlanOrder): Promise<APIResponse<any>>;
100
+ /** Modify Plan Order TPSL */
101
+ modifyPlanOrderTPSL(params: ModifyFuturesPlanOrderTPSL): Promise<APIResponse<any>>;
102
+ /** Place Stop order */
103
+ submitStopOrder(params: NewFuturesPlanStopOrder): Promise<APIResponse<any>>;
104
+ /** Place Position TPSL */
105
+ submitPositionTPSL(params: NewFuturesPlanPositionTPSL): Promise<APIResponse<any>>;
106
+ /** Modify Stop Order */
107
+ modifyStopOrder(params: ModifyFuturesPlanStopOrder): Promise<APIResponse<any>>;
108
+ /** Cancel Plan Order TPSL */
109
+ cancelPlanOrderTPSL(params: CancelFuturesPlanTPSL): Promise<APIResponse<any>>;
110
+ /** Get Plan Order (TPSL) List */
111
+ getPlanOrderTPSLs(symbol: string, isPlan?: string, productType?: FuturesProductType): Promise<APIResponse<any>>;
112
+ /** Get History Plan Orders (TPSL) */
113
+ getHistoricPlanOrdersTPSL(params: HistoricPlanOrderTPSLRequest): Promise<APIResponse<any>>;
114
+ /**
115
+ *
116
+ * Trade Endpoints
117
+ *
118
+ */
119
+ /** Get Trader Open order */
120
+ getCopyTraderOpenOrder(symbol: string, productType: FuturesProductType, pageSize: number, pageNo: number): Promise<APIResponse<any>>;
121
+ /** Get Followers Open Order */
122
+ getCopyFollowersOpenOrder(symbol: string, productType: FuturesProductType, pageSize: number, pageNo: number): Promise<APIResponse<any>>;
123
+ /** Trader Close Position */
124
+ closeCopyTraderPosition(symbol: string, trackingNo: string): Promise<APIResponse<any>>;
125
+ /** Trader Modify TPSL */
126
+ modifyCopyTraderTPSL(symbol: string, trackingNo: string, changes?: {
127
+ stopProfitPrice?: number;
128
+ stopLossPrice?: number;
129
+ }): Promise<APIResponse<any>>;
130
+ /** Get Traders History Orders */
131
+ getCopyTraderOrderHistory(startTime: string, endTime: string, pageSize: number, pageNo: number): Promise<APIResponse<any>>;
132
+ /** Get Trader Profit Summary */
133
+ getCopyTraderProfitSummary(): Promise<APIResponse<any>>;
134
+ /** Get Trader History Profit Summary (according to settlement currency) */
135
+ getCopyTraderHistoricProfitSummary(): Promise<APIResponse<any>>;
136
+ /** Get Trader History Profit Summary (according to settlement currency and date) */
137
+ getCopyTraderHistoricProfitSummaryByDate(marginCoin: string, dateMs: string, pageSize: number, pageNo: number): Promise<APIResponse<any>>;
138
+ /** Get Trader Histroy Profit Detail */
139
+ getCopyTraderHistoricProfitDetail(marginCoin: string, dateMs: string, pageSize: number, pageNo: number): Promise<APIResponse<any>>;
140
+ /** Get Trader Profits Details */
141
+ getCopyTraderProfitDetails(pageSize: number, pageNo: number): Promise<APIResponse<any>>;
142
+ /** Get CopyTrade Symbols */
143
+ getCopyTraderSymbols(): Promise<APIResponse<any>>;
144
+ /** Trader Change CopyTrade symbol */
145
+ setCopyTraderSymbols(symbol: string, operation: 'add' | 'delete'): Promise<APIResponse<any>>;
146
+ }