bitget-api 3.0.0 → 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 +135 -16
- package/llms.txt +14303 -0
- package/package.json +3 -2
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.
|
|
@@ -127,9 +186,9 @@ import { RestClientV3 } from 'bitget-api';
|
|
|
127
186
|
|
|
128
187
|
// note the single quotes, preventing special characters such as $ from being incorrectly passed
|
|
129
188
|
const client = new RestClientV3({
|
|
130
|
-
apiKey: process.env.API_KEY_COM ||
|
|
131
|
-
apiSecret: process.env.API_SECRET_COM ||
|
|
132
|
-
apiPass: process.env.API_PASS_COM ||
|
|
189
|
+
apiKey: process.env.API_KEY_COM || 'insert_api_key_here',
|
|
190
|
+
apiSecret: process.env.API_SECRET_COM || 'insert_api_secret_here',
|
|
191
|
+
apiPass: process.env.API_PASS_COM || 'insert_api_pass_here',
|
|
133
192
|
});
|
|
134
193
|
|
|
135
194
|
(async () => {
|
|
@@ -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
|
|
@@ -480,6 +593,12 @@ Build a bundle using webpack:
|
|
|
480
593
|
|
|
481
594
|
The bundle can be found in `dist/`. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO - contributions welcome.
|
|
482
595
|
|
|
596
|
+
## Use with LLMs & AI
|
|
597
|
+
|
|
598
|
+
This SDK includes a bundled `llms.txt` file in the root of the repository. If you're developing with LLMs, use the included `llms.txt` with your LLM - it will significantly improve the LLMs understanding of how to correctly use this SDK.
|
|
599
|
+
|
|
600
|
+
This file contains AI optimised structure of all the functions in this package, and their parameters for easier use with any learning models or artificial intelligence.
|
|
601
|
+
|
|
483
602
|
---
|
|
484
603
|
|
|
485
604
|
<!-- template_contributions -->
|