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