@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.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') { // sandbox mode
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') { // test mode, can only use ticker FAKEPACA
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 { // production
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;
@@ -16308,9 +16311,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16308
16311
  const dateRangeStr = earliestTimestamp && latestTimestamp
16309
16312
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
16310
16313
  : 'unknown range';
16311
- log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
16312
- type: 'info'
16313
- });
16314
+ log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbols.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`);
16314
16315
  // Prevent infinite loops
16315
16316
  if (pageCount > 1000) {
16316
16317
  log(`Stopping pagination after ${pageCount} pages to prevent infinite loop`, { type: 'warn' });
@@ -16318,10 +16319,10 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16318
16319
  }
16319
16320
  }
16320
16321
  // Final summary
16321
- const symbolCounts = Object.entries(allBars).map(([symbol, bars]) => `${symbol}: ${bars.length}`).join(', ');
16322
- log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
16323
- type: 'info'
16324
- });
16322
+ const symbolsJoined = Object.entries(allBars)
16323
+ .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
16324
+ .join(', ');
16325
+ log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages for ${symbolsJoined.length} symbols'}`);
16325
16326
  return {
16326
16327
  bars: allBars,
16327
16328
  next_page_token: null, // Always null since we fetch all pages
@@ -16588,11 +16589,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16588
16589
  let totalBarsCount = 0;
16589
16590
  let pageCount = 0;
16590
16591
  // Initialize bar arrays for each symbol
16591
- symbols.forEach(symbol => {
16592
+ symbols.forEach((symbol) => {
16592
16593
  allBars[symbol] = [];
16593
16594
  });
16594
- log(`Starting historical options bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
16595
- type: 'info'
16595
+ log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
16596
+ type: 'info',
16596
16597
  });
16597
16598
  while (hasMorePages) {
16598
16599
  pageCount++;
@@ -16602,7 +16603,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16602
16603
  };
16603
16604
  const response = await this.makeRequest('/options/bars', 'GET', requestParams, 'v1beta1');
16604
16605
  if (!response.bars) {
16605
- log(`No options bars data found in response for ${symbolsStr}`, { type: 'warn' });
16606
+ log(`No options bars data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
16606
16607
  break;
16607
16608
  }
16608
16609
  // Combine bars for each symbol
@@ -16614,7 +16615,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16614
16615
  allBars[symbol] = [...allBars[symbol], ...bars];
16615
16616
  pageBarsCount += bars.length;
16616
16617
  // Track date range for this page
16617
- bars.forEach(bar => {
16618
+ bars.forEach((bar) => {
16618
16619
  const barDate = new Date(bar.t);
16619
16620
  if (!earliestTimestamp || barDate < earliestTimestamp) {
16620
16621
  earliestTimestamp = barDate;
@@ -16633,7 +16634,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16633
16634
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
16634
16635
  : 'unknown range';
16635
16636
  log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
16636
- type: 'info'
16637
+ type: 'info',
16637
16638
  });
16638
16639
  // Prevent infinite loops
16639
16640
  if (pageCount > 1000) {
@@ -16642,9 +16643,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16642
16643
  }
16643
16644
  }
16644
16645
  // Final summary
16645
- const symbolCounts = Object.entries(allBars).map(([symbol, bars]) => `${symbol}: ${bars.length}`).join(', ');
16646
+ const symbolCounts = Object.entries(allBars)
16647
+ .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
16648
+ .join(', ');
16646
16649
  log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
16647
- type: 'info'
16650
+ type: 'info',
16648
16651
  });
16649
16652
  return {
16650
16653
  bars: allBars,
@@ -16668,11 +16671,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16668
16671
  let totalTradesCount = 0;
16669
16672
  let pageCount = 0;
16670
16673
  // Initialize trades arrays for each symbol
16671
- symbols.forEach(symbol => {
16674
+ symbols.forEach((symbol) => {
16672
16675
  allTrades[symbol] = [];
16673
16676
  });
16674
- log(`Starting historical options trades fetch for ${symbolsStr} (${params.start || 'no start'} to ${params.end || 'no end'})`, {
16675
- type: 'info'
16677
+ log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, {
16678
+ type: 'info',
16676
16679
  });
16677
16680
  while (hasMorePages) {
16678
16681
  pageCount++;
@@ -16682,7 +16685,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16682
16685
  };
16683
16686
  const response = await this.makeRequest('/options/trades', 'GET', requestParams, 'v1beta1');
16684
16687
  if (!response.trades) {
16685
- log(`No options trades data found in response for ${symbolsStr}`, { type: 'warn' });
16688
+ log(`No options trades data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
16686
16689
  break;
16687
16690
  }
16688
16691
  // Combine trades for each symbol
@@ -16694,7 +16697,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16694
16697
  allTrades[symbol] = [...allTrades[symbol], ...trades];
16695
16698
  pageTradesCount += trades.length;
16696
16699
  // Track date range for this page
16697
- trades.forEach(trade => {
16700
+ trades.forEach((trade) => {
16698
16701
  const tradeDate = new Date(trade.t);
16699
16702
  if (!earliestTimestamp || tradeDate < earliestTimestamp) {
16700
16703
  earliestTimestamp = tradeDate;
@@ -16712,8 +16715,8 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16712
16715
  const dateRangeStr = earliestTimestamp && latestTimestamp
16713
16716
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
16714
16717
  : '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'
16718
+ log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
16719
+ type: 'info',
16717
16720
  });
16718
16721
  // Prevent infinite loops
16719
16722
  if (pageCount > 1000) {
@@ -16722,9 +16725,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16722
16725
  }
16723
16726
  }
16724
16727
  // Final summary
16725
- const symbolCounts = Object.entries(allTrades).map(([symbol, trades]) => `${symbol}: ${trades.length}`).join(', ');
16728
+ const symbolCounts = Object.entries(allTrades)
16729
+ .map(([symbol, trades]) => `${symbol}: ${trades.length}`)
16730
+ .join(', ');
16726
16731
  log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
16727
- type: 'info'
16732
+ type: 'info',
16728
16733
  });
16729
16734
  return {
16730
16735
  trades: allTrades,
@@ -16869,7 +16874,9 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
16869
16874
  ...(symbol && { symbols: symbol }),
16870
16875
  ...(mergedParams.limit && { limit: Math.min(50, maxLimit - fetchedCount).toString() }),
16871
16876
  ...(mergedParams.sort && { sort: mergedParams.sort }),
16872
- ...(mergedParams.include_content !== undefined ? { include_content: mergedParams.include_content.toString() } : {}),
16877
+ ...(mergedParams.include_content !== undefined
16878
+ ? { include_content: mergedParams.include_content.toString() }
16879
+ : {}),
16873
16880
  ...(pageToken && { page_token: pageToken }),
16874
16881
  });
16875
16882
  const url = `${this.v1beta1url}/news?${queryParams}`;