@adaptic/utils 0.0.1024 → 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/test.js CHANGED
@@ -2143,6 +2143,23 @@ const DEFAULT_ADJUSTMENT = "all";
2143
2143
  // `feed` argument on getOptions*/getLatestBars/etc.) still win.
2144
2144
  const DEFAULT_FEED = (process.env.ALPACA_MARKET_DATA_FEED || "iex");
2145
2145
  const DEFAULT_CURRENCY = "USD";
2146
+ /** Close code that the close handler treats as "do not reconnect". */
2147
+ const INTENTIONAL_CLOSE_CODE = 1000;
2148
+ /** Reason text carried on an intentional close, for server-side logs. */
2149
+ const INTENTIONAL_CLOSE_REASON = "intentional disconnect";
2150
+ /**
2151
+ * Close a stream, optionally in the way the close handler treats as final.
2152
+ *
2153
+ * @param ws - The socket to close.
2154
+ * @param options - Whether this close is intentional.
2155
+ */
2156
+ function closeStream(ws, options) {
2157
+ if (options.intentional === true) {
2158
+ ws.close(INTENTIONAL_CLOSE_CODE, INTENTIONAL_CLOSE_REASON);
2159
+ return;
2160
+ }
2161
+ ws.close();
2162
+ }
2146
2163
  /**
2147
2164
  * Singleton class for interacting with Alpaca Market Data API
2148
2165
  * Provides methods for fetching historical bars, latest bars, last trades, latest trades, latest quotes, and latest quote for a single symbol
@@ -2528,19 +2545,19 @@ class AlpacaMarketDataAPI extends EventEmitter {
2528
2545
  this.connect("crypto");
2529
2546
  }
2530
2547
  }
2531
- disconnectStockStream() {
2548
+ disconnectStockStream(options = {}) {
2532
2549
  if (this.stockWs) {
2533
- this.stockWs.close();
2550
+ closeStream(this.stockWs, options);
2534
2551
  }
2535
2552
  }
2536
- disconnectOptionStream() {
2553
+ disconnectOptionStream(options = {}) {
2537
2554
  if (this.optionWs) {
2538
- this.optionWs.close();
2555
+ closeStream(this.optionWs, options);
2539
2556
  }
2540
2557
  }
2541
- disconnectCryptoStream() {
2558
+ disconnectCryptoStream(options = {}) {
2542
2559
  if (this.cryptoWs) {
2543
- this.cryptoWs.close();
2560
+ closeStream(this.cryptoWs, options);
2544
2561
  }
2545
2562
  }
2546
2563
  /**