@adaptic/utils 0.0.1025 → 0.0.1026

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.cjs CHANGED
@@ -3657,6 +3657,23 @@ const DEFAULT_ADJUSTMENT = "all";
3657
3657
  // `feed` argument on getOptions*/getLatestBars/etc.) still win.
3658
3658
  const DEFAULT_FEED$1 = (process.env.ALPACA_MARKET_DATA_FEED || "iex");
3659
3659
  const DEFAULT_CURRENCY$1 = "USD";
3660
+ /** Close code that the close handler treats as "do not reconnect". */
3661
+ const INTENTIONAL_CLOSE_CODE = 1000;
3662
+ /** Reason text carried on an intentional close, for server-side logs. */
3663
+ const INTENTIONAL_CLOSE_REASON = "intentional disconnect";
3664
+ /**
3665
+ * Close a stream, optionally in the way the close handler treats as final.
3666
+ *
3667
+ * @param ws - The socket to close.
3668
+ * @param options - Whether this close is intentional.
3669
+ */
3670
+ function closeStream(ws, options) {
3671
+ if (options.intentional === true) {
3672
+ ws.close(INTENTIONAL_CLOSE_CODE, INTENTIONAL_CLOSE_REASON);
3673
+ return;
3674
+ }
3675
+ ws.close();
3676
+ }
3660
3677
  /**
3661
3678
  * Singleton class for interacting with Alpaca Market Data API
3662
3679
  * Provides methods for fetching historical bars, latest bars, last trades, latest trades, latest quotes, and latest quote for a single symbol
@@ -4042,19 +4059,19 @@ class AlpacaMarketDataAPI extends require$$0$1.EventEmitter {
4042
4059
  this.connect("crypto");
4043
4060
  }
4044
4061
  }
4045
- disconnectStockStream() {
4062
+ disconnectStockStream(options = {}) {
4046
4063
  if (this.stockWs) {
4047
- this.stockWs.close();
4064
+ closeStream(this.stockWs, options);
4048
4065
  }
4049
4066
  }
4050
- disconnectOptionStream() {
4067
+ disconnectOptionStream(options = {}) {
4051
4068
  if (this.optionWs) {
4052
- this.optionWs.close();
4069
+ closeStream(this.optionWs, options);
4053
4070
  }
4054
4071
  }
4055
- disconnectCryptoStream() {
4072
+ disconnectCryptoStream(options = {}) {
4056
4073
  if (this.cryptoWs) {
4057
- this.cryptoWs.close();
4074
+ closeStream(this.cryptoWs, options);
4058
4075
  }
4059
4076
  }
4060
4077
  /**