@discomedia/utils 1.0.21 → 1.0.22
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 -30
- package/dist/index-frontend.cjs.map +1 -1
- package/dist/index-frontend.mjs +41 -30
- package/dist/index-frontend.mjs.map +1 -1
- package/dist/index.cjs +41 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +41 -30
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/test.js +41 -30
- 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;
|
|
@@ -13995,7 +13998,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
13995
13998
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
13996
13999
|
: 'unknown range';
|
|
13997
14000
|
log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
13998
|
-
type: 'info'
|
|
14001
|
+
type: 'info',
|
|
13999
14002
|
});
|
|
14000
14003
|
// Prevent infinite loops
|
|
14001
14004
|
if (pageCount > 1000) {
|
|
@@ -14004,9 +14007,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14004
14007
|
}
|
|
14005
14008
|
}
|
|
14006
14009
|
// Final summary
|
|
14007
|
-
const symbolCounts = Object.entries(allBars)
|
|
14010
|
+
const symbolCounts = Object.entries(allBars)
|
|
14011
|
+
.map(([symbol, bars]) => `${symbol}: ${bars.length}`)
|
|
14012
|
+
.join(', ');
|
|
14008
14013
|
log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
|
|
14009
|
-
type: 'info'
|
|
14014
|
+
type: 'info',
|
|
14010
14015
|
});
|
|
14011
14016
|
return {
|
|
14012
14017
|
bars: allBars,
|
|
@@ -14274,11 +14279,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14274
14279
|
let totalBarsCount = 0;
|
|
14275
14280
|
let pageCount = 0;
|
|
14276
14281
|
// Initialize bar arrays for each symbol
|
|
14277
|
-
symbols.forEach(symbol => {
|
|
14282
|
+
symbols.forEach((symbol) => {
|
|
14278
14283
|
allBars[symbol] = [];
|
|
14279
14284
|
});
|
|
14280
|
-
log(`Starting historical options bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
14281
|
-
type: 'info'
|
|
14285
|
+
log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
14286
|
+
type: 'info',
|
|
14282
14287
|
});
|
|
14283
14288
|
while (hasMorePages) {
|
|
14284
14289
|
pageCount++;
|
|
@@ -14288,7 +14293,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14288
14293
|
};
|
|
14289
14294
|
const response = await this.makeRequest('/options/bars', 'GET', requestParams, 'v1beta1');
|
|
14290
14295
|
if (!response.bars) {
|
|
14291
|
-
log(`No options bars data found in response for ${symbolsStr}`, { type: 'warn' });
|
|
14296
|
+
log(`No options bars data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
|
|
14292
14297
|
break;
|
|
14293
14298
|
}
|
|
14294
14299
|
// Combine bars for each symbol
|
|
@@ -14300,7 +14305,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14300
14305
|
allBars[symbol] = [...allBars[symbol], ...bars];
|
|
14301
14306
|
pageBarsCount += bars.length;
|
|
14302
14307
|
// Track date range for this page
|
|
14303
|
-
bars.forEach(bar => {
|
|
14308
|
+
bars.forEach((bar) => {
|
|
14304
14309
|
const barDate = new Date(bar.t);
|
|
14305
14310
|
if (!earliestTimestamp || barDate < earliestTimestamp) {
|
|
14306
14311
|
earliestTimestamp = barDate;
|
|
@@ -14319,7 +14324,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14319
14324
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
14320
14325
|
: 'unknown range';
|
|
14321
14326
|
log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
14322
|
-
type: 'info'
|
|
14327
|
+
type: 'info',
|
|
14323
14328
|
});
|
|
14324
14329
|
// Prevent infinite loops
|
|
14325
14330
|
if (pageCount > 1000) {
|
|
@@ -14328,9 +14333,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14328
14333
|
}
|
|
14329
14334
|
}
|
|
14330
14335
|
// Final summary
|
|
14331
|
-
const symbolCounts = Object.entries(allBars)
|
|
14336
|
+
const symbolCounts = Object.entries(allBars)
|
|
14337
|
+
.map(([symbol, bars]) => `${symbol}: ${bars.length}`)
|
|
14338
|
+
.join(', ');
|
|
14332
14339
|
log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
|
|
14333
|
-
type: 'info'
|
|
14340
|
+
type: 'info',
|
|
14334
14341
|
});
|
|
14335
14342
|
return {
|
|
14336
14343
|
bars: allBars,
|
|
@@ -14354,11 +14361,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14354
14361
|
let totalTradesCount = 0;
|
|
14355
14362
|
let pageCount = 0;
|
|
14356
14363
|
// Initialize trades arrays for each symbol
|
|
14357
|
-
symbols.forEach(symbol => {
|
|
14364
|
+
symbols.forEach((symbol) => {
|
|
14358
14365
|
allTrades[symbol] = [];
|
|
14359
14366
|
});
|
|
14360
|
-
log(`Starting historical options trades fetch for ${symbolsStr} (${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
14361
|
-
type: 'info'
|
|
14367
|
+
log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
14368
|
+
type: 'info',
|
|
14362
14369
|
});
|
|
14363
14370
|
while (hasMorePages) {
|
|
14364
14371
|
pageCount++;
|
|
@@ -14368,7 +14375,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14368
14375
|
};
|
|
14369
14376
|
const response = await this.makeRequest('/options/trades', 'GET', requestParams, 'v1beta1');
|
|
14370
14377
|
if (!response.trades) {
|
|
14371
|
-
log(`No options trades data found in response for ${symbolsStr}`, { type: 'warn' });
|
|
14378
|
+
log(`No options trades data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
|
|
14372
14379
|
break;
|
|
14373
14380
|
}
|
|
14374
14381
|
// Combine trades for each symbol
|
|
@@ -14380,7 +14387,7 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14380
14387
|
allTrades[symbol] = [...allTrades[symbol], ...trades];
|
|
14381
14388
|
pageTradesCount += trades.length;
|
|
14382
14389
|
// Track date range for this page
|
|
14383
|
-
trades.forEach(trade => {
|
|
14390
|
+
trades.forEach((trade) => {
|
|
14384
14391
|
const tradeDate = new Date(trade.t);
|
|
14385
14392
|
if (!earliestTimestamp || tradeDate < earliestTimestamp) {
|
|
14386
14393
|
earliestTimestamp = tradeDate;
|
|
@@ -14398,8 +14405,8 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14398
14405
|
const dateRangeStr = earliestTimestamp && latestTimestamp
|
|
14399
14406
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
14400
14407
|
: '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'
|
|
14408
|
+
log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
14409
|
+
type: 'info',
|
|
14403
14410
|
});
|
|
14404
14411
|
// Prevent infinite loops
|
|
14405
14412
|
if (pageCount > 1000) {
|
|
@@ -14408,9 +14415,11 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14408
14415
|
}
|
|
14409
14416
|
}
|
|
14410
14417
|
// Final summary
|
|
14411
|
-
const symbolCounts = Object.entries(allTrades)
|
|
14418
|
+
const symbolCounts = Object.entries(allTrades)
|
|
14419
|
+
.map(([symbol, trades]) => `${symbol}: ${trades.length}`)
|
|
14420
|
+
.join(', ');
|
|
14412
14421
|
log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
|
|
14413
|
-
type: 'info'
|
|
14422
|
+
type: 'info',
|
|
14414
14423
|
});
|
|
14415
14424
|
return {
|
|
14416
14425
|
trades: allTrades,
|
|
@@ -14555,7 +14564,9 @@ class AlpacaMarketDataAPI extends EventEmitter {
|
|
|
14555
14564
|
...(symbol && { symbols: symbol }),
|
|
14556
14565
|
...(mergedParams.limit && { limit: Math.min(50, maxLimit - fetchedCount).toString() }),
|
|
14557
14566
|
...(mergedParams.sort && { sort: mergedParams.sort }),
|
|
14558
|
-
...(mergedParams.include_content !== undefined
|
|
14567
|
+
...(mergedParams.include_content !== undefined
|
|
14568
|
+
? { include_content: mergedParams.include_content.toString() }
|
|
14569
|
+
: {}),
|
|
14559
14570
|
...(pageToken && { page_token: pageToken }),
|
|
14560
14571
|
});
|
|
14561
14572
|
const url = `${this.v1beta1url}/news?${queryParams}`;
|