@discomedia/utils 1.0.21 → 1.0.23
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-frontend.cjs +41 -34
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +41 -34
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +41 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +41 -34
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/test.js +41 -34
- package/dist/test.js.map +1 -1
- package/dist/types/alpaca-market-data-api.d.ts.map +1 -1
- package/dist/types-frontend/alpaca-market-data-api.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index-frontend.mjs
CHANGED
|
@@ -13725,15 +13725,18 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
13725
13725
|
stockSubscriptions = { trades: [], quotes: [], bars: [] };
|
|
13726
13726
|
optionSubscriptions = { trades: [], quotes: [], bars: [] };
|
|
13727
13727
|
setMode(mode = 'production') {
|
|
13728
|
-
if (mode === 'sandbox') {
|
|
13728
|
+
if (mode === 'sandbox') {
|
|
13729
|
+
// sandbox mode
|
|
13729
13730
|
this.stockStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v2/sip';
|
|
13730
13731
|
this.optionStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v1beta3/options';
|
|
13731
13732
|
}
|
|
13732
|
-
else if (mode === 'test') {
|
|
13733
|
+
else if (mode === 'test') {
|
|
13734
|
+
// test mode, can only use ticker FAKEPACA
|
|
13733
13735
|
this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/test';
|
|
13734
13736
|
this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options'; // there's no test mode for options
|
|
13735
13737
|
}
|
|
13736
|
-
else {
|
|
13738
|
+
else {
|
|
13739
|
+
// production
|
|
13737
13740
|
this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/sip';
|
|
13738
13741
|
this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options';
|
|
13739
13742
|
}
|
|
@@ -13881,7 +13884,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
13881
13884
|
const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
|
|
13882
13885
|
Object.entries(subscriptions).forEach(([key, value]) => {
|
|
13883
13886
|
if (value) {
|
|
13884
|
-
currentSubscriptions[key] = (currentSubscriptions[key] || []).filter(s => !value.includes(s));
|
|
13887
|
+
currentSubscriptions[key] = (currentSubscriptions[key] || []).filter((s) => !value.includes(s));
|
|
13885
13888
|
}
|
|
13886
13889
|
});
|
|
13887
13890
|
const unsubMessage = {
|
|
@@ -13944,11 +13947,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
13944
13947
|
let pageCount = 0;
|
|
13945
13948
|
let currency = '';
|
|
13946
13949
|
// Initialize bar arrays for each symbol
|
|
13947
|
-
symbols.forEach(symbol => {
|
|
13950
|
+
symbols.forEach((symbol) => {
|
|
13948
13951
|
allBars[symbol] = [];
|
|
13949
13952
|
});
|
|
13950
|
-
log(`Starting historical bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
13951
|
-
type: 'info'
|
|
13953
|
+
log(`Starting historical bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
13954
|
+
type: 'info',
|
|
13952
13955
|
});
|
|
13953
13956
|
while (hasMorePages) {
|
|
13954
13957
|
pageCount++;
|
|
@@ -13960,7 +13963,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
13960
13963
|
};
|
|
13961
13964
|
const response = await this.makeRequest('/stocks/bars', 'GET', requestParams);
|
|
13962
13965
|
if (!response.bars) {
|
|
13963
|
-
log(`No bars data found in response for ${symbolsStr}`, { type: 'warn' });
|
|
13966
|
+
log(`No bars data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
|
|
13964
13967
|
break;
|
|
13965
13968
|
}
|
|
13966
13969
|
// Track currency from first response
|
|
@@ -13976,7 +13979,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
13976
13979
|
allBars[symbol] = [...allBars[symbol], ...bars];
|
|
13977
13980
|
pageBarsCount += bars.length;
|
|
13978
13981
|
// Track date range for this page
|
|
13979
|
-
bars.forEach(bar => {
|
|
13982
|
+
bars.forEach((bar) => {
|
|
13980
13983
|
const barDate = new Date(bar.t);
|
|
13981
13984
|
if (!earliestTimestamp || barDate < earliestTimestamp) {
|
|
13982
13985
|
earliestTimestamp = barDate;
|
|
@@ -13994,9 +13997,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
13994
13997
|
const dateRangeStr = earliestTimestamp && latestTimestamp
|
|
13995
13998
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
13996
13999
|
: 'unknown range';
|
|
13997
|
-
log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${
|
|
13998
|
-
type: 'info'
|
|
13999
|
-
});
|
|
14000
|
+
log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`);
|
|
14000
14001
|
// Prevent infinite loops
|
|
14001
14002
|
if (pageCount > 1000) {
|
|
14002
14003
|
log(`Stopping pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
|
|
@@ -14004,10 +14005,10 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14004
14005
|
}
|
|
14005
14006
|
}
|
|
14006
14007
|
// Final summary
|
|
14007
|
-
const
|
|
14008
|
-
|
|
14009
|
-
|
|
14010
|
-
});
|
|
14008
|
+
const symbolsJoined = Object.entries(allBars)
|
|
14009
|
+
.map(([symbol, bars]) => `${symbol}: ${bars.length}`)
|
|
14010
|
+
.join(', ');
|
|
14011
|
+
log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages for ${symbolsJoined.length} symbols'}`);
|
|
14011
14012
|
return {
|
|
14012
14013
|
bars: allBars,
|
|
14013
14014
|
next_page_token: null, // Always null since we fetch all pages
|
|
@@ -14274,11 +14275,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14274
14275
|
let totalBarsCount = 0;
|
|
14275
14276
|
let pageCount = 0;
|
|
14276
14277
|
// Initialize bar arrays for each symbol
|
|
14277
|
-
symbols.forEach(symbol => {
|
|
14278
|
+
symbols.forEach((symbol) => {
|
|
14278
14279
|
allBars[symbol] = [];
|
|
14279
14280
|
});
|
|
14280
|
-
log(`Starting historical options bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
14281
|
-
type: 'info'
|
|
14281
|
+
log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
14282
|
+
type: 'info',
|
|
14282
14283
|
});
|
|
14283
14284
|
while (hasMorePages) {
|
|
14284
14285
|
pageCount++;
|
|
@@ -14288,7 +14289,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14288
14289
|
};
|
|
14289
14290
|
const response = await this.makeRequest('/options/bars', 'GET', requestParams, 'v1beta1');
|
|
14290
14291
|
if (!response.bars) {
|
|
14291
|
-
log(`No options bars data found in response for ${symbolsStr}`, { type: 'warn' });
|
|
14292
|
+
log(`No options bars data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
|
|
14292
14293
|
break;
|
|
14293
14294
|
}
|
|
14294
14295
|
// Combine bars for each symbol
|
|
@@ -14300,7 +14301,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14300
14301
|
allBars[symbol] = [...allBars[symbol], ...bars];
|
|
14301
14302
|
pageBarsCount += bars.length;
|
|
14302
14303
|
// Track date range for this page
|
|
14303
|
-
bars.forEach(bar => {
|
|
14304
|
+
bars.forEach((bar) => {
|
|
14304
14305
|
const barDate = new Date(bar.t);
|
|
14305
14306
|
if (!earliestTimestamp || barDate < earliestTimestamp) {
|
|
14306
14307
|
earliestTimestamp = barDate;
|
|
@@ -14319,7 +14320,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14319
14320
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
14320
14321
|
: 'unknown range';
|
|
14321
14322
|
log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
14322
|
-
type: 'info'
|
|
14323
|
+
type: 'info',
|
|
14323
14324
|
});
|
|
14324
14325
|
// Prevent infinite loops
|
|
14325
14326
|
if (pageCount > 1000) {
|
|
@@ -14328,9 +14329,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14328
14329
|
}
|
|
14329
14330
|
}
|
|
14330
14331
|
// Final summary
|
|
14331
|
-
const symbolCounts = Object.entries(allBars)
|
|
14332
|
+
const symbolCounts = Object.entries(allBars)
|
|
14333
|
+
.map(([symbol, bars]) => `${symbol}: ${bars.length}`)
|
|
14334
|
+
.join(', ');
|
|
14332
14335
|
log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
|
|
14333
|
-
type: 'info'
|
|
14336
|
+
type: 'info',
|
|
14334
14337
|
});
|
|
14335
14338
|
return {
|
|
14336
14339
|
bars: allBars,
|
|
@@ -14354,11 +14357,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14354
14357
|
let totalTradesCount = 0;
|
|
14355
14358
|
let pageCount = 0;
|
|
14356
14359
|
// Initialize trades arrays for each symbol
|
|
14357
|
-
symbols.forEach(symbol => {
|
|
14360
|
+
symbols.forEach((symbol) => {
|
|
14358
14361
|
allTrades[symbol] = [];
|
|
14359
14362
|
});
|
|
14360
|
-
log(`Starting historical options trades fetch for ${symbolsStr} (${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
14361
|
-
type: 'info'
|
|
14363
|
+
log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
14364
|
+
type: 'info',
|
|
14362
14365
|
});
|
|
14363
14366
|
while (hasMorePages) {
|
|
14364
14367
|
pageCount++;
|
|
@@ -14368,7 +14371,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14368
14371
|
};
|
|
14369
14372
|
const response = await this.makeRequest('/options/trades', 'GET', requestParams, 'v1beta1');
|
|
14370
14373
|
if (!response.trades) {
|
|
14371
|
-
log(`No options trades data found in response for ${symbolsStr}`, { type: 'warn' });
|
|
14374
|
+
log(`No options trades data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
|
|
14372
14375
|
break;
|
|
14373
14376
|
}
|
|
14374
14377
|
// Combine trades for each symbol
|
|
@@ -14380,7 +14383,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14380
14383
|
allTrades[symbol] = [...allTrades[symbol], ...trades];
|
|
14381
14384
|
pageTradesCount += trades.length;
|
|
14382
14385
|
// Track date range for this page
|
|
14383
|
-
trades.forEach(trade => {
|
|
14386
|
+
trades.forEach((trade) => {
|
|
14384
14387
|
const tradeDate = new Date(trade.t);
|
|
14385
14388
|
if (!earliestTimestamp || tradeDate < earliestTimestamp) {
|
|
14386
14389
|
earliestTimestamp = tradeDate;
|
|
@@ -14398,8 +14401,8 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14398
14401
|
const dateRangeStr = earliestTimestamp && latestTimestamp
|
|
14399
14402
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
14400
14403
|
: 'unknown range';
|
|
14401
|
-
log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
14402
|
-
type: 'info'
|
|
14404
|
+
log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
14405
|
+
type: 'info',
|
|
14403
14406
|
});
|
|
14404
14407
|
// Prevent infinite loops
|
|
14405
14408
|
if (pageCount > 1000) {
|
|
@@ -14408,9 +14411,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14408
14411
|
}
|
|
14409
14412
|
}
|
|
14410
14413
|
// Final summary
|
|
14411
|
-
const symbolCounts = Object.entries(allTrades)
|
|
14414
|
+
const symbolCounts = Object.entries(allTrades)
|
|
14415
|
+
.map(([symbol, trades]) => `${symbol}: ${trades.length}`)
|
|
14416
|
+
.join(', ');
|
|
14412
14417
|
log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
|
|
14413
|
-
type: 'info'
|
|
14418
|
+
type: 'info',
|
|
14414
14419
|
});
|
|
14415
14420
|
return {
|
|
14416
14421
|
trades: allTrades,
|
|
@@ -14555,7 +14560,9 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14555
14560
|
...(symbol && { symbols: symbol }),
|
|
14556
14561
|
...(mergedParams.limit && { limit: Math.min(50, maxLimit - fetchedCount).toString() }),
|
|
14557
14562
|
...(mergedParams.sort && { sort: mergedParams.sort }),
|
|
14558
|
-
...(mergedParams.include_content !== undefined
|
|
14563
|
+
...(mergedParams.include_content !== undefined
|
|
14564
|
+
? { include_content: mergedParams.include_content.toString() }
|
|
14565
|
+
: {}),
|
|
14559
14566
|
...(pageToken && { page_token: pageToken }),
|
|
14560
14567
|
});
|
|
14561
14568
|
const url = `${this.v1beta1url}/news?${queryParams}`;
|