@adaptic/utils 0.0.912 → 0.0.913
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/README.md +2 -2
- package/dist/index.cjs +96 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +85 -85
- package/dist/index.mjs.map +1 -1
- package/dist/types/cache/stampede-protected-cache.d.ts +2 -2
- package/dist/types/errors/index.d.ts +3 -3
- package/dist/types/index.d.ts +37 -37
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/massive-indices.d.ts +19 -19
- package/dist/types/massive-indices.d.ts.map +1 -1
- package/dist/types/massive.d.ts +17 -17
- package/dist/types/massive.d.ts.map +1 -1
- package/dist/types/misc-utils.d.ts +1 -1
- package/dist/types/rate-limiter.d.ts +1 -1
- package/dist/types/schemas/index.d.ts +5 -5
- package/dist/types/schemas/index.d.ts.map +1 -1
- package/dist/types/schemas/massive-schemas.d.ts +19 -19
- package/dist/types/technical-analysis.d.ts +9 -10
- package/dist/types/technical-analysis.d.ts.map +1 -1
- package/dist/types/types/massive-indices-types.d.ts +19 -19
- package/dist/types/types/massive-types.d.ts +21 -21
- package/dist/types/utils/auth-validator.d.ts +3 -3
- package/dist/types/utils/paginator.d.ts +1 -1
- package/dist/types/utils/retry.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -387,7 +387,7 @@ Fetches historical bar data for crypto trading pairs.
|
|
|
387
387
|
|
|
388
388
|
## Market Data Functions
|
|
389
389
|
|
|
390
|
-
### `
|
|
390
|
+
### `fetchMassivePrices(symbol: string, params: object): Promise<MassivePriceData[]>`
|
|
391
391
|
|
|
392
392
|
Fetches historical price data from Massive.com.
|
|
393
393
|
|
|
@@ -398,7 +398,7 @@ Fetches historical price data from Massive.com.
|
|
|
398
398
|
|
|
399
399
|
**Returns:**
|
|
400
400
|
|
|
401
|
-
- `Promise<
|
|
401
|
+
- `Promise<MassivePriceData[]>`:
|
|
402
402
|
```typescript
|
|
403
403
|
{
|
|
404
404
|
date: string;
|
package/dist/index.cjs
CHANGED
|
@@ -2056,13 +2056,13 @@ function validateAlpacaCredentials(auth, options = { throwOnMissing: true }) {
|
|
|
2056
2056
|
return true;
|
|
2057
2057
|
}
|
|
2058
2058
|
/**
|
|
2059
|
-
* Validates
|
|
2060
|
-
* @param apiKey -
|
|
2059
|
+
* Validates Massive API key
|
|
2060
|
+
* @param apiKey - Massive API key
|
|
2061
2061
|
* @throws {Error} If API key is invalid or missing
|
|
2062
2062
|
*/
|
|
2063
|
-
function
|
|
2063
|
+
function validateMassiveApiKey$1(apiKey) {
|
|
2064
2064
|
if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) {
|
|
2065
|
-
throw new Error("Invalid
|
|
2065
|
+
throw new Error("Invalid Massive API key: must be a non-empty string");
|
|
2066
2066
|
}
|
|
2067
2067
|
}
|
|
2068
2068
|
/**
|
|
@@ -5137,7 +5137,7 @@ function calculateBackoff(attempt, baseDelay, maxDelay) {
|
|
|
5137
5137
|
* @template T - The return type of the wrapped function
|
|
5138
5138
|
* @param fn - The async function to wrap with retry logic
|
|
5139
5139
|
* @param config - Retry configuration (merged with defaults)
|
|
5140
|
-
* @param label - A descriptive label for logging (e.g., '
|
|
5140
|
+
* @param label - A descriptive label for logging (e.g., 'Massive.fetchTickerInfo')
|
|
5141
5141
|
* @returns A promise that resolves to the function's return value
|
|
5142
5142
|
* @throws The last error encountered if all retries are exhausted
|
|
5143
5143
|
*
|
|
@@ -5430,7 +5430,7 @@ async function fetchWithRetry(url, options = {}, retries = 3, initialBackoff = 1
|
|
|
5430
5430
|
* @param apiKey - The API key to validate.
|
|
5431
5431
|
* @returns Promise that resolves to true if valid, false otherwise.
|
|
5432
5432
|
*/
|
|
5433
|
-
async function
|
|
5433
|
+
async function validateMassiveApiKey(apiKey) {
|
|
5434
5434
|
try {
|
|
5435
5435
|
const response = await fetch(`https://api.massive.com/v1/meta/symbols?apikey=${apiKey}&limit=1`);
|
|
5436
5436
|
if (response.status === 401) {
|
|
@@ -7051,7 +7051,7 @@ function dateTimeForGS(date) {
|
|
|
7051
7051
|
* Massive.com calls
|
|
7052
7052
|
**********************************************************************************/
|
|
7053
7053
|
/**
|
|
7054
|
-
* Set of
|
|
7054
|
+
* Set of Massive API response statuses that indicate valid, usable data.
|
|
7055
7055
|
* "OK" = real-time data, "DELAYED" = delayed data (still valid, e.g. free-tier plans).
|
|
7056
7056
|
*/
|
|
7057
7057
|
const MASSIVE_VALID_STATUSES = new Set(["OK", "DELAYED"]);
|
|
@@ -7066,14 +7066,14 @@ const massiveLimit = pLimit(MASSIVE_CONCURRENCY_LIMIT);
|
|
|
7066
7066
|
* @param {string} symbol - The stock ticker symbol to fetch information for.
|
|
7067
7067
|
* @param {Object} [options] - Optional parameters.
|
|
7068
7068
|
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
7069
|
-
* @returns {Promise<
|
|
7069
|
+
* @returns {Promise<MassiveTickerInfo | null>} The ticker information or null if not found.
|
|
7070
7070
|
*/
|
|
7071
7071
|
const fetchTickerInfo = async (symbol, options) => {
|
|
7072
7072
|
if (!options?.apiKey && !MASSIVE_API_KEY) {
|
|
7073
|
-
throw new Error("
|
|
7073
|
+
throw new Error("Massive API key is missing");
|
|
7074
7074
|
}
|
|
7075
7075
|
const apiKey = options?.apiKey || MASSIVE_API_KEY;
|
|
7076
|
-
|
|
7076
|
+
validateMassiveApiKey$1(apiKey);
|
|
7077
7077
|
const baseUrl = `https://api.massive.com/v3/reference/tickers/${encodeURIComponent(symbol)}`;
|
|
7078
7078
|
const params = new URLSearchParams({
|
|
7079
7079
|
apiKey,
|
|
@@ -7090,7 +7090,7 @@ const fetchTickerInfo = async (symbol, options) => {
|
|
|
7090
7090
|
// Map the results to the required structure
|
|
7091
7091
|
const results = data.results;
|
|
7092
7092
|
if (!results) {
|
|
7093
|
-
throw new Error("No results in
|
|
7093
|
+
throw new Error("No results in Massive API response");
|
|
7094
7094
|
}
|
|
7095
7095
|
// Validate required fields
|
|
7096
7096
|
const requiredFields = [
|
|
@@ -7105,7 +7105,7 @@ const fetchTickerInfo = async (symbol, options) => {
|
|
|
7105
7105
|
];
|
|
7106
7106
|
for (const field of requiredFields) {
|
|
7107
7107
|
if (results[field] === undefined) {
|
|
7108
|
-
throw new Error(`Missing required field in
|
|
7108
|
+
throw new Error(`Missing required field in Massive API response: ${field}`);
|
|
7109
7109
|
}
|
|
7110
7110
|
}
|
|
7111
7111
|
// Handle optional share_class_shares_outstanding field
|
|
@@ -7140,7 +7140,7 @@ const fetchTickerInfo = async (symbol, options) => {
|
|
|
7140
7140
|
? "NETWORK_ERROR"
|
|
7141
7141
|
: "UNKNOWN",
|
|
7142
7142
|
url: hideApiKeyFromurl(`${baseUrl}?${params.toString()}`),
|
|
7143
|
-
source: "
|
|
7143
|
+
source: "MassiveAPI.fetchTickerInfo",
|
|
7144
7144
|
timestamp: new Date().toISOString(),
|
|
7145
7145
|
});
|
|
7146
7146
|
throw new Error(`${contextualMessage}: ${errorMessage}`);
|
|
@@ -7153,14 +7153,14 @@ const fetchTickerInfo = async (symbol, options) => {
|
|
|
7153
7153
|
* @param {string} symbol - The stock ticker symbol to fetch the last trade for.
|
|
7154
7154
|
* @param {Object} [options] - Optional parameters.
|
|
7155
7155
|
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
7156
|
-
* @returns {Promise<
|
|
7156
|
+
* @returns {Promise<MassiveQuote>} The last trade information.
|
|
7157
7157
|
*/
|
|
7158
7158
|
const fetchLastTrade = async (symbol, options) => {
|
|
7159
7159
|
if (!options?.apiKey && !MASSIVE_API_KEY) {
|
|
7160
|
-
throw new Error("
|
|
7160
|
+
throw new Error("Massive API key is missing");
|
|
7161
7161
|
}
|
|
7162
7162
|
const apiKey = options?.apiKey || MASSIVE_API_KEY;
|
|
7163
|
-
|
|
7163
|
+
validateMassiveApiKey$1(apiKey);
|
|
7164
7164
|
const baseUrl = `https://api.massive.com/v2/last/trade/${encodeURIComponent(symbol)}`;
|
|
7165
7165
|
const params = new URLSearchParams({
|
|
7166
7166
|
apiKey,
|
|
@@ -7198,14 +7198,14 @@ const fetchLastTrade = async (symbol, options) => {
|
|
|
7198
7198
|
? "NETWORK_ERROR"
|
|
7199
7199
|
: "UNKNOWN",
|
|
7200
7200
|
url: hideApiKeyFromurl(`${baseUrl}?${params.toString()}`),
|
|
7201
|
-
source: "
|
|
7201
|
+
source: "MassiveAPI.fetchLastTrade",
|
|
7202
7202
|
timestamp: new Date().toISOString(),
|
|
7203
7203
|
});
|
|
7204
7204
|
throw new Error(`${contextualMessage}: ${errorMessage}`);
|
|
7205
7205
|
}
|
|
7206
7206
|
});
|
|
7207
7207
|
};
|
|
7208
|
-
// use
|
|
7208
|
+
// use Massive for all price data fetching
|
|
7209
7209
|
/**
|
|
7210
7210
|
* Fetches price data for a given stock ticker.
|
|
7211
7211
|
* @param {Object} params - The parameters for fetching price data.
|
|
@@ -7217,14 +7217,14 @@ const fetchLastTrade = async (symbol, options) => {
|
|
|
7217
7217
|
* @param {number} [params.limit] - The maximum number of price data points to fetch.
|
|
7218
7218
|
* @param {Object} [options] - Optional parameters.
|
|
7219
7219
|
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
7220
|
-
* @returns {Promise<
|
|
7220
|
+
* @returns {Promise<MassivePriceData[]>} The fetched price data.
|
|
7221
7221
|
*/
|
|
7222
7222
|
const fetchPrices = async (params, options) => {
|
|
7223
7223
|
if (!options?.apiKey && !MASSIVE_API_KEY) {
|
|
7224
|
-
throw new Error("
|
|
7224
|
+
throw new Error("Massive API key is missing");
|
|
7225
7225
|
}
|
|
7226
7226
|
const apiKey = options?.apiKey || MASSIVE_API_KEY;
|
|
7227
|
-
|
|
7227
|
+
validateMassiveApiKey$1(apiKey);
|
|
7228
7228
|
const { ticker, start, end = Date.now().valueOf(), multiplier, timespan, limit = 1000, } = params;
|
|
7229
7229
|
const baseUrl = `https://api.massive.com/v2/aggs/ticker/${encodeURIComponent(ticker)}/range/${multiplier}/${timespan}/${start}/${end}`;
|
|
7230
7230
|
const urlParams = new URLSearchParams({
|
|
@@ -7245,7 +7245,7 @@ const fetchPrices = async (params, options) => {
|
|
|
7245
7245
|
throw new Error(`Massive.com API responded with status: ${data.status}`);
|
|
7246
7246
|
}
|
|
7247
7247
|
if (data.status === "DELAYED") {
|
|
7248
|
-
getLogger().warn(`Massive.com returned DELAYED data for ${params.ticker} — using delayed results`, { ticker: params.ticker, source: "
|
|
7248
|
+
getLogger().warn(`Massive.com returned DELAYED data for ${params.ticker} — using delayed results`, { ticker: params.ticker, source: "MassiveAPI.fetchPrices" });
|
|
7249
7249
|
}
|
|
7250
7250
|
if (data.results) {
|
|
7251
7251
|
allResults = [...allResults, ...data.results];
|
|
@@ -7288,7 +7288,7 @@ const fetchPrices = async (params, options) => {
|
|
|
7288
7288
|
error.message.includes("NETWORK_ERROR")
|
|
7289
7289
|
? "NETWORK_ERROR"
|
|
7290
7290
|
: "UNKNOWN",
|
|
7291
|
-
source: "
|
|
7291
|
+
source: "MassiveAPI.fetchPrices",
|
|
7292
7292
|
timestamp: new Date().toISOString(),
|
|
7293
7293
|
});
|
|
7294
7294
|
throw new Error(`${contextualMessage}: ${errorMessage}`);
|
|
@@ -7297,10 +7297,10 @@ const fetchPrices = async (params, options) => {
|
|
|
7297
7297
|
};
|
|
7298
7298
|
/**
|
|
7299
7299
|
* Analyzes the price data for a given stock.
|
|
7300
|
-
* @param {
|
|
7300
|
+
* @param {MassivePriceData[]} priceData - The price data to analyze.
|
|
7301
7301
|
* @returns {string} The analysis report.
|
|
7302
7302
|
*/
|
|
7303
|
-
function
|
|
7303
|
+
function analyseMassivePriceData(priceData) {
|
|
7304
7304
|
if (!priceData || priceData.length === 0) {
|
|
7305
7305
|
return "No price data available for analysis.";
|
|
7306
7306
|
}
|
|
@@ -7342,11 +7342,11 @@ Report:
|
|
|
7342
7342
|
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
7343
7343
|
* @param {boolean} [options.adjusted] - Whether to adjust the data.
|
|
7344
7344
|
* @param {boolean} [options.includeOTC] - Whether to include OTC data.
|
|
7345
|
-
* @returns {Promise<
|
|
7345
|
+
* @returns {Promise<MassiveGroupedDailyResponse>} The grouped daily response.
|
|
7346
7346
|
*/
|
|
7347
7347
|
const fetchGroupedDaily = async (date, options) => {
|
|
7348
7348
|
if (!options?.apiKey && !MASSIVE_API_KEY) {
|
|
7349
|
-
throw new Error("
|
|
7349
|
+
throw new Error("Massive API key is missing");
|
|
7350
7350
|
}
|
|
7351
7351
|
const baseUrl = `https://api.massive.com/v2/aggs/grouped/locale/us/market/stocks/${date}`;
|
|
7352
7352
|
const params = new URLSearchParams({
|
|
@@ -7394,7 +7394,7 @@ const fetchGroupedDaily = async (date, options) => {
|
|
|
7394
7394
|
? "NETWORK_ERROR"
|
|
7395
7395
|
: "UNKNOWN",
|
|
7396
7396
|
url: hideApiKeyFromurl(`${baseUrl}?${params.toString()}`),
|
|
7397
|
-
source: "
|
|
7397
|
+
source: "MassiveAPI.fetchGroupedDaily",
|
|
7398
7398
|
timestamp: new Date().toISOString(),
|
|
7399
7399
|
});
|
|
7400
7400
|
throw new Error(`${contextualMessage}: ${errorMessage}`);
|
|
@@ -7403,7 +7403,7 @@ const fetchGroupedDaily = async (date, options) => {
|
|
|
7403
7403
|
};
|
|
7404
7404
|
/**
|
|
7405
7405
|
* Formats the price data into a readable string.
|
|
7406
|
-
* @param {
|
|
7406
|
+
* @param {MassivePriceData[]} priceData - The price data to format.
|
|
7407
7407
|
* @returns {string} The formatted price data.
|
|
7408
7408
|
*/
|
|
7409
7409
|
function formatPriceData(priceData) {
|
|
@@ -7434,11 +7434,11 @@ const fetchDailyOpenClose = async (
|
|
|
7434
7434
|
* @param {Object} [options] - Optional parameters.
|
|
7435
7435
|
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
7436
7436
|
* @param {boolean} [options.adjusted] - Whether to adjust the data.
|
|
7437
|
-
* @returns {Promise<
|
|
7437
|
+
* @returns {Promise<MassiveDailyOpenClose>} The daily open and close data.
|
|
7438
7438
|
*/
|
|
7439
7439
|
symbol, date = new Date(), options) => {
|
|
7440
7440
|
if (!options?.apiKey && !MASSIVE_API_KEY) {
|
|
7441
|
-
throw new Error("
|
|
7441
|
+
throw new Error("Massive API key is missing");
|
|
7442
7442
|
}
|
|
7443
7443
|
const formattedDate = date.toISOString().split("T")[0]; // Format as YYYY-MM-DD
|
|
7444
7444
|
const baseUrl = `https://api.massive.com/v1/open-close/${encodeURIComponent(symbol)}/${formattedDate}`;
|
|
@@ -7485,11 +7485,11 @@ async function getPreviousClose$1(symbol, referenceDate, options) {
|
|
|
7485
7485
|
* @param {'asc' | 'desc'} [options.order] - The order of the trades.
|
|
7486
7486
|
* @param {number} [options.limit] - The maximum number of trades to fetch.
|
|
7487
7487
|
* @param {string} [options.sort] - The sort order for the trades.
|
|
7488
|
-
* @returns {Promise<
|
|
7488
|
+
* @returns {Promise<MassiveTradesResponse>} The fetched trades response.
|
|
7489
7489
|
*/
|
|
7490
7490
|
const fetchTrades = async (symbol, options) => {
|
|
7491
7491
|
if (!options?.apiKey && !MASSIVE_API_KEY) {
|
|
7492
|
-
throw new Error("
|
|
7492
|
+
throw new Error("Massive API key is missing");
|
|
7493
7493
|
}
|
|
7494
7494
|
const baseUrl = `https://api.massive.com/v3/trades/${encodeURIComponent(symbol)}`;
|
|
7495
7495
|
const params = new URLSearchParams({
|
|
@@ -7520,7 +7520,7 @@ const fetchTrades = async (symbol, options) => {
|
|
|
7520
7520
|
const data = (await response.json());
|
|
7521
7521
|
if ("message" in data) {
|
|
7522
7522
|
// This is an error response
|
|
7523
|
-
throw new Error(`
|
|
7523
|
+
throw new Error(`Massive API Error: ${data.message}`);
|
|
7524
7524
|
}
|
|
7525
7525
|
return data;
|
|
7526
7526
|
}
|
|
@@ -7538,7 +7538,7 @@ const fetchTrades = async (symbol, options) => {
|
|
|
7538
7538
|
? "NETWORK_ERROR"
|
|
7539
7539
|
: "UNKNOWN",
|
|
7540
7540
|
url: hideApiKeyFromurl(url),
|
|
7541
|
-
source: "
|
|
7541
|
+
source: "MassiveAPI.fetchTrades",
|
|
7542
7542
|
timestamp: new Date().toISOString(),
|
|
7543
7543
|
});
|
|
7544
7544
|
throw new Error(`${contextualMessage}: ${errorMessage}`);
|
|
@@ -7547,7 +7547,7 @@ const fetchTrades = async (symbol, options) => {
|
|
|
7547
7547
|
};
|
|
7548
7548
|
|
|
7549
7549
|
/**
|
|
7550
|
-
*
|
|
7550
|
+
* Massive Indices API Implementation
|
|
7551
7551
|
*
|
|
7552
7552
|
* This module provides functions to interact with the Massive.com Indices API.
|
|
7553
7553
|
*/
|
|
@@ -7556,7 +7556,7 @@ const { ALPACA_INDICES_API_KEY } = process.env;
|
|
|
7556
7556
|
// Define concurrency limits for API
|
|
7557
7557
|
const MASSIVE_INDICES_CONCURRENCY_LIMIT = 5;
|
|
7558
7558
|
const massiveIndicesLimit = pLimit(MASSIVE_INDICES_CONCURRENCY_LIMIT);
|
|
7559
|
-
// Base URL for
|
|
7559
|
+
// Base URL for Massive API
|
|
7560
7560
|
const MASSIVE_API_BASE_URL = "https://api.massive.com";
|
|
7561
7561
|
/**
|
|
7562
7562
|
* Validates that an API key is available
|
|
@@ -7566,17 +7566,17 @@ const MASSIVE_API_BASE_URL = "https://api.massive.com";
|
|
|
7566
7566
|
const validateApiKey = (apiKey) => {
|
|
7567
7567
|
const key = apiKey || ALPACA_INDICES_API_KEY;
|
|
7568
7568
|
if (!key) {
|
|
7569
|
-
throw new Error("
|
|
7569
|
+
throw new Error("Massive Indices API key is missing");
|
|
7570
7570
|
}
|
|
7571
7571
|
return key;
|
|
7572
7572
|
};
|
|
7573
7573
|
/**
|
|
7574
7574
|
* Fetches aggregate bars for an index over a given date range in custom time window sizes.
|
|
7575
7575
|
*
|
|
7576
|
-
* @param {
|
|
7576
|
+
* @param {MassiveIndicesAggregatesParams} params - Parameters for the aggregates request
|
|
7577
7577
|
* @param {Object} [options] - Optional parameters
|
|
7578
7578
|
* @param {string} [options.apiKey] - API key to use for the request
|
|
7579
|
-
* @returns {Promise<
|
|
7579
|
+
* @returns {Promise<MassiveIndicesAggregatesResponse>} The aggregates response
|
|
7580
7580
|
*/
|
|
7581
7581
|
const fetchIndicesAggregates = async (params, options) => {
|
|
7582
7582
|
const apiKey = validateApiKey(options?.apiKey);
|
|
@@ -7596,7 +7596,7 @@ const fetchIndicesAggregates = async (params, options) => {
|
|
|
7596
7596
|
const response = await fetchWithRetry(url.toString(), {}, 3, 300);
|
|
7597
7597
|
const data = await response.json();
|
|
7598
7598
|
if (data.status === "ERROR") {
|
|
7599
|
-
throw new Error(`
|
|
7599
|
+
throw new Error(`Massive API Error: ${data.error}`);
|
|
7600
7600
|
}
|
|
7601
7601
|
return data;
|
|
7602
7602
|
}
|
|
@@ -7612,7 +7612,7 @@ const fetchIndicesAggregates = async (params, options) => {
|
|
|
7612
7612
|
* @param {string} indicesTicker - The ticker symbol of the index
|
|
7613
7613
|
* @param {Object} [options] - Optional parameters
|
|
7614
7614
|
* @param {string} [options.apiKey] - API key to use for the request
|
|
7615
|
-
* @returns {Promise<
|
|
7615
|
+
* @returns {Promise<MassiveIndicesPrevCloseResponse>} The previous close response
|
|
7616
7616
|
*/
|
|
7617
7617
|
const fetchIndicesPreviousClose = async (indicesTicker, options) => {
|
|
7618
7618
|
const apiKey = validateApiKey(options?.apiKey);
|
|
@@ -7625,7 +7625,7 @@ const fetchIndicesPreviousClose = async (indicesTicker, options) => {
|
|
|
7625
7625
|
const response = await fetchWithRetry(url.toString(), {}, 3, 300);
|
|
7626
7626
|
const data = await response.json();
|
|
7627
7627
|
if (data.status === "ERROR") {
|
|
7628
|
-
throw new Error(`
|
|
7628
|
+
throw new Error(`Massive API Error: ${data.error}`);
|
|
7629
7629
|
}
|
|
7630
7630
|
return data;
|
|
7631
7631
|
}
|
|
@@ -7642,7 +7642,7 @@ const fetchIndicesPreviousClose = async (indicesTicker, options) => {
|
|
|
7642
7642
|
* @param {string} date - The date in YYYY-MM-DD format
|
|
7643
7643
|
* @param {Object} [options] - Optional parameters
|
|
7644
7644
|
* @param {string} [options.apiKey] - API key to use for the request
|
|
7645
|
-
* @returns {Promise<
|
|
7645
|
+
* @returns {Promise<MassiveIndicesDailyOpenCloseResponse>} The daily open/close response
|
|
7646
7646
|
*/
|
|
7647
7647
|
const fetchIndicesDailyOpenClose = async (indicesTicker, date, options) => {
|
|
7648
7648
|
const apiKey = validateApiKey(options?.apiKey);
|
|
@@ -7655,7 +7655,7 @@ const fetchIndicesDailyOpenClose = async (indicesTicker, date, options) => {
|
|
|
7655
7655
|
const response = await fetchWithRetry(url.toString(), {}, 3, 300);
|
|
7656
7656
|
const data = await response.json();
|
|
7657
7657
|
if (data.status === "ERROR") {
|
|
7658
|
-
throw new Error(`
|
|
7658
|
+
throw new Error(`Massive API Error: ${data.error}`);
|
|
7659
7659
|
}
|
|
7660
7660
|
return data;
|
|
7661
7661
|
}
|
|
@@ -7668,10 +7668,10 @@ const fetchIndicesDailyOpenClose = async (indicesTicker, date, options) => {
|
|
|
7668
7668
|
/**
|
|
7669
7669
|
* Gets a snapshot of indices data for specified tickers.
|
|
7670
7670
|
*
|
|
7671
|
-
* @param {
|
|
7671
|
+
* @param {MassiveIndicesSnapshotParams} [params] - Parameters for the snapshot request
|
|
7672
7672
|
* @param {Object} [options] - Optional parameters
|
|
7673
7673
|
* @param {string} [options.apiKey] - API key to use for the request
|
|
7674
|
-
* @returns {Promise<
|
|
7674
|
+
* @returns {Promise<MassiveIndicesSnapshotResponse>} The indices snapshot response
|
|
7675
7675
|
*/
|
|
7676
7676
|
const fetchIndicesSnapshot = async (params, options) => {
|
|
7677
7677
|
const apiKey = validateApiKey(options?.apiKey);
|
|
@@ -7696,7 +7696,7 @@ const fetchIndicesSnapshot = async (params, options) => {
|
|
|
7696
7696
|
const response = await fetchWithRetry(url.toString(), {}, 3, 300);
|
|
7697
7697
|
const data = await response.json();
|
|
7698
7698
|
if (data.status === "ERROR") {
|
|
7699
|
-
throw new Error(`
|
|
7699
|
+
throw new Error(`Massive API Error: ${data.error}`);
|
|
7700
7700
|
}
|
|
7701
7701
|
return data;
|
|
7702
7702
|
}
|
|
@@ -7716,7 +7716,7 @@ const fetchIndicesSnapshot = async (params, options) => {
|
|
|
7716
7716
|
* @param {string} [options.order] - Order results
|
|
7717
7717
|
* @param {number} [options.limit] - Limit the number of results
|
|
7718
7718
|
* @param {string} [options.sort] - Sort field
|
|
7719
|
-
* @returns {Promise<
|
|
7719
|
+
* @returns {Promise<MassiveIndicesSnapshotResponse>} The universal snapshot response
|
|
7720
7720
|
*/
|
|
7721
7721
|
const fetchUniversalSnapshot = async (tickers, options) => {
|
|
7722
7722
|
const apiKey = validateApiKey(options?.apiKey);
|
|
@@ -7744,7 +7744,7 @@ const fetchUniversalSnapshot = async (tickers, options) => {
|
|
|
7744
7744
|
const response = await fetchWithRetry(url.toString(), {}, 3, 300);
|
|
7745
7745
|
const data = await response.json();
|
|
7746
7746
|
if (data.status === "ERROR") {
|
|
7747
|
-
throw new Error(`
|
|
7747
|
+
throw new Error(`Massive API Error: ${data.error}`);
|
|
7748
7748
|
}
|
|
7749
7749
|
return data;
|
|
7750
7750
|
}
|
|
@@ -7755,9 +7755,9 @@ const fetchUniversalSnapshot = async (tickers, options) => {
|
|
|
7755
7755
|
});
|
|
7756
7756
|
};
|
|
7757
7757
|
/**
|
|
7758
|
-
* Converts
|
|
7758
|
+
* Converts Massive Indices bar data to a more standardized format
|
|
7759
7759
|
*
|
|
7760
|
-
* @param {
|
|
7760
|
+
* @param {MassiveIndicesAggregatesResponse} data - The raw aggregates response
|
|
7761
7761
|
* @returns {Array<{date: string, open: number, high: number, low: number, close: number, timestamp: number}>} Formatted bar data
|
|
7762
7762
|
*/
|
|
7763
7763
|
const formatIndicesBarData = (data) => {
|
|
@@ -9222,7 +9222,7 @@ async function fetchPerformanceMetrics({ params, client, accountId, alpacaAccoun
|
|
|
9222
9222
|
* Structured error type hierarchy for all API integrations
|
|
9223
9223
|
*
|
|
9224
9224
|
* This module provides a comprehensive error handling system for external API integrations,
|
|
9225
|
-
* including Alpaca,
|
|
9225
|
+
* including Alpaca, Massive, and AlphaVantage services.
|
|
9226
9226
|
*/
|
|
9227
9227
|
/**
|
|
9228
9228
|
* Base error class for all @adaptic/utils errors
|
|
@@ -9262,9 +9262,9 @@ class AlpacaApiError extends AdapticUtilsError {
|
|
|
9262
9262
|
}
|
|
9263
9263
|
/**
|
|
9264
9264
|
* Massive.com API specific errors
|
|
9265
|
-
* Handles all errors from
|
|
9265
|
+
* Handles all errors from Massive market data API
|
|
9266
9266
|
*/
|
|
9267
|
-
class
|
|
9267
|
+
class MassiveApiError extends AdapticUtilsError {
|
|
9268
9268
|
statusCode;
|
|
9269
9269
|
constructor(message, code, statusCode, cause) {
|
|
9270
9270
|
// Rate limit (429) and server errors (5xx) are retryable
|
|
@@ -9419,7 +9419,7 @@ class DataFormatError extends AdapticUtilsError {
|
|
|
9419
9419
|
* Token bucket rate limiter for external API integrations
|
|
9420
9420
|
*
|
|
9421
9421
|
* Implements client-side rate limiting to prevent exceeding API quotas
|
|
9422
|
-
* and ensure fair usage of external services like Alpaca,
|
|
9422
|
+
* and ensure fair usage of external services like Alpaca, Massive, and AlphaVantage.
|
|
9423
9423
|
*
|
|
9424
9424
|
* @example
|
|
9425
9425
|
* ```typescript
|
|
@@ -48369,7 +48369,7 @@ class AlpacaClient {
|
|
|
48369
48369
|
keyId: config.apiKey,
|
|
48370
48370
|
secretKey: config.apiSecret,
|
|
48371
48371
|
paper: config.accountType === "PAPER",
|
|
48372
|
-
|
|
48372
|
+
useMassive: false,
|
|
48373
48373
|
});
|
|
48374
48374
|
// Set up for direct API calls
|
|
48375
48375
|
this.apiBaseUrl = getTradingApiUrl(config.accountType);
|
|
@@ -60326,7 +60326,7 @@ class LRUCache {
|
|
|
60326
60326
|
* request bursts during synchronized cache expiration events.
|
|
60327
60327
|
*
|
|
60328
60328
|
* @rationale In algorithmic trading, cache stampedes can:
|
|
60329
|
-
* - Overwhelm market data APIs (Alpaca,
|
|
60329
|
+
* - Overwhelm market data APIs (Alpaca, Massive) causing rate limiting (200 req/min limits)
|
|
60330
60330
|
* - Introduce latency spikes during critical trading windows (market open/close)
|
|
60331
60331
|
* - Trigger cascading failures when position data becomes unavailable
|
|
60332
60332
|
* - Cause missed trading opportunities due to stale or unavailable data
|
|
@@ -66145,8 +66145,8 @@ const AlpacaCryptoBarsResponseSchema = objectType({
|
|
|
66145
66145
|
* Validates API responses against expected shapes to catch breaking API changes early.
|
|
66146
66146
|
*/
|
|
66147
66147
|
// ===== Raw Price Data Schemas =====
|
|
66148
|
-
/** Schema for raw
|
|
66149
|
-
const
|
|
66148
|
+
/** Schema for raw Massive price data (as returned from aggregates endpoint) */
|
|
66149
|
+
const RawMassivePriceDataSchema = objectType({
|
|
66150
66150
|
T: stringType(),
|
|
66151
66151
|
c: numberType(),
|
|
66152
66152
|
h: numberType(),
|
|
@@ -66158,8 +66158,8 @@ const RawPolygonPriceDataSchema = objectType({
|
|
|
66158
66158
|
vw: numberType(),
|
|
66159
66159
|
});
|
|
66160
66160
|
// ===== Ticker Info Schemas =====
|
|
66161
|
-
/** Schema for
|
|
66162
|
-
const
|
|
66161
|
+
/** Schema for Massive ticker info response */
|
|
66162
|
+
const MassiveTickerInfoSchema = objectType({
|
|
66163
66163
|
active: booleanType(),
|
|
66164
66164
|
currency_name: stringType(),
|
|
66165
66165
|
delisted_utc: stringType().optional(),
|
|
@@ -66174,24 +66174,24 @@ const PolygonTickerInfoSchema = objectType({
|
|
|
66174
66174
|
type: stringType(),
|
|
66175
66175
|
});
|
|
66176
66176
|
/** Schema for the wrapper around ticker details API response */
|
|
66177
|
-
const
|
|
66178
|
-
results:
|
|
66177
|
+
const MassiveTickerDetailsResponseSchema = objectType({
|
|
66178
|
+
results: MassiveTickerInfoSchema,
|
|
66179
66179
|
status: stringType(),
|
|
66180
66180
|
request_id: stringType(),
|
|
66181
66181
|
});
|
|
66182
66182
|
// ===== Grouped Daily Schemas =====
|
|
66183
|
-
/** Schema for
|
|
66184
|
-
const
|
|
66183
|
+
/** Schema for Massive grouped daily response */
|
|
66184
|
+
const MassiveGroupedDailyResponseSchema = objectType({
|
|
66185
66185
|
adjusted: booleanType(),
|
|
66186
66186
|
queryCount: numberType(),
|
|
66187
66187
|
request_id: stringType(),
|
|
66188
66188
|
resultsCount: numberType(),
|
|
66189
66189
|
status: stringType(),
|
|
66190
|
-
results: arrayType(
|
|
66190
|
+
results: arrayType(RawMassivePriceDataSchema),
|
|
66191
66191
|
});
|
|
66192
66192
|
// ===== Daily Open Close Schemas =====
|
|
66193
|
-
/** Schema for
|
|
66194
|
-
const
|
|
66193
|
+
/** Schema for Massive daily open close response */
|
|
66194
|
+
const MassiveDailyOpenCloseSchema = objectType({
|
|
66195
66195
|
afterHours: numberType().optional(),
|
|
66196
66196
|
close: numberType(),
|
|
66197
66197
|
from: stringType(),
|
|
@@ -66204,8 +66204,8 @@ const PolygonDailyOpenCloseSchema = objectType({
|
|
|
66204
66204
|
volume: numberType(),
|
|
66205
66205
|
});
|
|
66206
66206
|
// ===== Trade Schemas =====
|
|
66207
|
-
/** Schema for a single
|
|
66208
|
-
const
|
|
66207
|
+
/** Schema for a single Massive trade */
|
|
66208
|
+
const MassiveTradeSchema = objectType({
|
|
66209
66209
|
conditions: arrayType(numberType()),
|
|
66210
66210
|
correction: numberType().optional(),
|
|
66211
66211
|
exchange: numberType(),
|
|
@@ -66219,16 +66219,16 @@ const PolygonTradeSchema = objectType({
|
|
|
66219
66219
|
trf_id: numberType().optional(),
|
|
66220
66220
|
trf_timestamp: numberType().optional(),
|
|
66221
66221
|
});
|
|
66222
|
-
/** Schema for
|
|
66223
|
-
const
|
|
66222
|
+
/** Schema for Massive trades response */
|
|
66223
|
+
const MassiveTradesResponseSchema = objectType({
|
|
66224
66224
|
status: literalType("OK"),
|
|
66225
66225
|
request_id: stringType(),
|
|
66226
66226
|
next_url: stringType().optional(),
|
|
66227
|
-
results: arrayType(
|
|
66227
|
+
results: arrayType(MassiveTradeSchema),
|
|
66228
66228
|
});
|
|
66229
66229
|
// ===== Last Trade Schemas =====
|
|
66230
|
-
/** Schema for
|
|
66231
|
-
const
|
|
66230
|
+
/** Schema for Massive last trade response */
|
|
66231
|
+
const MassiveLastTradeResponseSchema = objectType({
|
|
66232
66232
|
status: stringType(),
|
|
66233
66233
|
request_id: stringType(),
|
|
66234
66234
|
results: objectType({
|
|
@@ -66245,20 +66245,20 @@ const PolygonLastTradeResponseSchema = objectType({
|
|
|
66245
66245
|
}),
|
|
66246
66246
|
});
|
|
66247
66247
|
// ===== Aggregates (Bars) Schemas =====
|
|
66248
|
-
/** Schema for
|
|
66249
|
-
const
|
|
66248
|
+
/** Schema for Massive aggregates (bars) response */
|
|
66249
|
+
const MassiveAggregatesResponseSchema = objectType({
|
|
66250
66250
|
adjusted: booleanType().optional(),
|
|
66251
66251
|
next_url: stringType().optional(),
|
|
66252
66252
|
queryCount: numberType().optional(),
|
|
66253
66253
|
request_id: stringType(),
|
|
66254
|
-
results: arrayType(
|
|
66254
|
+
results: arrayType(RawMassivePriceDataSchema).optional(),
|
|
66255
66255
|
resultsCount: numberType().optional(),
|
|
66256
66256
|
status: stringType(),
|
|
66257
66257
|
ticker: stringType().optional(),
|
|
66258
66258
|
});
|
|
66259
66259
|
// ===== Error Response Schema =====
|
|
66260
|
-
/** Schema for
|
|
66261
|
-
const
|
|
66260
|
+
/** Schema for Massive error response */
|
|
66261
|
+
const MassiveErrorResponseSchema = objectType({
|
|
66262
66262
|
status: stringType(),
|
|
66263
66263
|
request_id: stringType(),
|
|
66264
66264
|
message: stringType(),
|
|
@@ -66318,7 +66318,7 @@ const AVNewsResponseSchema = objectType({
|
|
|
66318
66318
|
*
|
|
66319
66319
|
* Supports:
|
|
66320
66320
|
* - Cursor-based pagination (Alpaca: `next_page_token` / `page_token`)
|
|
66321
|
-
* - URL-based pagination (
|
|
66321
|
+
* - URL-based pagination (Massive: `next_url`)
|
|
66322
66322
|
* - Offset-based pagination (page numbers or skip/take)
|
|
66323
66323
|
*
|
|
66324
66324
|
* Provides both async iterator and collect-all patterns.
|
|
@@ -66713,7 +66713,7 @@ const adaptic = {
|
|
|
66713
66713
|
fetchLastTrade: fetchLastTrade,
|
|
66714
66714
|
fetchTrades: fetchTrades,
|
|
66715
66715
|
fetchPrices: fetchPrices,
|
|
66716
|
-
|
|
66716
|
+
analyseMassivePriceData: analyseMassivePriceData,
|
|
66717
66717
|
formatPriceData: formatPriceData,
|
|
66718
66718
|
fetchDailyOpenClose: fetchDailyOpenClose,
|
|
66719
66719
|
getPreviousClose: getPreviousClose$1,
|
|
@@ -66770,7 +66770,7 @@ const adaptic = {
|
|
|
66770
66770
|
utils: {
|
|
66771
66771
|
logIfDebug: logIfDebug,
|
|
66772
66772
|
fetchWithRetry: fetchWithRetry,
|
|
66773
|
-
|
|
66773
|
+
validateMassiveApiKey: validateMassiveApiKey,
|
|
66774
66774
|
},
|
|
66775
66775
|
rateLimiter: {
|
|
66776
66776
|
TokenBucketRateLimiter,
|
|
@@ -66818,23 +66818,23 @@ exports.HttpClientError = HttpClientError;
|
|
|
66818
66818
|
exports.HttpServerError = HttpServerError;
|
|
66819
66819
|
exports.KEEP_ALIVE_DEFAULTS = KEEP_ALIVE_DEFAULTS;
|
|
66820
66820
|
exports.MARKET_DATA_API = MARKET_DATA_API;
|
|
66821
|
+
exports.MassiveAggregatesResponseSchema = MassiveAggregatesResponseSchema;
|
|
66822
|
+
exports.MassiveApiError = MassiveApiError;
|
|
66823
|
+
exports.MassiveDailyOpenCloseSchema = MassiveDailyOpenCloseSchema;
|
|
66824
|
+
exports.MassiveErrorResponseSchema = MassiveErrorResponseSchema;
|
|
66825
|
+
exports.MassiveGroupedDailyResponseSchema = MassiveGroupedDailyResponseSchema;
|
|
66826
|
+
exports.MassiveLastTradeResponseSchema = MassiveLastTradeResponseSchema;
|
|
66827
|
+
exports.MassiveTickerDetailsResponseSchema = MassiveTickerDetailsResponseSchema;
|
|
66828
|
+
exports.MassiveTickerInfoSchema = MassiveTickerInfoSchema;
|
|
66829
|
+
exports.MassiveTradeZodSchema = MassiveTradeSchema;
|
|
66830
|
+
exports.MassiveTradesResponseSchema = MassiveTradesResponseSchema;
|
|
66821
66831
|
exports.NetworkError = NetworkError;
|
|
66822
66832
|
exports.NewsError = NewsError;
|
|
66823
66833
|
exports.OptionStrategyError = OptionStrategyError;
|
|
66824
66834
|
exports.OptionsDataError = OptionsDataError;
|
|
66825
|
-
exports.PolygonAggregatesResponseSchema = PolygonAggregatesResponseSchema;
|
|
66826
|
-
exports.PolygonApiError = PolygonApiError;
|
|
66827
|
-
exports.PolygonDailyOpenCloseSchema = PolygonDailyOpenCloseSchema;
|
|
66828
|
-
exports.PolygonErrorResponseSchema = PolygonErrorResponseSchema;
|
|
66829
|
-
exports.PolygonGroupedDailyResponseSchema = PolygonGroupedDailyResponseSchema;
|
|
66830
|
-
exports.PolygonLastTradeResponseSchema = PolygonLastTradeResponseSchema;
|
|
66831
|
-
exports.PolygonTickerDetailsResponseSchema = PolygonTickerDetailsResponseSchema;
|
|
66832
|
-
exports.PolygonTickerInfoSchema = PolygonTickerInfoSchema;
|
|
66833
|
-
exports.PolygonTradeZodSchema = PolygonTradeSchema;
|
|
66834
|
-
exports.PolygonTradesResponseSchema = PolygonTradesResponseSchema;
|
|
66835
66835
|
exports.QuoteError = QuoteError;
|
|
66836
66836
|
exports.RateLimitError = RateLimitError;
|
|
66837
|
-
exports.
|
|
66837
|
+
exports.RawMassivePriceDataSchema = RawMassivePriceDataSchema;
|
|
66838
66838
|
exports.StampedeProtectedCache = StampedeProtectedCache;
|
|
66839
66839
|
exports.TRADING_API = TRADING_API;
|
|
66840
66840
|
exports.TimeoutError = TimeoutError;
|
|
@@ -67047,8 +67047,8 @@ exports.updateAccountConfiguration = updateAccountConfiguration;
|
|
|
67047
67047
|
exports.updateTrailingStop = updateTrailingStop;
|
|
67048
67048
|
exports.validateAlpacaCredentials = validateAlpacaCredentials;
|
|
67049
67049
|
exports.validateAlphaVantageApiKey = validateAlphaVantageApiKey;
|
|
67050
|
+
exports.validateMassiveApiKey = validateMassiveApiKey$1;
|
|
67050
67051
|
exports.validateMultiLegOrder = validateMultiLegOrder;
|
|
67051
|
-
exports.validatePolygonApiKey = validatePolygonApiKey$1;
|
|
67052
67052
|
exports.validateResponse = validateResponse;
|
|
67053
67053
|
exports.verifyFetchKeepAlive = verifyFetchKeepAlive;
|
|
67054
67054
|
exports.waitForOrderFill = waitForOrderFill;
|