@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.cjs
CHANGED
|
@@ -16039,15 +16039,18 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16039
16039
|
stockSubscriptions = { trades: [], quotes: [], bars: [] };
|
|
16040
16040
|
optionSubscriptions = { trades: [], quotes: [], bars: [] };
|
|
16041
16041
|
setMode(mode = 'production') {
|
|
16042
|
-
if (mode === 'sandbox') {
|
|
16042
|
+
if (mode === 'sandbox') {
|
|
16043
|
+
// sandbox mode
|
|
16043
16044
|
this.stockStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v2/sip';
|
|
16044
16045
|
this.optionStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v1beta3/options';
|
|
16045
16046
|
}
|
|
16046
|
-
else if (mode === 'test') {
|
|
16047
|
+
else if (mode === 'test') {
|
|
16048
|
+
// test mode, can only use ticker FAKEPACA
|
|
16047
16049
|
this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/test';
|
|
16048
16050
|
this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options'; // there's no test mode for options
|
|
16049
16051
|
}
|
|
16050
|
-
else {
|
|
16052
|
+
else {
|
|
16053
|
+
// production
|
|
16051
16054
|
this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/sip';
|
|
16052
16055
|
this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options';
|
|
16053
16056
|
}
|
|
@@ -16195,7 +16198,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16195
16198
|
const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
|
|
16196
16199
|
Object.entries(subscriptions).forEach(([key, value]) => {
|
|
16197
16200
|
if (value) {
|
|
16198
|
-
currentSubscriptions[key] = (currentSubscriptions[key] || []).filter(s => !value.includes(s));
|
|
16201
|
+
currentSubscriptions[key] = (currentSubscriptions[key] || []).filter((s) => !value.includes(s));
|
|
16199
16202
|
}
|
|
16200
16203
|
});
|
|
16201
16204
|
const unsubMessage = {
|
|
@@ -16258,11 +16261,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16258
16261
|
let pageCount = 0;
|
|
16259
16262
|
let currency = '';
|
|
16260
16263
|
// Initialize bar arrays for each symbol
|
|
16261
|
-
symbols.forEach(symbol => {
|
|
16264
|
+
symbols.forEach((symbol) => {
|
|
16262
16265
|
allBars[symbol] = [];
|
|
16263
16266
|
});
|
|
16264
|
-
log(`Starting historical bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
16265
|
-
type: 'info'
|
|
16267
|
+
log(`Starting historical bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
16268
|
+
type: 'info',
|
|
16266
16269
|
});
|
|
16267
16270
|
while (hasMorePages) {
|
|
16268
16271
|
pageCount++;
|
|
@@ -16274,7 +16277,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16274
16277
|
};
|
|
16275
16278
|
const response = await this.makeRequest('/stocks/bars', 'GET', requestParams);
|
|
16276
16279
|
if (!response.bars) {
|
|
16277
|
-
log(`No bars data found in response for ${symbolsStr}`, { type: 'warn' });
|
|
16280
|
+
log(`No bars data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
|
|
16278
16281
|
break;
|
|
16279
16282
|
}
|
|
16280
16283
|
// Track currency from first response
|
|
@@ -16290,7 +16293,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16290
16293
|
allBars[symbol] = [...allBars[symbol], ...bars];
|
|
16291
16294
|
pageBarsCount += bars.length;
|
|
16292
16295
|
// Track date range for this page
|
|
16293
|
-
bars.forEach(bar => {
|
|
16296
|
+
bars.forEach((bar) => {
|
|
16294
16297
|
const barDate = new Date(bar.t);
|
|
16295
16298
|
if (!earliestTimestamp || barDate < earliestTimestamp) {
|
|
16296
16299
|
earliestTimestamp = barDate;
|
|
@@ -16309,7 +16312,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16309
16312
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
16310
16313
|
: 'unknown range';
|
|
16311
16314
|
log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
16312
|
-
type: 'info'
|
|
16315
|
+
type: 'info',
|
|
16313
16316
|
});
|
|
16314
16317
|
// Prevent infinite loops
|
|
16315
16318
|
if (pageCount > 1000) {
|
|
@@ -16318,9 +16321,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16318
16321
|
}
|
|
16319
16322
|
}
|
|
16320
16323
|
// Final summary
|
|
16321
|
-
const symbolCounts = Object.entries(allBars)
|
|
16324
|
+
const symbolCounts = Object.entries(allBars)
|
|
16325
|
+
.map(([symbol, bars]) => `${symbol}: ${bars.length}`)
|
|
16326
|
+
.join(', ');
|
|
16322
16327
|
log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
|
|
16323
|
-
type: 'info'
|
|
16328
|
+
type: 'info',
|
|
16324
16329
|
});
|
|
16325
16330
|
return {
|
|
16326
16331
|
bars: allBars,
|
|
@@ -16588,11 +16593,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16588
16593
|
let totalBarsCount = 0;
|
|
16589
16594
|
let pageCount = 0;
|
|
16590
16595
|
// Initialize bar arrays for each symbol
|
|
16591
|
-
symbols.forEach(symbol => {
|
|
16596
|
+
symbols.forEach((symbol) => {
|
|
16592
16597
|
allBars[symbol] = [];
|
|
16593
16598
|
});
|
|
16594
|
-
log(`Starting historical options bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
16595
|
-
type: 'info'
|
|
16599
|
+
log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
16600
|
+
type: 'info',
|
|
16596
16601
|
});
|
|
16597
16602
|
while (hasMorePages) {
|
|
16598
16603
|
pageCount++;
|
|
@@ -16602,7 +16607,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16602
16607
|
};
|
|
16603
16608
|
const response = await this.makeRequest('/options/bars', 'GET', requestParams, 'v1beta1');
|
|
16604
16609
|
if (!response.bars) {
|
|
16605
|
-
log(`No options bars data found in response for ${symbolsStr}`, { type: 'warn' });
|
|
16610
|
+
log(`No options bars data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
|
|
16606
16611
|
break;
|
|
16607
16612
|
}
|
|
16608
16613
|
// Combine bars for each symbol
|
|
@@ -16614,7 +16619,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16614
16619
|
allBars[symbol] = [...allBars[symbol], ...bars];
|
|
16615
16620
|
pageBarsCount += bars.length;
|
|
16616
16621
|
// Track date range for this page
|
|
16617
|
-
bars.forEach(bar => {
|
|
16622
|
+
bars.forEach((bar) => {
|
|
16618
16623
|
const barDate = new Date(bar.t);
|
|
16619
16624
|
if (!earliestTimestamp || barDate < earliestTimestamp) {
|
|
16620
16625
|
earliestTimestamp = barDate;
|
|
@@ -16633,7 +16638,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16633
16638
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
16634
16639
|
: 'unknown range';
|
|
16635
16640
|
log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
16636
|
-
type: 'info'
|
|
16641
|
+
type: 'info',
|
|
16637
16642
|
});
|
|
16638
16643
|
// Prevent infinite loops
|
|
16639
16644
|
if (pageCount > 1000) {
|
|
@@ -16642,9 +16647,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16642
16647
|
}
|
|
16643
16648
|
}
|
|
16644
16649
|
// Final summary
|
|
16645
|
-
const symbolCounts = Object.entries(allBars)
|
|
16650
|
+
const symbolCounts = Object.entries(allBars)
|
|
16651
|
+
.map(([symbol, bars]) => `${symbol}: ${bars.length}`)
|
|
16652
|
+
.join(', ');
|
|
16646
16653
|
log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
|
|
16647
|
-
type: 'info'
|
|
16654
|
+
type: 'info',
|
|
16648
16655
|
});
|
|
16649
16656
|
return {
|
|
16650
16657
|
bars: allBars,
|
|
@@ -16668,11 +16675,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16668
16675
|
let totalTradesCount = 0;
|
|
16669
16676
|
let pageCount = 0;
|
|
16670
16677
|
// Initialize trades arrays for each symbol
|
|
16671
|
-
symbols.forEach(symbol => {
|
|
16678
|
+
symbols.forEach((symbol) => {
|
|
16672
16679
|
allTrades[symbol] = [];
|
|
16673
16680
|
});
|
|
16674
|
-
log(`Starting historical options trades fetch for ${symbolsStr} (${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
16675
|
-
type: 'info'
|
|
16681
|
+
log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, {
|
|
16682
|
+
type: 'info',
|
|
16676
16683
|
});
|
|
16677
16684
|
while (hasMorePages) {
|
|
16678
16685
|
pageCount++;
|
|
@@ -16682,7 +16689,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16682
16689
|
};
|
|
16683
16690
|
const response = await this.makeRequest('/options/trades', 'GET', requestParams, 'v1beta1');
|
|
16684
16691
|
if (!response.trades) {
|
|
16685
|
-
log(`No options trades data found in response for ${symbolsStr}`, { type: 'warn' });
|
|
16692
|
+
log(`No options trades data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
|
|
16686
16693
|
break;
|
|
16687
16694
|
}
|
|
16688
16695
|
// Combine trades for each symbol
|
|
@@ -16694,7 +16701,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16694
16701
|
allTrades[symbol] = [...allTrades[symbol], ...trades];
|
|
16695
16702
|
pageTradesCount += trades.length;
|
|
16696
16703
|
// Track date range for this page
|
|
16697
|
-
trades.forEach(trade => {
|
|
16704
|
+
trades.forEach((trade) => {
|
|
16698
16705
|
const tradeDate = new Date(trade.t);
|
|
16699
16706
|
if (!earliestTimestamp || tradeDate < earliestTimestamp) {
|
|
16700
16707
|
earliestTimestamp = tradeDate;
|
|
@@ -16712,8 +16719,8 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16712
16719
|
const dateRangeStr = earliestTimestamp && latestTimestamp
|
|
16713
16720
|
? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
|
|
16714
16721
|
: 'unknown range';
|
|
16715
|
-
log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
16716
|
-
type: 'info'
|
|
16722
|
+
log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
|
|
16723
|
+
type: 'info',
|
|
16717
16724
|
});
|
|
16718
16725
|
// Prevent infinite loops
|
|
16719
16726
|
if (pageCount > 1000) {
|
|
@@ -16722,9 +16729,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16722
16729
|
}
|
|
16723
16730
|
}
|
|
16724
16731
|
// Final summary
|
|
16725
|
-
const symbolCounts = Object.entries(allTrades)
|
|
16732
|
+
const symbolCounts = Object.entries(allTrades)
|
|
16733
|
+
.map(([symbol, trades]) => `${symbol}: ${trades.length}`)
|
|
16734
|
+
.join(', ');
|
|
16726
16735
|
log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
|
|
16727
|
-
type: 'info'
|
|
16736
|
+
type: 'info',
|
|
16728
16737
|
});
|
|
16729
16738
|
return {
|
|
16730
16739
|
trades: allTrades,
|
|
@@ -16869,7 +16878,9 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
|
|
|
16869
16878
|
...(symbol && { symbols: symbol }),
|
|
16870
16879
|
...(mergedParams.limit && { limit: Math.min(50, maxLimit - fetchedCount).toString() }),
|
|
16871
16880
|
...(mergedParams.sort && { sort: mergedParams.sort }),
|
|
16872
|
-
...(mergedParams.include_content !== undefined
|
|
16881
|
+
...(mergedParams.include_content !== undefined
|
|
16882
|
+
? { include_content: mergedParams.include_content.toString() }
|
|
16883
|
+
: {}),
|
|
16873
16884
|
...(pageToken && { page_token: pageToken }),
|
|
16874
16885
|
});
|
|
16875
16886
|
const url = `${this.v1beta1url}/news?${queryParams}`;
|