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