Skip to content

Commit f10db19

Browse files
committed
chore(v3.0.2): enhance README with detailed usage instructions, and reintroduce .gitignore file. Refactor BrokerClient to include additional API methods and improve documentation for WebSocket clients.
1 parent 053b185 commit f10db19

File tree

4 files changed

+479
-253
lines changed

4 files changed

+479
-253
lines changed

README.md

Lines changed: 126 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,67 @@
2121

2222
Updated & performant JavaScript & Node.js SDK for the Bitget V2 REST APIs and WebSockets:
2323

24+
- Professional, robust & performant Bitget SDK with extensive production use in live trading environments.
2425
- Complete integration with all Bitget APIs.
25-
- [x] Supports V1 REST APIs & WebSockets
26+
- [x] Supports V1 REST APIs & WebSockets (legacy)
2627
- [x] Supports V2 REST APIs & WebSockets
27-
- [x] Supports V3/UTA REST APIs & WebSockets
28+
- [x] Supports V3/UTA REST APIs & WebSockets (latest)
2829
- [x] Supports order placement via V3 WebSocket API
29-
- TypeScript support (with type declarations for most API requests & responses).
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.
3034
- Over 100 integration tests making real API calls & WebSocket connections, validating any changes before they reach npm.
3135
- 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.
3240
- Officially listed Node.js SDK in [Bitget API docs](https://bitgetlimited.github.io/apidoc/en/spot/#sdk-code-example).
3341
- Browser support (via webpack bundle - see "Browser Usage" below).
3442
- Support all authentication methods supported by Bitget:
3543
- [x] HMAC
3644
- [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)
3776

3877
## Installation
3978

4079
`npm install --save bitget-api`
4180

81+
## Examples
82+
83+
Refer to the [examples](./examples) folder for implementation demos.
84+
4285
## Issues & Discussion
4386

4487
- 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:
69112

70113
## Documentation
71114

72-
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).
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).
73116

74-
- [Bitget API V2 Documentation](https://www.bitget.com/api-doc/common/intro).
75-
- [Bitget API V3/UTA Documentation](https://www.bitget.com/api-doc/uta/intro).
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)
76121
- [REST Endpoint Function List](./docs/endpointFunctionList.md)
122+
- [TSDoc Documentation (autogenerated using typedoc)](https://tsdocs.dev/docs/bitget-api)
77123

78124
## Structure
79125

@@ -88,6 +134,13 @@ The version on npm is the output from the `build` command and can be used in pro
88134

89135
---
90136

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+
91144
## REST API Clients
92145

93146
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:
110163

111164
If you're missing an example, you're welcome to request one. Priority will be given to [github sponsors](https://github.com/sponsors/tiagosiebler).
112165

113-
### Usage
114-
115-
First, create API credentials on Bitget's website.
166+
### Getting Started
116167

117168
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.
118169

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+
119178
#### V3 REST APIs
120179

121180
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
198257
});
199258
```
200259

201-
#### WebSockets
260+
## WebSockets
202261

203262
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.
204263

205264
Use the following guidance to decide which one to use:
206265

207-
- Unified Trading Account / V3 (latest generation):
266+
- **Unified Trading Account / V3** (latest generation):
208267
- For receiving data, use the [WebsocketClientV3](./src/websocket-client-v3.ts).
209268
- 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)
211270
- Use the [WebsocketClientV2](./src/websocket-client-v2.ts).
212-
- V1 (deprecated)
271+
- **V1** (deprecated)
213272
- This is the oldest API group supported by Bitget. You should migrate to V3 or V2 as soon as possible.
214273
- If you're not ready to migrate, you can use the [WebsocketClientLegacyV1](./src/websocket-client-legacy-v1.ts) class in the meantime.
215274

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+
216284
Higher level examples below, while more thorough examples can be found in the examples folder on GitHub.
217285

218286
##### V3 Unified Trading Account
@@ -407,6 +475,51 @@ wsClient.subscribe(
407475

408476
For more examples, including how to use websockets with Bitget, check the [examples](./examples/) and [test](./test/) folders.
409477

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+
410523
---
411524
412525
## Logging

0 commit comments

Comments
 (0)