@binance/alpha 2.0.0 → 3.0.0
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 +103 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
This is a client library for the Binance Alpha API, enabling developers to interact programmatically with Binance Alpha. The library provides tools to access curated early-stage token data, track Alpha project metrics and integrate discovery-focused market information into applications through the REST API:
|
|
13
13
|
|
|
14
14
|
- [REST API](./src/rest-api/rest-api.ts)
|
|
15
|
+
- [Websocket Stream](./src/websocket-streams/websocket-streams-connection.ts)
|
|
15
16
|
|
|
16
17
|
## Table of Contents
|
|
17
18
|
|
|
@@ -19,6 +20,7 @@ This is a client library for the Binance Alpha API, enabling developers to inter
|
|
|
19
20
|
- [Installation](#installation)
|
|
20
21
|
- [Documentation](#documentation)
|
|
21
22
|
- [REST APIs](#rest-apis)
|
|
23
|
+
- [Websocket Streams](#websocket-streams)
|
|
22
24
|
- [Testing](#testing)
|
|
23
25
|
- [Contributing](#contributing)
|
|
24
26
|
- [Licence](#licence)
|
|
@@ -27,6 +29,7 @@ This is a client library for the Binance Alpha API, enabling developers to inter
|
|
|
27
29
|
|
|
28
30
|
- REST API Endpoints:
|
|
29
31
|
- `/bapi/defi/v1/*`
|
|
32
|
+
- WebSocket Endpoints: Real-time data streaming.
|
|
30
33
|
- Inclusion of test cases and examples for quick onboarding.
|
|
31
34
|
|
|
32
35
|
## Installation
|
|
@@ -141,6 +144,93 @@ See the [Error Handling example](./docs/rest-api/error-handling.md) for detailed
|
|
|
141
144
|
|
|
142
145
|
If `basePath` is not provided, it defaults to `https://www.binance.com`.
|
|
143
146
|
|
|
147
|
+
### Websocket Streams
|
|
148
|
+
|
|
149
|
+
WebSocket Streams provide real-time data feeds for market trades, candlesticks, and more. Use the [websocket-streams](./src/websocket-streams/websocket-streams.ts) module to subscribe to these streams.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { Alpha, ALPHA_WS_STREAMS_PROD_URL } from '@binance/alpha';
|
|
153
|
+
|
|
154
|
+
const configurationWebsocketStreams = {
|
|
155
|
+
wsURL: ALPHA_WS_STREAMS_PROD_URL,
|
|
156
|
+
};
|
|
157
|
+
const client = new Alpha({ configurationWebsocketStreams });
|
|
158
|
+
|
|
159
|
+
client.websocketStreams
|
|
160
|
+
.connect()
|
|
161
|
+
.then((connection) => {
|
|
162
|
+
const stream = connection.allBookTickerStream();
|
|
163
|
+
stream.on('message', (data) => console.info(data));
|
|
164
|
+
})
|
|
165
|
+
.catch((err) => console.error(err));
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
More examples are available in the [`examples/websocket-streams`](./examples/websocket-streams/) folder.
|
|
169
|
+
|
|
170
|
+
#### Configuration Options
|
|
171
|
+
|
|
172
|
+
The WebSocket Streams API supports the following advanced configuration options:
|
|
173
|
+
|
|
174
|
+
- `reconnectDelay`: Specify the delay between reconnection attempts (default: 5000 ms).
|
|
175
|
+
- `compression`: Enable or disable compression for WebSocket messages (default: true).
|
|
176
|
+
- `agent`: Customize the WebSocket agent for advanced configurations.
|
|
177
|
+
- `mode`: Choose between `single` and `pool` connection modes.
|
|
178
|
+
- `single`: A single WebSocket connection.
|
|
179
|
+
- `pool`: A pool of WebSocket connections.
|
|
180
|
+
- `poolSize`: Define the number of WebSocket connections in pool mode.
|
|
181
|
+
|
|
182
|
+
##### Reconnect Delay
|
|
183
|
+
|
|
184
|
+
Specify the delay in milliseconds between WebSocket reconnection attempts for streams. See the [Reconnect Delay example](./docs/websocket-streams/reconnect-delay.md) for detailed usage.
|
|
185
|
+
|
|
186
|
+
##### Compression
|
|
187
|
+
|
|
188
|
+
Enable or disable compression for WebSocket Streams messages. See the [Compression example](./docs/websocket-streams/compression.md) for detailed usage.
|
|
189
|
+
|
|
190
|
+
##### WebSocket Agent
|
|
191
|
+
|
|
192
|
+
Customize the agent for advanced configurations. See the [WebSocket Agent example](./docs/websocket-streams/agent.md) for detailed usage.
|
|
193
|
+
|
|
194
|
+
##### Connection Mode
|
|
195
|
+
|
|
196
|
+
Choose between `single` and `pool` connection modes for WebSocket Streams. The `single` mode uses a single WebSocket connection, while the `pool` mode uses a pool of WebSocket connections. See the [Connection Mode example](./docs/websocket-streams/connection-mode.md) for detailed usage.
|
|
197
|
+
|
|
198
|
+
##### Certificate Pinning
|
|
199
|
+
|
|
200
|
+
To enhance security, you can use certificate pinning with the `agent` option in the configuration. This ensures the client only communicates with servers using specific certificates. See the [Certificate Pinning example](./docs/websocket-streams/certificate-pinning.md) for detailed usage.
|
|
201
|
+
|
|
202
|
+
#### Unsubscribing from Streams
|
|
203
|
+
|
|
204
|
+
You can unsubscribe from specific WebSocket streams using the `unsubscribe` method. This is useful for managing active subscriptions without closing the connection.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
import { Alpha, ALPHA_WS_STREAMS_PROD_URL } from '@binance/alpha';
|
|
208
|
+
|
|
209
|
+
const configurationWebsocketStreams = {
|
|
210
|
+
wsURL: ALPHA_WS_STREAMS_PROD_URL,
|
|
211
|
+
};
|
|
212
|
+
const client = new Alpha({ configurationWebsocketStreams });
|
|
213
|
+
|
|
214
|
+
client.websocketStreams
|
|
215
|
+
.connect()
|
|
216
|
+
.then((connection) => {
|
|
217
|
+
const stream = connection.allBookTickerStream();
|
|
218
|
+
stream.on('message', (data) => console.info(data));
|
|
219
|
+
|
|
220
|
+
setTimeout(() => {
|
|
221
|
+
stream.unsubscribe();
|
|
222
|
+
console.log('Unsubscribed from allBookTickerStream stream');
|
|
223
|
+
}, 10000);
|
|
224
|
+
})
|
|
225
|
+
.catch((err) => console.error(err));
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
If `wsURL` is not provided, it defaults to `wss://nbstream.binance.com/w3w/wsa`.
|
|
229
|
+
|
|
230
|
+
### Automatic Connection Renewal
|
|
231
|
+
|
|
232
|
+
The WebSocket connection is automatically renewed for the WebSocket Streams connections, before the 24 hours expiration of the API key. This ensures continuous connectivity.
|
|
233
|
+
|
|
144
234
|
## Testing
|
|
145
235
|
|
|
146
236
|
To run the tests:
|
|
@@ -171,6 +261,19 @@ Please ensure that all tests pass if you're making a direct contribution. Submit
|
|
|
171
261
|
|
|
172
262
|
Thank you for your contributions!
|
|
173
263
|
|
|
264
|
+
## Disclaimer
|
|
265
|
+
|
|
266
|
+
This SDK is provided by Binance on an "as is" and "as available" basis for use at your own risk. Binance makes no representations or warranties of any kind, whether express or implied, as to the operation of the SDK, its accuracy, reliability, completeness, or fitness for any particular purpose.
|
|
267
|
+
|
|
268
|
+
To the fullest extent permitted by law, Binance shall not be liable for any losses, damages, or expenses of any kind arising from or in connection with your use of, or inability to use, this SDK, including but not limited to any financial losses resulting from errors, bugs, interruptions, or inaccuracies in the SDK.
|
|
269
|
+
|
|
270
|
+
Your use of this SDK to access the Binance Platform is subject to the Binance API Key Terms and the Binance Terms of Use, which shall prevail in the event of any conflict with this disclaimer. You are solely responsible for any orders or transactions executed through the Binance Platform using this SDK.
|
|
271
|
+
|
|
272
|
+
This SDK is not intended to constitute investment advice or a recommendation to buy, sell, or hold any digital asset. You should independently evaluate and verify all information before acting.
|
|
273
|
+
|
|
274
|
+
- [Binance Terms of Use](https://www.binance.com/en/terms)
|
|
275
|
+
- [Binance API Key Terms](https://www.binance.com/en/about-legal/terms-binance-api)
|
|
276
|
+
|
|
174
277
|
## Licence
|
|
175
278
|
|
|
176
279
|
This project is licensed under the MIT License. See the [LICENCE](./LICENCE) file for details.
|
package/dist/index.d.mts
CHANGED
|
@@ -3197,7 +3197,7 @@ declare class WebsocketStreamsConnection {
|
|
|
3197
3197
|
* @param id Optional subscription ID
|
|
3198
3198
|
* @returns void
|
|
3199
3199
|
*/
|
|
3200
|
-
subscribe(stream: string | string[], id?:
|
|
3200
|
+
subscribe(stream: string | string[], id?: number): void;
|
|
3201
3201
|
/**
|
|
3202
3202
|
* Unsubscribes from one or multiple WebSocket streams
|
|
3203
3203
|
* Handles both single and pool modes
|
|
@@ -3205,7 +3205,7 @@ declare class WebsocketStreamsConnection {
|
|
|
3205
3205
|
* @param id Optional unsubscription ID
|
|
3206
3206
|
* @returns void
|
|
3207
3207
|
*/
|
|
3208
|
-
unsubscribe(stream: string | string[], id?:
|
|
3208
|
+
unsubscribe(stream: string | string[], id?: number): void;
|
|
3209
3209
|
/**
|
|
3210
3210
|
* Checks if the WebSocket connection is subscribed to the specified stream.
|
|
3211
3211
|
* @param stream The name of the WebSocket stream to check.
|
package/dist/index.d.ts
CHANGED
|
@@ -3198,7 +3198,7 @@ declare class WebsocketStreamsConnection {
|
|
|
3198
3198
|
* @param id Optional subscription ID
|
|
3199
3199
|
* @returns void
|
|
3200
3200
|
*/
|
|
3201
|
-
subscribe(stream: string | string[], id?:
|
|
3201
|
+
subscribe(stream: string | string[], id?: number): void;
|
|
3202
3202
|
/**
|
|
3203
3203
|
* Unsubscribes from one or multiple WebSocket streams
|
|
3204
3204
|
* Handles both single and pool modes
|
|
@@ -3206,7 +3206,7 @@ declare class WebsocketStreamsConnection {
|
|
|
3206
3206
|
* @param id Optional unsubscription ID
|
|
3207
3207
|
* @returns void
|
|
3208
3208
|
*/
|
|
3209
|
-
unsubscribe(stream: string | string[], id?:
|
|
3209
|
+
unsubscribe(stream: string | string[], id?: number): void;
|
|
3210
3210
|
/**
|
|
3211
3211
|
* Checks if the WebSocket connection is subscribed to the specified stream.
|
|
3212
3212
|
* @param stream The name of the WebSocket stream to check.
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ let __binance_common = require("@binance/common");
|
|
|
14
14
|
|
|
15
15
|
//#region package.json
|
|
16
16
|
var name = "@binance/alpha";
|
|
17
|
-
var version = "
|
|
17
|
+
var version = "3.0.0";
|
|
18
18
|
|
|
19
19
|
//#endregion
|
|
20
20
|
//#region src/rest-api/modules/market-data-api.ts
|
|
@@ -1025,6 +1025,7 @@ var WebsocketStreams = class {
|
|
|
1025
1025
|
...mode && { mode },
|
|
1026
1026
|
...poolSize && { poolSize }
|
|
1027
1027
|
});
|
|
1028
|
+
websocketBase.streamIdIsStrictlyNumber = true;
|
|
1028
1029
|
const websocketStreamsConnection = new WebsocketStreamsConnection(websocketBase);
|
|
1029
1030
|
await websocketBase.connect(stream);
|
|
1030
1031
|
return websocketStreamsConnection;
|