v2.0.0: feat() V2 REST & Websocket support for bitget
This commit is contained in:
74
README.md
74
README.md
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
[1]: https://www.npmjs.com/package/bitget-api
|
[1]: https://www.npmjs.com/package/bitget-api
|
||||||
|
|
||||||
Node.js connector for the Bitget APIs and WebSockets:
|
Updated & performant JavaScript & Node.js SDK for the Bitget V2 REST APIs and WebSockets:
|
||||||
|
|
||||||
- Complete integration with all Bitget APIs.
|
- Complete integration with all Bitget APIs.
|
||||||
- TypeScript support (with type declarations for most API requests & responses).
|
- TypeScript support (with type declarations for most API requests & responses).
|
||||||
@@ -45,7 +45,7 @@ Check out my related projects:
|
|||||||
|
|
||||||
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).
|
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).
|
||||||
|
|
||||||
- [Bitget API Documentation](https://www.bitget.com/docs-v5/en/#rest-api).
|
- [Bitget API Documentation](https://www.bitget.com/api-doc/common/intro).
|
||||||
|
|
||||||
## Structure
|
## Structure
|
||||||
|
|
||||||
@@ -65,10 +65,12 @@ The version on npm is the output from the `build` command and can be used in pro
|
|||||||
Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups:
|
Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups:
|
||||||
| Class | Description |
|
| Class | Description |
|
||||||
|:------------------------------------: |:---------------------------------------------------------------------------------------------: |
|
|:------------------------------------: |:---------------------------------------------------------------------------------------------: |
|
||||||
| [SpotClient](src/spot-client.ts) | [Spot APIs](https://bitgetlimited.github.io/apidoc/en/spot/#introduction) |
|
| [RestClientV2](src/rest-client-v2.ts) | [V2 REST APIs](https://www.bitget.com/api-doc/common/intro) |
|
||||||
| [FuturesClient](src/futures-client.ts) | [Futures APIs](https://bitgetlimited.github.io/apidoc/en/mix/#introduction) |
|
| [WebsocketClient](src/websocket-client-v2.ts) | Universal client for all Bitget's V2 Websockets |
|
||||||
| [BrokerClient](src/broker-client.ts) | [Broker APIs](https://bitgetlimited.github.io/apidoc/en/broker/#introduction) |
|
| [~~SpotClient~~ (deprecated, use RestClientV2)](src/spot-client.ts) | [~~Spot APIs~~](https://bitgetlimited.github.io/apidoc/en/spot/#introduction) |
|
||||||
| [WebsocketClient](src/websocket-client.ts) | Universal client for all Bitget's Websockets |
|
| [~~FuturesClient~~ (deprecated, use RestClientV2)](src/futures-client.ts) | [~~Futures APIs~~](https://bitgetlimited.github.io/apidoc/en/mix/#introduction) |
|
||||||
|
| [~~BrokerClient~~ (deprecated, use RestClientV2)](src/broker-client.ts) | [~~Broker APIs~~](https://bitgetlimited.github.io/apidoc/en/broker/#introduction) |
|
||||||
|
| [~~WebsocketClient~~ (deprecated, use WebsocketClientV2)](src/websocket-client.ts) | ~~Universal client for all Bitget's V1 Websockets~~ |
|
||||||
|
|
||||||
Examples for using each client can be found in:
|
Examples for using each client can be found in:
|
||||||
|
|
||||||
@@ -81,54 +83,57 @@ If you're missing an example, you're welcome to request one. Priority will be gi
|
|||||||
|
|
||||||
First, create API credentials on Bitget's website.
|
First, create API credentials on Bitget's website.
|
||||||
|
|
||||||
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!
|
All REST endpoints should be included in the [RestClientV2](src/rest-client-v2.ts) class. If any endpoints are missing or need improved types, pull requests are very welcome. You can also open an issue on this repo to request an improvement. Priority will be given to [github sponsors](https://github.com/sponsors/tiagosiebler).
|
||||||
|
|
||||||
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.
|
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/parameters/responses.
|
||||||
|
|
||||||
|
If you found the method you're looking for in the API docs, you can also search for the endpoint in the [RestClientV2](src/rest-client-v2.ts) class.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const {
|
const { RestClientV2 } = require('bitget-api');
|
||||||
SpotClient,
|
|
||||||
FuturesClient,
|
|
||||||
BrokerClient,
|
|
||||||
} = require('bitget-api');
|
|
||||||
|
|
||||||
const API_KEY = 'xxx';
|
const API_KEY = 'xxx';
|
||||||
const API_SECRET = 'yyy';
|
const API_SECRET = 'yyy';
|
||||||
const API_PASS = 'zzz';
|
const API_PASS = 'zzz';
|
||||||
|
|
||||||
const client = new SpotClient({
|
const client = new RestClientV2(
|
||||||
|
{
|
||||||
apiKey: API_KEY,
|
apiKey: API_KEY,
|
||||||
apiSecret: API_SECRET,
|
apiSecret: API_SECRET,
|
||||||
apiPass: API_PASS,
|
apiPass: API_PASS,
|
||||||
},
|
},
|
||||||
// requestLibraryOptions
|
// requestLibraryOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
// For public-only API calls, simply don't provide a key & secret or set them to undefined
|
// For public-only API calls, simply don't provide a key & secret or set them to undefined
|
||||||
// const client = new SpotClient();
|
// const client = new RestClientV2();
|
||||||
|
|
||||||
|
client
|
||||||
client.getApiKeyInfo()
|
.getSpotAccount()
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
console.log("getApiKeyInfo result: ", result);
|
console.log('getSpotAccount result: ', result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.error("getApiKeyInfo error: ", err);
|
console.error('getSpotAccount error: ', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
const symbol = 'BTCUSDT_SPBL';
|
client
|
||||||
client.getCandles(symbol, '1min');
|
.getSpotCandles({
|
||||||
.then(result => {
|
symbol: 'BTCUSDT',
|
||||||
console.log("getCandles result: ", result);
|
granularity: '1min',
|
||||||
|
limit: '1000',
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.then((result) => {
|
||||||
console.error("getCandles error: ", err);
|
console.log('getCandles result: ', result);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('getCandles error: ', err);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
#### WebSockets
|
#### WebSockets
|
||||||
|
|
||||||
For more examples, including how to use websockets with bitget, check the [examples](./examples/) and [test](./test/) folders.
|
For more examples, including how to use websockets with Bitget, check the [examples](./examples/) and [test](./test/) folders.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -141,16 +146,19 @@ Pass a custom logger which supports the log methods `silly`, `debug`, `notice`,
|
|||||||
```javascript
|
```javascript
|
||||||
const { WebsocketClient, DefaultLogger } = require('bitget-api');
|
const { WebsocketClient, DefaultLogger } = require('bitget-api');
|
||||||
|
|
||||||
// Disable all logging on the silly level
|
// Disable all logging on the silly level (less console logs)
|
||||||
DefaultLogger.silly = () => {};
|
const customLogger = {
|
||||||
|
...DefaultLogger,
|
||||||
|
silly: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
const ws = new WebsocketClient(
|
const ws = new WebsocketClientV2(
|
||||||
{
|
{
|
||||||
apiKey: 'API_KEY',
|
apiKey: 'API_KEY',
|
||||||
apiSecret: 'API_SECRET',
|
apiSecret: 'API_SECRET',
|
||||||
apiPass: 'API_PASS',
|
apiPass: 'API_PASS',
|
||||||
},
|
},
|
||||||
DefaultLogger,
|
customLogger,
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "bitget-api",
|
"name": "bitget-api",
|
||||||
"version": "1.1.4",
|
"version": "2.0.0",
|
||||||
"description": "Node.js connector for Bitget REST APIs and WebSockets, with TypeScript & end-to-end tests.",
|
"description": "Node.js & JavaScript SDK for Bitget REST APIs & WebSockets, with TypeScript & end-to-end tests.",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
Reference in New Issue
Block a user