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