@binance/derivatives-trading-portfolio-margin 4.0.2 → 5.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/dist/index.mjs CHANGED
@@ -8,12 +8,14 @@ var __export = (target, all) => {
8
8
  import {
9
9
  buildUserAgent,
10
10
  ConfigurationRestAPI as ConfigurationRestAPI6,
11
- DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL
11
+ ConfigurationWebsocketStreams as ConfigurationWebsocketStreams2,
12
+ DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL,
13
+ DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL
12
14
  } from "@binance/common";
13
15
 
14
16
  // package.json
15
17
  var name = "@binance/derivatives-trading-portfolio-margin";
16
- var version = "4.0.2";
18
+ var version = "5.0.0";
17
19
 
18
20
  // src/rest-api/index.ts
19
21
  var rest_api_exports = {};
@@ -3130,6 +3132,8 @@ var TradeApiAxiosParamCreator = function(configuration) {
3130
3132
  * `OrderId` can only be sent together with symbol
3131
3133
  * If a `pair` is sent, tickers for all symbols of the `pair` will be returned
3132
3134
  * The parameter `fromId` cannot be sent with `startTime` or `endTime`
3135
+ * If `startTime` and `endTime` are both not sent, then the last '24 hours' data will be returned.
3136
+ * The time between `startTime` and `endTime` cannot be longer than 24 hours.
3133
3137
  *
3134
3138
  * Weight: 20 with symbol, 40 with pair
3135
3139
  *
@@ -5236,8 +5240,8 @@ var TradeApiAxiosParamCreator = function(configuration) {
5236
5240
  * Get trades for a specific account and UM symbol.
5237
5241
  *
5238
5242
  *
5239
- * If `startTime` and `endTime` are both not sent, then the last '24 hours' data will be returned.
5240
- * The time between `startTime` and `endTime` cannot be longer than 24 hours.
5243
+ * If `startTime` and `endTime` are both not sent, then the last '7 days' data will be returned.
5244
+ * The time between `startTime` and `endTime` cannot be longer than 7 days.
5241
5245
  * The parameter `fromId` cannot be sent with `startTime` or `endTime`.
5242
5246
  *
5243
5247
  * Weight: 5
@@ -5645,6 +5649,8 @@ var TradeApi = class {
5645
5649
  * `OrderId` can only be sent together with symbol
5646
5650
  * If a `pair` is sent, tickers for all symbols of the `pair` will be returned
5647
5651
  * The parameter `fromId` cannot be sent with `startTime` or `endTime`
5652
+ * If `startTime` and `endTime` are both not sent, then the last '24 hours' data will be returned.
5653
+ * The time between `startTime` and `endTime` cannot be longer than 24 hours.
5648
5654
  *
5649
5655
  * Weight: 20 with symbol, 40 with pair
5650
5656
  *
@@ -7117,8 +7123,8 @@ var TradeApi = class {
7117
7123
  * Get trades for a specific account and UM symbol.
7118
7124
  *
7119
7125
  *
7120
- * If `startTime` and `endTime` are both not sent, then the last '24 hours' data will be returned.
7121
- * The time between `startTime` and `endTime` cannot be longer than 24 hours.
7126
+ * If `startTime` and `endTime` are both not sent, then the last '7 days' data will be returned.
7127
+ * The time between `startTime` and `endTime` cannot be longer than 7 days.
7122
7128
  * The parameter `fromId` cannot be sent with `startTime` or `endTime`.
7123
7129
  *
7124
7130
  * Weight: 5
@@ -8482,6 +8488,8 @@ var RestAPI = class {
8482
8488
  * `OrderId` can only be sent together with symbol
8483
8489
  * If a `pair` is sent, tickers for all symbols of the `pair` will be returned
8484
8490
  * The parameter `fromId` cannot be sent with `startTime` or `endTime`
8491
+ * If `startTime` and `endTime` are both not sent, then the last '24 hours' data will be returned.
8492
+ * The time between `startTime` and `endTime` cannot be longer than 24 hours.
8485
8493
  *
8486
8494
  * Weight: 20 with symbol, 40 with pair
8487
8495
  *
@@ -9272,8 +9280,8 @@ var RestAPI = class {
9272
9280
  * Get trades for a specific account and UM symbol.
9273
9281
  *
9274
9282
  *
9275
- * If `startTime` and `endTime` are both not sent, then the last '24 hours' data will be returned.
9276
- * The time between `startTime` and `endTime` cannot be longer than 24 hours.
9283
+ * If `startTime` and `endTime` are both not sent, then the last '7 days' data will be returned.
9284
+ * The time between `startTime` and `endTime` cannot be longer than 7 days.
9277
9285
  * The parameter `fromId` cannot be sent with `startTime` or `endTime`.
9278
9286
  *
9279
9287
  * Weight: 5
@@ -9349,6 +9357,134 @@ var RestAPI = class {
9349
9357
  }
9350
9358
  };
9351
9359
 
9360
+ // src/websocket-streams/index.ts
9361
+ var websocket_streams_exports = {};
9362
+ __export(websocket_streams_exports, {
9363
+ WebsocketStreams: () => WebsocketStreams,
9364
+ WebsocketStreamsConnection: () => WebsocketStreamsConnection
9365
+ });
9366
+
9367
+ // src/websocket-streams/websocket-streams.ts
9368
+ import { WebsocketStreamsBase as WebsocketStreamsBase2 } from "@binance/common";
9369
+
9370
+ // src/websocket-streams/websocket-streams-connection.ts
9371
+ import { createStreamHandler } from "@binance/common";
9372
+ var WebsocketStreamsConnection = class {
9373
+ constructor(websocketBase) {
9374
+ this.websocketBase = websocketBase;
9375
+ }
9376
+ /**
9377
+ * Adds an event listener for the specified WebSocket event.
9378
+ * @param event - The WebSocket event to listen for, such as 'open', 'message', 'error', 'close', 'ping', or 'pong'.
9379
+ * @param listener - The callback function to be executed when the event is triggered. The function can accept any number of arguments.
9380
+ */
9381
+ on(event, listener) {
9382
+ this.websocketBase.on(event, listener);
9383
+ }
9384
+ /**
9385
+ * Removes an event listener for the specified WebSocket event.
9386
+ * @param event - The WebSocket event to stop listening for, such as 'open', 'message', 'error', 'close', 'ping', or 'pong'.
9387
+ * @param listener - The callback function that was previously added as the event listener.
9388
+ */
9389
+ off(event, listener) {
9390
+ this.websocketBase.off(event, listener);
9391
+ }
9392
+ /**
9393
+ * Disconnects from the WebSocket server.
9394
+ * If there is no active connection, a warning is logged.
9395
+ * Otherwise, all connections in the connection pool are closed gracefully,
9396
+ * and a message is logged indicating that the connection has been disconnected.
9397
+ * @returns A Promise that resolves when all connections have been closed.
9398
+ * @throws Error if the WebSocket client is not set.
9399
+ */
9400
+ disconnect() {
9401
+ return this.websocketBase.disconnect();
9402
+ }
9403
+ /**
9404
+ * Checks if the WebSocket connection is currently open.
9405
+ * @returns `true` if the connection is open, `false` otherwise.
9406
+ */
9407
+ isConnected() {
9408
+ return this.websocketBase.isConnected();
9409
+ }
9410
+ /**
9411
+ * Sends a ping message to all connected Websocket servers in the pool.
9412
+ * If no connections are ready, a warning is logged.
9413
+ * For each active connection, the ping message is sent, and debug logs provide details.
9414
+ * @throws Error if a Websocket client is not set for a connection.
9415
+ */
9416
+ pingServer() {
9417
+ this.websocketBase.pingServer();
9418
+ }
9419
+ /**
9420
+ * Subscribes to one or multiple WebSocket streams
9421
+ * Handles both single and pool modes
9422
+ * @param stream Single stream name or array of stream names to subscribe to
9423
+ * @param id Optional subscription ID
9424
+ * @returns void
9425
+ */
9426
+ subscribe(stream, id) {
9427
+ this.websocketBase.subscribe(stream, id);
9428
+ }
9429
+ /**
9430
+ * Unsubscribes from one or multiple WebSocket streams
9431
+ * Handles both single and pool modes
9432
+ * @param stream Single stream name or array of stream names to unsubscribe from
9433
+ * @param id Optional unsubscription ID
9434
+ * @returns void
9435
+ */
9436
+ unsubscribe(stream, id) {
9437
+ this.websocketBase.unsubscribe(stream, id);
9438
+ }
9439
+ /**
9440
+ * Checks if the WebSocket connection is subscribed to the specified stream.
9441
+ * @param stream The name of the WebSocket stream to check.
9442
+ * @returns `true` if the connection is subscribed to the stream, `false` otherwise.
9443
+ */
9444
+ isSubscribed(stream) {
9445
+ return this.websocketBase.isSubscribed(stream);
9446
+ }
9447
+ /**
9448
+ * Subscribes to the user data WebSocket stream using the provided listen key.
9449
+ * @param listenKey - The listen key for the user data WebSocket stream.
9450
+ * @param id - Optional user data stream ID
9451
+ * @returns A WebSocket stream handler for the user data stream.
9452
+ */
9453
+ userData(listenKey, id) {
9454
+ return createStreamHandler(this.websocketBase, listenKey, id);
9455
+ }
9456
+ };
9457
+
9458
+ // src/websocket-streams/websocket-streams.ts
9459
+ var WebsocketStreams = class {
9460
+ constructor(configuration) {
9461
+ this.configuration = configuration;
9462
+ }
9463
+ /**
9464
+ * Connects to the Binance WebSocket streams and returns a `WebsocketStreamsConnection` instance.
9465
+ *
9466
+ * @param {object} [options] - Optional connection options.
9467
+ * @param {string|string[]} [options.stream] - The stream(s) to connect to.
9468
+ * @param {'single'|'pool'} [options.mode] - The connection mode, either 'single' or 'pool'. Overwrite the `mode` option in the configuration.
9469
+ * @param {number} [options.poolSize] - The number of connections to use in pool mode. Overwrite the `poolSize` option in the configuration.
9470
+ * @returns {Promise<WebsocketStreamsConnection>} - A promise that resolves to a `WebsocketStreamsConnection` instance.
9471
+ */
9472
+ async connect({
9473
+ stream,
9474
+ mode,
9475
+ poolSize
9476
+ } = {}) {
9477
+ const websocketBase = new WebsocketStreamsBase2({
9478
+ ...this.configuration,
9479
+ ...mode && { mode },
9480
+ ...poolSize && { poolSize }
9481
+ });
9482
+ const websocketStreamsConnection = new WebsocketStreamsConnection(websocketBase);
9483
+ await websocketBase.connect(stream);
9484
+ return websocketStreamsConnection;
9485
+ }
9486
+ };
9487
+
9352
9488
  // src/derivatives-trading-portfolio-margin.ts
9353
9489
  var DerivativesTradingPortfolioMargin = class {
9354
9490
  constructor(config) {
@@ -9365,6 +9501,14 @@ var DerivativesTradingPortfolioMargin = class {
9365
9501
  };
9366
9502
  this.restAPI = new RestAPI(configRestAPI);
9367
9503
  }
9504
+ if (config?.configurationWebsocketStreams) {
9505
+ const configWebsocketStreams = new ConfigurationWebsocketStreams2(
9506
+ config.configurationWebsocketStreams
9507
+ );
9508
+ configWebsocketStreams.wsURL = configWebsocketStreams.wsURL || DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL;
9509
+ configWebsocketStreams.userAgent = userAgent;
9510
+ this.websocketStreams = new WebsocketStreams(configWebsocketStreams);
9511
+ }
9368
9512
  }
9369
9513
  };
9370
9514
 
@@ -9372,6 +9516,8 @@ var DerivativesTradingPortfolioMargin = class {
9372
9516
  import {
9373
9517
  DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL as DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL2,
9374
9518
  DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL,
9519
+ DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL as DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL2,
9520
+ DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_TESTNET_URL,
9375
9521
  ConnectorClientError,
9376
9522
  RequiredError,
9377
9523
  UnauthorizedError,
@@ -9388,8 +9534,11 @@ export {
9388
9534
  ConnectorClientError,
9389
9535
  DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL2 as DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_PROD_URL,
9390
9536
  DERIVATIVES_TRADING_PORTFOLIO_MARGIN_REST_API_TESTNET_URL,
9537
+ DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL2 as DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_PROD_URL,
9538
+ DERIVATIVES_TRADING_PORTFOLIO_MARGIN_WS_STREAMS_TESTNET_URL,
9391
9539
  DerivativesTradingPortfolioMargin,
9392
9540
  rest_api_exports as DerivativesTradingPortfolioMarginRestAPI,
9541
+ websocket_streams_exports as DerivativesTradingPortfolioMarginWebsocketStreams,
9393
9542
  ForbiddenError,
9394
9543
  NetworkError,
9395
9544
  NotFoundError,