@adaptic/utils 0.0.934 → 0.0.935

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
@@ -7631,6 +7631,14 @@ const MASSIVE_API_KEY = process.env.MASSIVE_API_KEY;
7631
7631
  // Define concurrency limits per API
7632
7632
  const MASSIVE_CONCURRENCY_LIMIT = 100;
7633
7633
  const massiveLimit = pLimit(MASSIVE_CONCURRENCY_LIMIT);
7634
+ /**
7635
+ * In-flight request deduplication for fetchLastTrade.
7636
+ * When multiple callers request the same symbol simultaneously (e.g. 10 options
7637
+ * contracts all need the AMD underlying price), only one actual HTTP request is
7638
+ * made. All callers share the same Promise. The entry is removed when the
7639
+ * request settles, so subsequent calls after resolution make a fresh request.
7640
+ */
7641
+ const fetchLastTradeInflight = new Map();
7634
7642
  // Use to update general information about stocks
7635
7643
  /**
7636
7644
  * Fetches general information about a stock ticker.
@@ -7728,6 +7736,25 @@ const fetchTickerInfo = async (symbol, options) => {
7728
7736
  * @returns {Promise<MassiveQuote>} The last trade information.
7729
7737
  */
7730
7738
  const fetchLastTrade = async (symbol, options) => {
7739
+ // Coalesce concurrent requests for the same symbol.
7740
+ // If a request is already in-flight, return the shared promise.
7741
+ const inflight = fetchLastTradeInflight.get(symbol);
7742
+ if (inflight) {
7743
+ return inflight;
7744
+ }
7745
+ const promise = fetchLastTradeImpl(symbol, options);
7746
+ fetchLastTradeInflight.set(symbol, promise);
7747
+ try {
7748
+ return await promise;
7749
+ }
7750
+ finally {
7751
+ fetchLastTradeInflight.delete(symbol);
7752
+ }
7753
+ };
7754
+ /**
7755
+ * Internal implementation of fetchLastTrade (called once per dedup window).
7756
+ */
7757
+ const fetchLastTradeImpl = async (symbol, options) => {
7731
7758
  if (!options?.apiKey && !MASSIVE_API_KEY) {
7732
7759
  throw new Error("Massive API key is missing");
7733
7760
  }