@binance/derivatives-trading-usds-futures 7.0.2 → 9.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 CHANGED
@@ -298,6 +298,40 @@ Choose between `single` and `pool` connection modes for WebSocket Streams. The `
298
298
 
299
299
  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.
300
300
 
301
+ #### Subscribe to User Data Streams
302
+
303
+ You can consume the user data stream, which sends account-level events such as account and order updates. First create a listen-key via REST or WebSocket API; then:
304
+
305
+ ```typescript
306
+ import { DerivativesTradingUsdsFutures, DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL } from '@binance/derivatives-trading-usds-futures';
307
+
308
+ const configurationWebsocketStreams = {
309
+ wsURL: DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL,
310
+ };
311
+ const client = new DerivativesTradingUsdsFutures({ configurationWebsocketStreams });
312
+
313
+ client.websocketStreams
314
+ .connect()
315
+ .then((connection) => {
316
+ const stream = connection.userData('listenKey');
317
+ stream.on('message', (data) => {
318
+ switch (data.e) {
319
+ case 'ACCOUNT_CONFIG_UPDATE':
320
+ console.log('account config update stream', data);
321
+ break;
322
+ case 'ORDER_TRADE_UPDATE':
323
+ console.log('order trade update stream', data);
324
+ break;
325
+ // …handle other variants…
326
+ default:
327
+ console.log('unknown stream', data);
328
+ break;
329
+ }
330
+ });
331
+ })
332
+ .catch((err) => console.error(err));
333
+ ```
334
+
301
335
  #### Unsubscribing from Streams
302
336
 
303
337
  You can unsubscribe from specific WebSocket streams using the `unsubscribe` method. This is useful for managing active subscriptions without closing the connection.