bitget-api 3.0.1 → 3.0.2
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.
- package/README.md +126 -13
- package/llms.txt +350 -237
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,24 +21,67 @@
|
|
|
21
21
|
|
|
22
22
|
Updated & performant JavaScript & Node.js SDK for the Bitget V2 REST APIs and WebSockets:
|
|
23
23
|
|
|
24
|
+
- Professional, robust & performant Bitget SDK with extensive production use in live trading environments.
|
|
24
25
|
- Complete integration with all Bitget APIs.
|
|
25
|
-
- [x] Supports V1 REST APIs & WebSockets
|
|
26
|
+
- [x] Supports V1 REST APIs & WebSockets (legacy)
|
|
26
27
|
- [x] Supports V2 REST APIs & WebSockets
|
|
27
|
-
- [x] Supports V3/UTA REST APIs & WebSockets
|
|
28
|
+
- [x] Supports V3/UTA REST APIs & WebSockets (latest)
|
|
28
29
|
- [x] Supports order placement via V3 WebSocket API
|
|
29
|
-
- TypeScript support (with type declarations for
|
|
30
|
+
- Complete TypeScript support (with type declarations for all API requests & responses).
|
|
31
|
+
- Strongly typed requests and responses.
|
|
32
|
+
- Automated end-to-end tests on most API calls, ensuring no breaking changes are released to npm.
|
|
33
|
+
- Actively maintained with a modern, promise-driven interface.
|
|
30
34
|
- Over 100 integration tests making real API calls & WebSocket connections, validating any changes before they reach npm.
|
|
31
35
|
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
|
|
36
|
+
- Event driven messaging.
|
|
37
|
+
- Smart WebSocket persistence with automatic reconnection handling.
|
|
38
|
+
- Emit `reconnected` event when dropped connection is restored.
|
|
39
|
+
- Optional beautification of WebSocket events for improved readability.
|
|
32
40
|
- Officially listed Node.js SDK in [Bitget API docs](https://bitgetlimited.github.io/apidoc/en/spot/#sdk-code-example).
|
|
33
41
|
- Browser support (via webpack bundle - see "Browser Usage" below).
|
|
34
42
|
- Support all authentication methods supported by Bitget:
|
|
35
43
|
- [x] HMAC
|
|
36
44
|
- [x] RSA
|
|
45
|
+
- Heavy automated end-to-end testing with real API calls.
|
|
46
|
+
- End-to-end testing before any release.
|
|
47
|
+
- Real API calls in e2e tests.
|
|
48
|
+
- Proxy support via axios integration.
|
|
49
|
+
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
|
|
50
|
+
|
|
51
|
+
## Table of Contents
|
|
52
|
+
|
|
53
|
+
- [Installation](#installation)
|
|
54
|
+
- [Examples](#examples)
|
|
55
|
+
- [Issues & Discussion](#issues--discussion)
|
|
56
|
+
- [Related Projects](#related-projects)
|
|
57
|
+
- [Documentation](#documentation)
|
|
58
|
+
- [Structure](#structure)
|
|
59
|
+
- [Usage](#usage)
|
|
60
|
+
- [REST API Clients](#rest-api-clients)
|
|
61
|
+
- [V3 REST APIs (Unified Trading Account)](#v3-rest-apis)
|
|
62
|
+
- [V2 REST APIs](#v2-rest-apis)
|
|
63
|
+
- [WebSockets](#websockets)
|
|
64
|
+
- [V3 Unified Trading Account](#v3-unified-trading-account)
|
|
65
|
+
- [Sending Orders via WebSockets](#sending-orders-via-websockets)
|
|
66
|
+
- [Receiving Realtime Data](#receiving-realtime-data)
|
|
67
|
+
- [V2 WebSockets](#v2-websockets)
|
|
68
|
+
- [Customise Logging](#logging)
|
|
69
|
+
- [Custom Logger](#customise-logging)
|
|
70
|
+
- [Debug HTTP Requests](#debug-http-requests)
|
|
71
|
+
- [Frontend Usage](#browser-usage)
|
|
72
|
+
- [Import](#import)
|
|
73
|
+
- [Webpack](#webpack)
|
|
74
|
+
- [LLMs & AI](#use-with-llms--ai)
|
|
75
|
+
- [Contributions & Thanks](#contributions--thanks)
|
|
37
76
|
|
|
38
77
|
## Installation
|
|
39
78
|
|
|
40
79
|
`npm install --save bitget-api`
|
|
41
80
|
|
|
81
|
+
## Examples
|
|
82
|
+
|
|
83
|
+
Refer to the [examples](./examples) folder for implementation demos.
|
|
84
|
+
|
|
42
85
|
## Issues & Discussion
|
|
43
86
|
|
|
44
87
|
- Issues? Check the [issues tab](https://github.com/tiagosiebler/bitget-api/issues).
|
|
@@ -69,11 +112,14 @@ Check out my related JavaScript/TypeScript/Node.js projects:
|
|
|
69
112
|
|
|
70
113
|
## Documentation
|
|
71
114
|
|
|
72
|
-
Most methods
|
|
115
|
+
Most methods accept JS objects. 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).
|
|
73
116
|
|
|
74
|
-
-
|
|
75
|
-
- [
|
|
117
|
+
- Bitget API Documentation
|
|
118
|
+
- [V3/UTA API Documentation](https://www.bitget.com/api-doc/uta/intro) (Latest - Unified Trading Account)
|
|
119
|
+
- [V2 API Documentation](https://www.bitget.com/api-doc/common/intro)
|
|
120
|
+
- [Legacy V1 API Documentation](https://bitgetlimited.github.io/apidoc/en/spot/#introduction) (deprecated)
|
|
76
121
|
- [REST Endpoint Function List](./docs/endpointFunctionList.md)
|
|
122
|
+
- [TSDoc Documentation (autogenerated using typedoc)](https://tsdocs.dev/docs/bitget-api)
|
|
77
123
|
|
|
78
124
|
## Structure
|
|
79
125
|
|
|
@@ -88,6 +134,13 @@ The version on npm is the output from the `build` command and can be used in pro
|
|
|
88
134
|
|
|
89
135
|
---
|
|
90
136
|
|
|
137
|
+
# Usage
|
|
138
|
+
|
|
139
|
+
Create API credentials at Bitget:
|
|
140
|
+
|
|
141
|
+
- [Livenet API Management](https://www.bitget.com/en/support/articles/360011132814-How-to-create-API)
|
|
142
|
+
- [Demo Trading Environment](https://www.bitget.com/en/demo-trading)
|
|
143
|
+
|
|
91
144
|
## REST API Clients
|
|
92
145
|
|
|
93
146
|
Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups:
|
|
@@ -110,12 +163,18 @@ Examples for using each client can be found in:
|
|
|
110
163
|
|
|
111
164
|
If you're missing an example, you're welcome to request one. Priority will be given to [github sponsors](https://github.com/sponsors/tiagosiebler).
|
|
112
165
|
|
|
113
|
-
###
|
|
114
|
-
|
|
115
|
-
First, create API credentials on Bitget's website.
|
|
166
|
+
### Getting Started
|
|
116
167
|
|
|
117
168
|
All REST APIs are integrated in each dedicated Rest Client class. See the above table for which REST client to use. If you've upgraded to the Unified Trading Account, you should use the V3 REST APIs and WebSockets.
|
|
118
169
|
|
|
170
|
+
There are several REST API modules as there are some differences in each API group:
|
|
171
|
+
|
|
172
|
+
1. `RestClientV3` for the latest V3/UTA APIs (Unified Trading Account) - recommended for new projects.
|
|
173
|
+
2. `RestClientV2` for V2 APIs - use if you haven't upgraded to UTA yet.
|
|
174
|
+
3. Legacy V1 clients (`SpotClient`, `FuturesClient`, `BrokerClient`) - deprecated, migrate to V2 or V3.
|
|
175
|
+
|
|
176
|
+
More Node.js & JavaScript examples for Bitget's REST APIs & WebSockets can be found in the [examples](./examples) folder on GitHub.
|
|
177
|
+
|
|
119
178
|
#### V3 REST APIs
|
|
120
179
|
|
|
121
180
|
These are only available if you have upgraded to the Unified Trading Account. If not, use the V2 APIs instead.
|
|
@@ -198,21 +257,30 @@ client
|
|
|
198
257
|
});
|
|
199
258
|
```
|
|
200
259
|
|
|
201
|
-
|
|
260
|
+
## WebSockets
|
|
202
261
|
|
|
203
262
|
All WebSocket functionality is supported via the WebsocketClient. Since there are currently 3 generations of Bitget's API, there are 3 WebsocketClient classes in this Node.js, JavaScript & TypeScript SDK for Bitget.
|
|
204
263
|
|
|
205
264
|
Use the following guidance to decide which one to use:
|
|
206
265
|
|
|
207
|
-
- Unified Trading Account / V3 (latest generation):
|
|
266
|
+
- **Unified Trading Account / V3** (latest generation):
|
|
208
267
|
- For receiving data, use the [WebsocketClientV3](./src/websocket-client-v3.ts).
|
|
209
268
|
- For sending orders via WebSockets, use the [WebsocketAPIClient](./src/websocket-api-client.ts).
|
|
210
|
-
- V2 (not upgraded to Unified Trading Account yet)
|
|
269
|
+
- **V2** (not upgraded to Unified Trading Account yet)
|
|
211
270
|
- Use the [WebsocketClientV2](./src/websocket-client-v2.ts).
|
|
212
|
-
- V1 (deprecated)
|
|
271
|
+
- **V1** (deprecated)
|
|
213
272
|
- This is the oldest API group supported by Bitget. You should migrate to V3 or V2 as soon as possible.
|
|
214
273
|
- If you're not ready to migrate, you can use the [WebsocketClientLegacyV1](./src/websocket-client-legacy-v1.ts) class in the meantime.
|
|
215
274
|
|
|
275
|
+
All WebSocket clients support:
|
|
276
|
+
|
|
277
|
+
- Event driven messaging
|
|
278
|
+
- Smart WebSocket persistence with automatic reconnection
|
|
279
|
+
- Heartbeat mechanisms to detect disconnections
|
|
280
|
+
- Automatic resubscription after reconnection
|
|
281
|
+
- Error handling and connection monitoring
|
|
282
|
+
- Optional data beautification
|
|
283
|
+
|
|
216
284
|
Higher level examples below, while more thorough examples can be found in the examples folder on GitHub.
|
|
217
285
|
|
|
218
286
|
##### V3 Unified Trading Account
|
|
@@ -407,6 +475,51 @@ wsClient.subscribe(
|
|
|
407
475
|
|
|
408
476
|
For more examples, including how to use websockets with Bitget, check the [examples](./examples/) and [test](./test/) folders.
|
|
409
477
|
|
|
478
|
+
### V2 WebSockets
|
|
479
|
+
|
|
480
|
+
If you haven't upgraded to the Unified Trading Account, use the V2 WebSocket client:
|
|
481
|
+
|
|
482
|
+
```javascript
|
|
483
|
+
import { WebsocketClientV2 } from 'bitget-api';
|
|
484
|
+
// or if you prefer require:
|
|
485
|
+
// const { WebsocketClientV2 } = require('bitget-api');
|
|
486
|
+
|
|
487
|
+
const API_KEY = 'xxx';
|
|
488
|
+
const API_SECRET = 'yyy';
|
|
489
|
+
const API_PASS = 'zzz';
|
|
490
|
+
|
|
491
|
+
const wsClient = new WebsocketClientV2({
|
|
492
|
+
apiKey: API_KEY,
|
|
493
|
+
apiSecret: API_SECRET,
|
|
494
|
+
apiPass: API_PASS,
|
|
495
|
+
// Optional: connect to demo trading environment
|
|
496
|
+
// demoTrading: true,
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
// Handle incoming messages
|
|
500
|
+
wsClient.on('update', (data) => {
|
|
501
|
+
console.log('WS update received: ', data);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
wsClient.on('open', (data) => {
|
|
505
|
+
console.log('WS connection opened: ', data.wsKey);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
wsClient.on('reconnected', (data) => {
|
|
509
|
+
console.log('WS reconnected: ', data?.wsKey);
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
wsClient.on('exception', (data) => {
|
|
513
|
+
console.log('WS error: ', data);
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
// Subscribe to public data streams
|
|
517
|
+
wsClient.subscribeTopic('SPOT', 'ticker', symbol);
|
|
518
|
+
|
|
519
|
+
// Subscribe to private data streams (requires authentication)
|
|
520
|
+
wsClient.subscribeTopic('SPOT', 'account');
|
|
521
|
+
```
|
|
522
|
+
|
|
410
523
|
---
|
|
411
524
|
|
|
412
525
|
## Logging
|
package/llms.txt
CHANGED
|
@@ -4014,41 +4014,6 @@ export interface SpotDepositRecordV2 {
|
|
|
4014
4014
|
uTime: string;
|
|
4015
4015
|
}
|
|
4016
4016
|
|
|
4017
|
-
================
|
|
4018
|
-
File: .gitignore
|
|
4019
|
-
================
|
|
4020
|
-
!.gitkeep
|
|
4021
|
-
.DS_STORE
|
|
4022
|
-
*.log
|
|
4023
|
-
npm-debug.log*
|
|
4024
|
-
yarn-debug.log*
|
|
4025
|
-
yarn-error.log*
|
|
4026
|
-
lerna-debug.log*
|
|
4027
|
-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
4028
|
-
pids
|
|
4029
|
-
*.pid
|
|
4030
|
-
*.seed
|
|
4031
|
-
*.pid.lock
|
|
4032
|
-
node_modules/
|
|
4033
|
-
.npm
|
|
4034
|
-
.eslintcache
|
|
4035
|
-
.node_repl_history
|
|
4036
|
-
*.tgz
|
|
4037
|
-
.yarn-integrity
|
|
4038
|
-
.env
|
|
4039
|
-
.env.test
|
|
4040
|
-
.cache
|
|
4041
|
-
lib
|
|
4042
|
-
bundleReport.html
|
|
4043
|
-
.history/
|
|
4044
|
-
tiagoSpot.ts
|
|
4045
|
-
restClientRegex.ts
|
|
4046
|
-
localtest.sh
|
|
4047
|
-
privaterepotracker
|
|
4048
|
-
testfile.ts
|
|
4049
|
-
dist
|
|
4050
|
-
repomix.sh
|
|
4051
|
-
|
|
4052
4017
|
================
|
|
4053
4018
|
File: .jshintrc
|
|
4054
4019
|
================
|
|
@@ -6751,6 +6716,41 @@ new BundleAnalyzerPlugin({
|
|
|
6751
6716
|
⋮----
|
|
6752
6717
|
module.exports = generateConfig('bitgetapi');
|
|
6753
6718
|
|
|
6719
|
+
================
|
|
6720
|
+
File: .gitignore
|
|
6721
|
+
================
|
|
6722
|
+
!.gitkeep
|
|
6723
|
+
.DS_STORE
|
|
6724
|
+
*.log
|
|
6725
|
+
npm-debug.log*
|
|
6726
|
+
yarn-debug.log*
|
|
6727
|
+
yarn-error.log*
|
|
6728
|
+
lerna-debug.log*
|
|
6729
|
+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
6730
|
+
pids
|
|
6731
|
+
*.pid
|
|
6732
|
+
*.seed
|
|
6733
|
+
*.pid.lock
|
|
6734
|
+
node_modules/
|
|
6735
|
+
.npm
|
|
6736
|
+
.eslintcache
|
|
6737
|
+
.node_repl_history
|
|
6738
|
+
*.tgz
|
|
6739
|
+
.yarn-integrity
|
|
6740
|
+
.env
|
|
6741
|
+
.env.test
|
|
6742
|
+
.cache
|
|
6743
|
+
lib
|
|
6744
|
+
bundleReport.html
|
|
6745
|
+
.history/
|
|
6746
|
+
tiagoSpot.ts
|
|
6747
|
+
restClientRegex.ts
|
|
6748
|
+
localtest.sh
|
|
6749
|
+
privaterepotracker
|
|
6750
|
+
testfile.ts
|
|
6751
|
+
dist
|
|
6752
|
+
repomix.sh
|
|
6753
|
+
|
|
6754
6754
|
================
|
|
6755
6755
|
File: .nvmrc
|
|
6756
6756
|
================
|
|
@@ -8074,6 +8074,194 @@ export interface WSAPIPlaceOrderRequestV3 {
|
|
|
8074
8074
|
⋮----
|
|
8075
8075
|
reduceOnly?: 'YES' | 'NO'; // Note: reduceOnly is not supported for batch place WS API. Might be supported starting late Q4 2025, but not supported yet.
|
|
8076
8076
|
|
|
8077
|
+
================
|
|
8078
|
+
File: src/broker-client.ts
|
|
8079
|
+
================
|
|
8080
|
+
import {
|
|
8081
|
+
BrokerProductType,
|
|
8082
|
+
BrokerSubAPIKeyModifyRequest,
|
|
8083
|
+
BrokerSubListRequest,
|
|
8084
|
+
BrokerSubWithdrawalRequest,
|
|
8085
|
+
} from './types/request/v1/brokerV1.js';
|
|
8086
|
+
import { APIResponse } from './types/response/v1/shared.js';
|
|
8087
|
+
import BaseRestClient from './util/BaseRestClient.js';
|
|
8088
|
+
import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils.js';
|
|
8089
|
+
⋮----
|
|
8090
|
+
/**
|
|
8091
|
+
* REST API client for the V1 bitget Broker APIs. These are the previous generation of Bitget's APIs and should be considered deprecated.
|
|
8092
|
+
* These will be removed in a future release, once Bitget formally deprecates them.
|
|
8093
|
+
*
|
|
8094
|
+
* @deprecated use RestClientV2 instead
|
|
8095
|
+
*/
|
|
8096
|
+
export class BrokerClient extends BaseRestClient
|
|
8097
|
+
⋮----
|
|
8098
|
+
getClientType()
|
|
8099
|
+
⋮----
|
|
8100
|
+
/**
|
|
8101
|
+
*
|
|
8102
|
+
* Sub Account Interface
|
|
8103
|
+
*
|
|
8104
|
+
*/
|
|
8105
|
+
⋮----
|
|
8106
|
+
/** Get Broker Info */
|
|
8107
|
+
getBrokerInfo(): Promise<APIResponse<any>>
|
|
8108
|
+
⋮----
|
|
8109
|
+
/** Create Sub Account */
|
|
8110
|
+
createSubAccount(
|
|
8111
|
+
subName: string,
|
|
8112
|
+
remark?: string,
|
|
8113
|
+
): Promise<APIResponse<any>>
|
|
8114
|
+
⋮----
|
|
8115
|
+
/** Get Sub List */
|
|
8116
|
+
getSubAccounts(params?: BrokerSubListRequest): Promise<APIResponse<any>>
|
|
8117
|
+
⋮----
|
|
8118
|
+
/** Modify Sub Account */
|
|
8119
|
+
modifySubAccount(
|
|
8120
|
+
subUid: string,
|
|
8121
|
+
perm: string,
|
|
8122
|
+
status: 'normal' | 'freeze' | 'del',
|
|
8123
|
+
): Promise<APIResponse<any>>
|
|
8124
|
+
⋮----
|
|
8125
|
+
/** Modify Sub Email */
|
|
8126
|
+
modifySubEmail(subUid: string, subEmail: string): Promise<APIResponse<any>>
|
|
8127
|
+
⋮----
|
|
8128
|
+
/** Get Sub Email */
|
|
8129
|
+
getSubEmail(subUid: string): Promise<APIResponse<any>>
|
|
8130
|
+
⋮----
|
|
8131
|
+
/** Get Sub Spot Assets */
|
|
8132
|
+
getSubSpotAssets(subUid: string): Promise<APIResponse<any>>
|
|
8133
|
+
⋮----
|
|
8134
|
+
/** Get Sub Future Assets */
|
|
8135
|
+
getSubFutureAssets(
|
|
8136
|
+
subUid: string,
|
|
8137
|
+
productType: BrokerProductType,
|
|
8138
|
+
): Promise<APIResponse<any>>
|
|
8139
|
+
⋮----
|
|
8140
|
+
/** Get Sub Deposit Address (Only Broker) */
|
|
8141
|
+
getSubDepositAddress(
|
|
8142
|
+
subUid: string,
|
|
8143
|
+
coin: string,
|
|
8144
|
+
chain?: string,
|
|
8145
|
+
): Promise<APIResponse<any>>
|
|
8146
|
+
⋮----
|
|
8147
|
+
/** Sub Withdrawal (Only Broker) */
|
|
8148
|
+
subWithdrawal(params: BrokerSubWithdrawalRequest): Promise<APIResponse<any>>
|
|
8149
|
+
⋮----
|
|
8150
|
+
/** Sub Deposit Auto Transfer (Only Broker) */
|
|
8151
|
+
setSubDepositAutoTransfer(
|
|
8152
|
+
subUid: string,
|
|
8153
|
+
coin: string,
|
|
8154
|
+
toAccountType: 'spot' | 'mix_usdt' | 'mix_usd' | 'mix_usdc',
|
|
8155
|
+
): Promise<APIResponse<any>>
|
|
8156
|
+
⋮----
|
|
8157
|
+
/**
|
|
8158
|
+
*
|
|
8159
|
+
* Sub API Interface
|
|
8160
|
+
*
|
|
8161
|
+
*/
|
|
8162
|
+
⋮----
|
|
8163
|
+
/** Create Sub ApiKey (Only Broker) */
|
|
8164
|
+
createSubAPIKey(
|
|
8165
|
+
subUid: string,
|
|
8166
|
+
passphrase: string,
|
|
8167
|
+
remark: string,
|
|
8168
|
+
ip: string,
|
|
8169
|
+
perm?: string,
|
|
8170
|
+
): Promise<APIResponse<any>>
|
|
8171
|
+
⋮----
|
|
8172
|
+
/** Get Sub ApiKey List */
|
|
8173
|
+
getSubAPIKeys(subUid: string): Promise<APIResponse<any>>
|
|
8174
|
+
⋮----
|
|
8175
|
+
/** Modify Sub ApiKey (Only Broker) */
|
|
8176
|
+
modifySubAPIKey(
|
|
8177
|
+
params: BrokerSubAPIKeyModifyRequest,
|
|
8178
|
+
): Promise<APIResponse<any>>
|
|
8179
|
+
⋮----
|
|
8180
|
+
/**
|
|
8181
|
+
* Undocumented endpoints
|
|
8182
|
+
*/
|
|
8183
|
+
⋮----
|
|
8184
|
+
getAgentCommissionDetail(params?: {
|
|
8185
|
+
startTime?: string;
|
|
8186
|
+
endTime?: string;
|
|
8187
|
+
limit?: string;
|
|
8188
|
+
idLessThan?: string;
|
|
8189
|
+
}): Promise<APIResponse<any>>
|
|
8190
|
+
⋮----
|
|
8191
|
+
/** Get Agent Customer List */
|
|
8192
|
+
getAgentCustomerList(params?: {
|
|
8193
|
+
startTime?: string;
|
|
8194
|
+
endTime?: string;
|
|
8195
|
+
pageNo?: string;
|
|
8196
|
+
pageSize?: string;
|
|
8197
|
+
uid?: string;
|
|
8198
|
+
referralCode?: string;
|
|
8199
|
+
}): Promise<APIResponse<any>>
|
|
8200
|
+
⋮----
|
|
8201
|
+
/**
|
|
8202
|
+
* Get Agent Customer Deposit List
|
|
8203
|
+
* Includes both on-chain deposits and internal transfers
|
|
8204
|
+
* Note: Can only query data within the last 90 days
|
|
8205
|
+
*/
|
|
8206
|
+
getAgentCustomerDepositList(params?: {
|
|
8207
|
+
startTime?: string;
|
|
8208
|
+
endTime?: string;
|
|
8209
|
+
pageNo?: string;
|
|
8210
|
+
pageSize?: string;
|
|
8211
|
+
uid?: string;
|
|
8212
|
+
}): Promise<APIResponse<any>>
|
|
8213
|
+
⋮----
|
|
8214
|
+
/**
|
|
8215
|
+
* Get Agent Customer Trade Volume List
|
|
8216
|
+
* Includes trading volume for both spot and futures
|
|
8217
|
+
* Note: Data updates every 10 minutes and can only query last 90 days
|
|
8218
|
+
*/
|
|
8219
|
+
getAgentCustomerTradeVolumeList(params?: {
|
|
8220
|
+
startTime?: string;
|
|
8221
|
+
endTime?: string;
|
|
8222
|
+
pageNo?: string;
|
|
8223
|
+
pageSize?: string;
|
|
8224
|
+
uid?: string;
|
|
8225
|
+
}): Promise<APIResponse<any>>
|
|
8226
|
+
⋮----
|
|
8227
|
+
/**
|
|
8228
|
+
* Get Agent Customer Assets List
|
|
8229
|
+
* Returns account balances for customer accounts
|
|
8230
|
+
* Note: Data updates every 10 minutes
|
|
8231
|
+
*/
|
|
8232
|
+
getAgentCustomerAssetsList(params?: {
|
|
8233
|
+
pageNo?: string;
|
|
8234
|
+
pageSize?: string;
|
|
8235
|
+
uid?: string;
|
|
8236
|
+
}): Promise<APIResponse<any>>
|
|
8237
|
+
⋮----
|
|
8238
|
+
/**
|
|
8239
|
+
* Get Agent Direct Commissions
|
|
8240
|
+
* Returns commission data for direct customers
|
|
8241
|
+
* Note: Data updates on T+1 (UTC+8) basis and can only query last 90 days
|
|
8242
|
+
*/
|
|
8243
|
+
getAgentCustomerCommissions(params?: {
|
|
8244
|
+
startTime?: string;
|
|
8245
|
+
endTime?: string;
|
|
8246
|
+
idLessThan?: string;
|
|
8247
|
+
limit?: string;
|
|
8248
|
+
uid?: string;
|
|
8249
|
+
coin?: string;
|
|
8250
|
+
symbol?: string;
|
|
8251
|
+
}): Promise<APIResponse<any>>
|
|
8252
|
+
⋮----
|
|
8253
|
+
/**
|
|
8254
|
+
* Get Agent Customer KYC Result
|
|
8255
|
+
* Returns KYC verification status for customers
|
|
8256
|
+
*/
|
|
8257
|
+
getAgentCustomerKycResult(params?: {
|
|
8258
|
+
startTime?: string;
|
|
8259
|
+
endTime?: string;
|
|
8260
|
+
pageNo?: string;
|
|
8261
|
+
pageSize?: string;
|
|
8262
|
+
uid?: string;
|
|
8263
|
+
}): Promise<APIResponse<any>>
|
|
8264
|
+
|
|
8077
8265
|
================
|
|
8078
8266
|
File: src/rest-client-v2.ts
|
|
8079
8267
|
================
|
|
@@ -10863,194 +11051,6 @@ export interface PlaceOrderResponseV3 {
|
|
|
10863
11051
|
clientOid: string;
|
|
10864
11052
|
}
|
|
10865
11053
|
|
|
10866
|
-
================
|
|
10867
|
-
File: src/broker-client.ts
|
|
10868
|
-
================
|
|
10869
|
-
import {
|
|
10870
|
-
BrokerProductType,
|
|
10871
|
-
BrokerSubAPIKeyModifyRequest,
|
|
10872
|
-
BrokerSubListRequest,
|
|
10873
|
-
BrokerSubWithdrawalRequest,
|
|
10874
|
-
} from './types/request/v1/brokerV1.js';
|
|
10875
|
-
import { APIResponse } from './types/response/v1/shared.js';
|
|
10876
|
-
import BaseRestClient from './util/BaseRestClient.js';
|
|
10877
|
-
import { REST_CLIENT_TYPE_ENUM } from './util/requestUtils.js';
|
|
10878
|
-
⋮----
|
|
10879
|
-
/**
|
|
10880
|
-
* REST API client for the V1 bitget Broker APIs. These are the previous generation of Bitget's APIs and should be considered deprecated.
|
|
10881
|
-
* These will be removed in a future release, once Bitget formally deprecates them.
|
|
10882
|
-
*
|
|
10883
|
-
* @deprecated use RestClientV2 instead
|
|
10884
|
-
*/
|
|
10885
|
-
export class BrokerClient extends BaseRestClient
|
|
10886
|
-
⋮----
|
|
10887
|
-
getClientType()
|
|
10888
|
-
⋮----
|
|
10889
|
-
/**
|
|
10890
|
-
*
|
|
10891
|
-
* Sub Account Interface
|
|
10892
|
-
*
|
|
10893
|
-
*/
|
|
10894
|
-
⋮----
|
|
10895
|
-
/** Get Broker Info */
|
|
10896
|
-
getBrokerInfo(): Promise<APIResponse<any>>
|
|
10897
|
-
⋮----
|
|
10898
|
-
/** Create Sub Account */
|
|
10899
|
-
createSubAccount(
|
|
10900
|
-
subName: string,
|
|
10901
|
-
remark?: string,
|
|
10902
|
-
): Promise<APIResponse<any>>
|
|
10903
|
-
⋮----
|
|
10904
|
-
/** Get Sub List */
|
|
10905
|
-
getSubAccounts(params?: BrokerSubListRequest): Promise<APIResponse<any>>
|
|
10906
|
-
⋮----
|
|
10907
|
-
/** Modify Sub Account */
|
|
10908
|
-
modifySubAccount(
|
|
10909
|
-
subUid: string,
|
|
10910
|
-
perm: string,
|
|
10911
|
-
status: 'normal' | 'freeze' | 'del',
|
|
10912
|
-
): Promise<APIResponse<any>>
|
|
10913
|
-
⋮----
|
|
10914
|
-
/** Modify Sub Email */
|
|
10915
|
-
modifySubEmail(subUid: string, subEmail: string): Promise<APIResponse<any>>
|
|
10916
|
-
⋮----
|
|
10917
|
-
/** Get Sub Email */
|
|
10918
|
-
getSubEmail(subUid: string): Promise<APIResponse<any>>
|
|
10919
|
-
⋮----
|
|
10920
|
-
/** Get Sub Spot Assets */
|
|
10921
|
-
getSubSpotAssets(subUid: string): Promise<APIResponse<any>>
|
|
10922
|
-
⋮----
|
|
10923
|
-
/** Get Sub Future Assets */
|
|
10924
|
-
getSubFutureAssets(
|
|
10925
|
-
subUid: string,
|
|
10926
|
-
productType: BrokerProductType,
|
|
10927
|
-
): Promise<APIResponse<any>>
|
|
10928
|
-
⋮----
|
|
10929
|
-
/** Get Sub Deposit Address (Only Broker) */
|
|
10930
|
-
getSubDepositAddress(
|
|
10931
|
-
subUid: string,
|
|
10932
|
-
coin: string,
|
|
10933
|
-
chain?: string,
|
|
10934
|
-
): Promise<APIResponse<any>>
|
|
10935
|
-
⋮----
|
|
10936
|
-
/** Sub Withdrawal (Only Broker) */
|
|
10937
|
-
subWithdrawal(params: BrokerSubWithdrawalRequest): Promise<APIResponse<any>>
|
|
10938
|
-
⋮----
|
|
10939
|
-
/** Sub Deposit Auto Transfer (Only Broker) */
|
|
10940
|
-
setSubDepositAutoTransfer(
|
|
10941
|
-
subUid: string,
|
|
10942
|
-
coin: string,
|
|
10943
|
-
toAccountType: 'spot' | 'mix_usdt' | 'mix_usd' | 'mix_usdc',
|
|
10944
|
-
): Promise<APIResponse<any>>
|
|
10945
|
-
⋮----
|
|
10946
|
-
/**
|
|
10947
|
-
*
|
|
10948
|
-
* Sub API Interface
|
|
10949
|
-
*
|
|
10950
|
-
*/
|
|
10951
|
-
⋮----
|
|
10952
|
-
/** Create Sub ApiKey (Only Broker) */
|
|
10953
|
-
createSubAPIKey(
|
|
10954
|
-
subUid: string,
|
|
10955
|
-
passphrase: string,
|
|
10956
|
-
remark: string,
|
|
10957
|
-
ip: string,
|
|
10958
|
-
perm?: string,
|
|
10959
|
-
): Promise<APIResponse<any>>
|
|
10960
|
-
⋮----
|
|
10961
|
-
/** Get Sub ApiKey List */
|
|
10962
|
-
getSubAPIKeys(subUid: string): Promise<APIResponse<any>>
|
|
10963
|
-
⋮----
|
|
10964
|
-
/** Modify Sub ApiKey (Only Broker) */
|
|
10965
|
-
modifySubAPIKey(
|
|
10966
|
-
params: BrokerSubAPIKeyModifyRequest,
|
|
10967
|
-
): Promise<APIResponse<any>>
|
|
10968
|
-
⋮----
|
|
10969
|
-
/**
|
|
10970
|
-
* Undocumented endpoints
|
|
10971
|
-
*/
|
|
10972
|
-
⋮----
|
|
10973
|
-
getAgentCommissionDetail(params?: {
|
|
10974
|
-
startTime?: string;
|
|
10975
|
-
endTime?: string;
|
|
10976
|
-
limit?: string;
|
|
10977
|
-
idLessThan?: string;
|
|
10978
|
-
}): Promise<APIResponse<any>>
|
|
10979
|
-
⋮----
|
|
10980
|
-
/** Get Agent Customer List */
|
|
10981
|
-
getAgentCustomerList(params?: {
|
|
10982
|
-
startTime?: string;
|
|
10983
|
-
endTime?: string;
|
|
10984
|
-
pageNo?: string;
|
|
10985
|
-
pageSize?: string;
|
|
10986
|
-
uid?: string;
|
|
10987
|
-
referralCode?: string;
|
|
10988
|
-
}): Promise<APIResponse<any>>
|
|
10989
|
-
⋮----
|
|
10990
|
-
/**
|
|
10991
|
-
* Get Agent Customer Deposit List
|
|
10992
|
-
* Includes both on-chain deposits and internal transfers
|
|
10993
|
-
* Note: Can only query data within the last 90 days
|
|
10994
|
-
*/
|
|
10995
|
-
getAgentCustomerDepositList(params?: {
|
|
10996
|
-
startTime?: string;
|
|
10997
|
-
endTime?: string;
|
|
10998
|
-
pageNo?: string;
|
|
10999
|
-
pageSize?: string;
|
|
11000
|
-
uid?: string;
|
|
11001
|
-
}): Promise<APIResponse<any>>
|
|
11002
|
-
⋮----
|
|
11003
|
-
/**
|
|
11004
|
-
* Get Agent Customer Trade Volume List
|
|
11005
|
-
* Includes trading volume for both spot and futures
|
|
11006
|
-
* Note: Data updates every 10 minutes and can only query last 90 days
|
|
11007
|
-
*/
|
|
11008
|
-
getAgentCustomerTradeVolumeList(params?: {
|
|
11009
|
-
startTime?: string;
|
|
11010
|
-
endTime?: string;
|
|
11011
|
-
pageNo?: string;
|
|
11012
|
-
pageSize?: string;
|
|
11013
|
-
uid?: string;
|
|
11014
|
-
}): Promise<APIResponse<any>>
|
|
11015
|
-
⋮----
|
|
11016
|
-
/**
|
|
11017
|
-
* Get Agent Customer Assets List
|
|
11018
|
-
* Returns account balances for customer accounts
|
|
11019
|
-
* Note: Data updates every 10 minutes
|
|
11020
|
-
*/
|
|
11021
|
-
getAgentCustomerAssetsList(params?: {
|
|
11022
|
-
pageNo?: string;
|
|
11023
|
-
pageSize?: string;
|
|
11024
|
-
uid?: string;
|
|
11025
|
-
}): Promise<APIResponse<any>>
|
|
11026
|
-
⋮----
|
|
11027
|
-
/**
|
|
11028
|
-
* Get Agent Direct Commissions
|
|
11029
|
-
* Returns commission data for direct customers
|
|
11030
|
-
* Note: Data updates on T+1 (UTC+8) basis and can only query last 90 days
|
|
11031
|
-
*/
|
|
11032
|
-
getAgentCustomerCommissions(params?: {
|
|
11033
|
-
startTime?: string;
|
|
11034
|
-
endTime?: string;
|
|
11035
|
-
idLessThan?: string;
|
|
11036
|
-
limit?: string;
|
|
11037
|
-
uid?: string;
|
|
11038
|
-
coin?: string;
|
|
11039
|
-
symbol?: string;
|
|
11040
|
-
}): Promise<APIResponse<any>>
|
|
11041
|
-
⋮----
|
|
11042
|
-
/**
|
|
11043
|
-
* Get Agent Customer KYC Result
|
|
11044
|
-
* Returns KYC verification status for customers
|
|
11045
|
-
*/
|
|
11046
|
-
getAgentCustomerKycResult(params?: {
|
|
11047
|
-
startTime?: string;
|
|
11048
|
-
endTime?: string;
|
|
11049
|
-
pageNo?: string;
|
|
11050
|
-
pageSize?: string;
|
|
11051
|
-
uid?: string;
|
|
11052
|
-
}): Promise<APIResponse<any>>
|
|
11053
|
-
|
|
11054
11054
|
================
|
|
11055
11055
|
File: src/websocket-client-v3.ts
|
|
11056
11056
|
================
|
|
@@ -12513,7 +12513,7 @@ File: package.json
|
|
|
12513
12513
|
================
|
|
12514
12514
|
{
|
|
12515
12515
|
"name": "bitget-api",
|
|
12516
|
-
"version": "3.0.
|
|
12516
|
+
"version": "3.0.2",
|
|
12517
12517
|
"description": "Complete Node.js & JavaScript SDK for Bitget V1-V3 REST APIs & WebSockets, with TypeScript & end-to-end tests.",
|
|
12518
12518
|
"scripts": {
|
|
12519
12519
|
"test": "jest",
|
|
@@ -12852,24 +12852,67 @@ File: README.md
|
|
|
12852
12852
|
|
|
12853
12853
|
Updated & performant JavaScript & Node.js SDK for the Bitget V2 REST APIs and WebSockets:
|
|
12854
12854
|
|
|
12855
|
+
- Professional, robust & performant Bitget SDK with extensive production use in live trading environments.
|
|
12855
12856
|
- Complete integration with all Bitget APIs.
|
|
12856
|
-
- [x] Supports V1 REST APIs & WebSockets
|
|
12857
|
+
- [x] Supports V1 REST APIs & WebSockets (legacy)
|
|
12857
12858
|
- [x] Supports V2 REST APIs & WebSockets
|
|
12858
|
-
- [x] Supports V3/UTA REST APIs & WebSockets
|
|
12859
|
+
- [x] Supports V3/UTA REST APIs & WebSockets (latest)
|
|
12859
12860
|
- [x] Supports order placement via V3 WebSocket API
|
|
12860
|
-
- TypeScript support (with type declarations for
|
|
12861
|
+
- Complete TypeScript support (with type declarations for all API requests & responses).
|
|
12862
|
+
- Strongly typed requests and responses.
|
|
12863
|
+
- Automated end-to-end tests on most API calls, ensuring no breaking changes are released to npm.
|
|
12864
|
+
- Actively maintained with a modern, promise-driven interface.
|
|
12861
12865
|
- Over 100 integration tests making real API calls & WebSocket connections, validating any changes before they reach npm.
|
|
12862
12866
|
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
|
|
12867
|
+
- Event driven messaging.
|
|
12868
|
+
- Smart WebSocket persistence with automatic reconnection handling.
|
|
12869
|
+
- Emit `reconnected` event when dropped connection is restored.
|
|
12870
|
+
- Optional beautification of WebSocket events for improved readability.
|
|
12863
12871
|
- Officially listed Node.js SDK in [Bitget API docs](https://bitgetlimited.github.io/apidoc/en/spot/#sdk-code-example).
|
|
12864
12872
|
- Browser support (via webpack bundle - see "Browser Usage" below).
|
|
12865
12873
|
- Support all authentication methods supported by Bitget:
|
|
12866
12874
|
- [x] HMAC
|
|
12867
12875
|
- [x] RSA
|
|
12876
|
+
- Heavy automated end-to-end testing with real API calls.
|
|
12877
|
+
- End-to-end testing before any release.
|
|
12878
|
+
- Real API calls in e2e tests.
|
|
12879
|
+
- Proxy support via axios integration.
|
|
12880
|
+
- Active community support & collaboration in telegram: [Node.js Algo Traders](https://t.me/nodetraders).
|
|
12881
|
+
|
|
12882
|
+
## Table of Contents
|
|
12883
|
+
|
|
12884
|
+
- [Installation](#installation)
|
|
12885
|
+
- [Examples](#examples)
|
|
12886
|
+
- [Issues & Discussion](#issues--discussion)
|
|
12887
|
+
- [Related Projects](#related-projects)
|
|
12888
|
+
- [Documentation](#documentation)
|
|
12889
|
+
- [Structure](#structure)
|
|
12890
|
+
- [Usage](#usage)
|
|
12891
|
+
- [REST API Clients](#rest-api-clients)
|
|
12892
|
+
- [V3 REST APIs (Unified Trading Account)](#v3-rest-apis)
|
|
12893
|
+
- [V2 REST APIs](#v2-rest-apis)
|
|
12894
|
+
- [WebSockets](#websockets)
|
|
12895
|
+
- [V3 Unified Trading Account](#v3-unified-trading-account)
|
|
12896
|
+
- [Sending Orders via WebSockets](#sending-orders-via-websockets)
|
|
12897
|
+
- [Receiving Realtime Data](#receiving-realtime-data)
|
|
12898
|
+
- [V2 WebSockets](#v2-websockets)
|
|
12899
|
+
- [Customise Logging](#logging)
|
|
12900
|
+
- [Custom Logger](#customise-logging)
|
|
12901
|
+
- [Debug HTTP Requests](#debug-http-requests)
|
|
12902
|
+
- [Frontend Usage](#browser-usage)
|
|
12903
|
+
- [Import](#import)
|
|
12904
|
+
- [Webpack](#webpack)
|
|
12905
|
+
- [LLMs & AI](#use-with-llms--ai)
|
|
12906
|
+
- [Contributions & Thanks](#contributions--thanks)
|
|
12868
12907
|
|
|
12869
12908
|
## Installation
|
|
12870
12909
|
|
|
12871
12910
|
`npm install --save bitget-api`
|
|
12872
12911
|
|
|
12912
|
+
## Examples
|
|
12913
|
+
|
|
12914
|
+
Refer to the [examples](./examples) folder for implementation demos.
|
|
12915
|
+
|
|
12873
12916
|
## Issues & Discussion
|
|
12874
12917
|
|
|
12875
12918
|
- Issues? Check the [issues tab](https://github.com/tiagosiebler/bitget-api/issues).
|
|
@@ -12900,11 +12943,14 @@ Check out my related JavaScript/TypeScript/Node.js projects:
|
|
|
12900
12943
|
|
|
12901
12944
|
## Documentation
|
|
12902
12945
|
|
|
12903
|
-
Most methods
|
|
12946
|
+
Most methods accept JS objects. 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).
|
|
12904
12947
|
|
|
12905
|
-
-
|
|
12906
|
-
- [
|
|
12948
|
+
- Bitget API Documentation
|
|
12949
|
+
- [V3/UTA API Documentation](https://www.bitget.com/api-doc/uta/intro) (Latest - Unified Trading Account)
|
|
12950
|
+
- [V2 API Documentation](https://www.bitget.com/api-doc/common/intro)
|
|
12951
|
+
- [Legacy V1 API Documentation](https://bitgetlimited.github.io/apidoc/en/spot/#introduction) (deprecated)
|
|
12907
12952
|
- [REST Endpoint Function List](./docs/endpointFunctionList.md)
|
|
12953
|
+
- [TSDoc Documentation (autogenerated using typedoc)](https://tsdocs.dev/docs/bitget-api)
|
|
12908
12954
|
|
|
12909
12955
|
## Structure
|
|
12910
12956
|
|
|
@@ -12919,6 +12965,13 @@ The version on npm is the output from the `build` command and can be used in pro
|
|
|
12919
12965
|
|
|
12920
12966
|
---
|
|
12921
12967
|
|
|
12968
|
+
# Usage
|
|
12969
|
+
|
|
12970
|
+
Create API credentials at Bitget:
|
|
12971
|
+
|
|
12972
|
+
- [Livenet API Management](https://www.bitget.com/en/support/articles/360011132814-How-to-create-API)
|
|
12973
|
+
- [Demo Trading Environment](https://www.bitget.com/en/demo-trading)
|
|
12974
|
+
|
|
12922
12975
|
## REST API Clients
|
|
12923
12976
|
|
|
12924
12977
|
Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups:
|
|
@@ -12941,12 +12994,18 @@ Examples for using each client can be found in:
|
|
|
12941
12994
|
|
|
12942
12995
|
If you're missing an example, you're welcome to request one. Priority will be given to [github sponsors](https://github.com/sponsors/tiagosiebler).
|
|
12943
12996
|
|
|
12944
|
-
###
|
|
12945
|
-
|
|
12946
|
-
First, create API credentials on Bitget's website.
|
|
12997
|
+
### Getting Started
|
|
12947
12998
|
|
|
12948
12999
|
All REST APIs are integrated in each dedicated Rest Client class. See the above table for which REST client to use. If you've upgraded to the Unified Trading Account, you should use the V3 REST APIs and WebSockets.
|
|
12949
13000
|
|
|
13001
|
+
There are several REST API modules as there are some differences in each API group:
|
|
13002
|
+
|
|
13003
|
+
1. `RestClientV3` for the latest V3/UTA APIs (Unified Trading Account) - recommended for new projects.
|
|
13004
|
+
2. `RestClientV2` for V2 APIs - use if you haven't upgraded to UTA yet.
|
|
13005
|
+
3. Legacy V1 clients (`SpotClient`, `FuturesClient`, `BrokerClient`) - deprecated, migrate to V2 or V3.
|
|
13006
|
+
|
|
13007
|
+
More Node.js & JavaScript examples for Bitget's REST APIs & WebSockets can be found in the [examples](./examples) folder on GitHub.
|
|
13008
|
+
|
|
12950
13009
|
#### V3 REST APIs
|
|
12951
13010
|
|
|
12952
13011
|
These are only available if you have upgraded to the Unified Trading Account. If not, use the V2 APIs instead.
|
|
@@ -13029,21 +13088,30 @@ client
|
|
|
13029
13088
|
});
|
|
13030
13089
|
```
|
|
13031
13090
|
|
|
13032
|
-
|
|
13091
|
+
## WebSockets
|
|
13033
13092
|
|
|
13034
13093
|
All WebSocket functionality is supported via the WebsocketClient. Since there are currently 3 generations of Bitget's API, there are 3 WebsocketClient classes in this Node.js, JavaScript & TypeScript SDK for Bitget.
|
|
13035
13094
|
|
|
13036
13095
|
Use the following guidance to decide which one to use:
|
|
13037
13096
|
|
|
13038
|
-
- Unified Trading Account / V3 (latest generation):
|
|
13097
|
+
- **Unified Trading Account / V3** (latest generation):
|
|
13039
13098
|
- For receiving data, use the [WebsocketClientV3](./src/websocket-client-v3.ts).
|
|
13040
13099
|
- For sending orders via WebSockets, use the [WebsocketAPIClient](./src/websocket-api-client.ts).
|
|
13041
|
-
- V2 (not upgraded to Unified Trading Account yet)
|
|
13100
|
+
- **V2** (not upgraded to Unified Trading Account yet)
|
|
13042
13101
|
- Use the [WebsocketClientV2](./src/websocket-client-v2.ts).
|
|
13043
|
-
- V1 (deprecated)
|
|
13102
|
+
- **V1** (deprecated)
|
|
13044
13103
|
- This is the oldest API group supported by Bitget. You should migrate to V3 or V2 as soon as possible.
|
|
13045
13104
|
- If you're not ready to migrate, you can use the [WebsocketClientLegacyV1](./src/websocket-client-legacy-v1.ts) class in the meantime.
|
|
13046
13105
|
|
|
13106
|
+
All WebSocket clients support:
|
|
13107
|
+
|
|
13108
|
+
- Event driven messaging
|
|
13109
|
+
- Smart WebSocket persistence with automatic reconnection
|
|
13110
|
+
- Heartbeat mechanisms to detect disconnections
|
|
13111
|
+
- Automatic resubscription after reconnection
|
|
13112
|
+
- Error handling and connection monitoring
|
|
13113
|
+
- Optional data beautification
|
|
13114
|
+
|
|
13047
13115
|
Higher level examples below, while more thorough examples can be found in the examples folder on GitHub.
|
|
13048
13116
|
|
|
13049
13117
|
##### V3 Unified Trading Account
|
|
@@ -13238,6 +13306,51 @@ wsClient.subscribe(
|
|
|
13238
13306
|
|
|
13239
13307
|
For more examples, including how to use websockets with Bitget, check the [examples](./examples/) and [test](./test/) folders.
|
|
13240
13308
|
|
|
13309
|
+
### V2 WebSockets
|
|
13310
|
+
|
|
13311
|
+
If you haven't upgraded to the Unified Trading Account, use the V2 WebSocket client:
|
|
13312
|
+
|
|
13313
|
+
```javascript
|
|
13314
|
+
import { WebsocketClientV2 } from 'bitget-api';
|
|
13315
|
+
// or if you prefer require:
|
|
13316
|
+
// const { WebsocketClientV2 } = require('bitget-api');
|
|
13317
|
+
|
|
13318
|
+
const API_KEY = 'xxx';
|
|
13319
|
+
const API_SECRET = 'yyy';
|
|
13320
|
+
const API_PASS = 'zzz';
|
|
13321
|
+
|
|
13322
|
+
const wsClient = new WebsocketClientV2({
|
|
13323
|
+
apiKey: API_KEY,
|
|
13324
|
+
apiSecret: API_SECRET,
|
|
13325
|
+
apiPass: API_PASS,
|
|
13326
|
+
// Optional: connect to demo trading environment
|
|
13327
|
+
// demoTrading: true,
|
|
13328
|
+
});
|
|
13329
|
+
|
|
13330
|
+
// Handle incoming messages
|
|
13331
|
+
wsClient.on('update', (data) => {
|
|
13332
|
+
console.log('WS update received: ', data);
|
|
13333
|
+
});
|
|
13334
|
+
|
|
13335
|
+
wsClient.on('open', (data) => {
|
|
13336
|
+
console.log('WS connection opened: ', data.wsKey);
|
|
13337
|
+
});
|
|
13338
|
+
|
|
13339
|
+
wsClient.on('reconnected', (data) => {
|
|
13340
|
+
console.log('WS reconnected: ', data?.wsKey);
|
|
13341
|
+
});
|
|
13342
|
+
|
|
13343
|
+
wsClient.on('exception', (data) => {
|
|
13344
|
+
console.log('WS error: ', data);
|
|
13345
|
+
});
|
|
13346
|
+
|
|
13347
|
+
// Subscribe to public data streams
|
|
13348
|
+
wsClient.subscribeTopic('SPOT', 'ticker', symbol);
|
|
13349
|
+
|
|
13350
|
+
// Subscribe to private data streams (requires authentication)
|
|
13351
|
+
wsClient.subscribeTopic('SPOT', 'account');
|
|
13352
|
+
```
|
|
13353
|
+
|
|
13241
13354
|
---
|
|
13242
13355
|
|
|
13243
13356
|
## Logging
|