@discomedia/utils 1.0.20 → 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.
@@ -13585,7 +13585,7 @@ class MarketCalendar {
13585
13585
  const yearHolidays = marketHolidays[year];
13586
13586
  if (!yearHolidays)
13587
13587
  return false;
13588
- return Object.values(yearHolidays).some(holiday => holiday.date === formattedDate);
13588
+ return Object.values(yearHolidays).some((holiday) => holiday.date === formattedDate);
13589
13589
  }
13590
13590
  /**
13591
13591
  * Checks if a date is an early close day in NY time.
@@ -13668,7 +13668,9 @@ function getLastFullTradingDateImpl(currentDate = new Date()) {
13668
13668
  marketCloseMinutes = MARKET_CONFIG.TIMES.EARLY_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.EARLY_CLOSE.minute;
13669
13669
  }
13670
13670
  // If not a market day, or before open, or during market hours, return previous market day's close
13671
- if (!calendar.isMarketDay(currentDate) || minutes < marketOpenMinutes || (minutes >= marketOpenMinutes && minutes < marketCloseMinutes)) {
13671
+ if (!calendar.isMarketDay(currentDate) ||
13672
+ minutes < marketOpenMinutes ||
13673
+ (minutes >= marketOpenMinutes && minutes < marketCloseMinutes)) {
13672
13674
  const prevMarketDay = calendar.getPreviousMarketDay(currentDate);
13673
13675
  let prevCloseMinutes = MARKET_CONFIG.TIMES.MARKET_CLOSE.hour * 60 + MARKET_CONFIG.TIMES.MARKET_CLOSE.minute;
13674
13676
  if (calendar.isEarlyCloseDay(prevMarketDay)) {
@@ -13725,15 +13727,18 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
13725
13727
  stockSubscriptions = { trades: [], quotes: [], bars: [] };
13726
13728
  optionSubscriptions = { trades: [], quotes: [], bars: [] };
13727
13729
  setMode(mode = 'production') {
13728
- if (mode === 'sandbox') { // sandbox mode
13730
+ if (mode === 'sandbox') {
13731
+ // sandbox mode
13729
13732
  this.stockStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v2/sip';
13730
13733
  this.optionStreamUrl = 'wss://stream.data.sandbox.alpaca.markets/v1beta3/options';
13731
13734
  }
13732
- else if (mode === 'test') { // test mode, can only use ticker FAKEPACA
13735
+ else if (mode === 'test') {
13736
+ // test mode, can only use ticker FAKEPACA
13733
13737
  this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/test';
13734
13738
  this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options'; // there's no test mode for options
13735
13739
  }
13736
- else { // production
13740
+ else {
13741
+ // production
13737
13742
  this.stockStreamUrl = 'wss://stream.data.alpaca.markets/v2/sip';
13738
13743
  this.optionStreamUrl = 'wss://stream.data.alpaca.markets/v1beta3/options';
13739
13744
  }
@@ -13881,7 +13886,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
13881
13886
  const currentSubscriptions = streamType === 'stock' ? this.stockSubscriptions : this.optionSubscriptions;
13882
13887
  Object.entries(subscriptions).forEach(([key, value]) => {
13883
13888
  if (value) {
13884
- currentSubscriptions[key] = (currentSubscriptions[key] || []).filter(s => !value.includes(s));
13889
+ currentSubscriptions[key] = (currentSubscriptions[key] || []).filter((s) => !value.includes(s));
13885
13890
  }
13886
13891
  });
13887
13892
  const unsubMessage = {
@@ -13944,11 +13949,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
13944
13949
  let pageCount = 0;
13945
13950
  let currency = '';
13946
13951
  // Initialize bar arrays for each symbol
13947
- symbols.forEach(symbol => {
13952
+ symbols.forEach((symbol) => {
13948
13953
  allBars[symbol] = [];
13949
13954
  });
13950
- log(`Starting historical bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
13951
- 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',
13952
13957
  });
13953
13958
  while (hasMorePages) {
13954
13959
  pageCount++;
@@ -13960,7 +13965,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
13960
13965
  };
13961
13966
  const response = await this.makeRequest('/stocks/bars', 'GET', requestParams);
13962
13967
  if (!response.bars) {
13963
- 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' });
13964
13969
  break;
13965
13970
  }
13966
13971
  // Track currency from first response
@@ -13976,7 +13981,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
13976
13981
  allBars[symbol] = [...allBars[symbol], ...bars];
13977
13982
  pageBarsCount += bars.length;
13978
13983
  // Track date range for this page
13979
- bars.forEach(bar => {
13984
+ bars.forEach((bar) => {
13980
13985
  const barDate = new Date(bar.t);
13981
13986
  if (!earliestTimestamp || barDate < earliestTimestamp) {
13982
13987
  earliestTimestamp = barDate;
@@ -13995,7 +14000,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
13995
14000
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
13996
14001
  : 'unknown range';
13997
14002
  log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
13998
- type: 'info'
14003
+ type: 'info',
13999
14004
  });
14000
14005
  // Prevent infinite loops
14001
14006
  if (pageCount > 1000) {
@@ -14004,9 +14009,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14004
14009
  }
14005
14010
  }
14006
14011
  // Final summary
14007
- const symbolCounts = Object.entries(allBars).map(([symbol, bars]) => `${symbol}: ${bars.length}`).join(', ');
14012
+ const symbolCounts = Object.entries(allBars)
14013
+ .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
14014
+ .join(', ');
14008
14015
  log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
14009
- type: 'info'
14016
+ type: 'info',
14010
14017
  });
14011
14018
  return {
14012
14019
  bars: allBars,
@@ -14274,11 +14281,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14274
14281
  let totalBarsCount = 0;
14275
14282
  let pageCount = 0;
14276
14283
  // Initialize bar arrays for each symbol
14277
- symbols.forEach(symbol => {
14284
+ symbols.forEach((symbol) => {
14278
14285
  allBars[symbol] = [];
14279
14286
  });
14280
- log(`Starting historical options bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
14281
- type: 'info'
14287
+ log(`Starting historical options bars fetch for ${symbolsStr.length} symbols (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
14288
+ type: 'info',
14282
14289
  });
14283
14290
  while (hasMorePages) {
14284
14291
  pageCount++;
@@ -14288,7 +14295,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14288
14295
  };
14289
14296
  const response = await this.makeRequest('/options/bars', 'GET', requestParams, 'v1beta1');
14290
14297
  if (!response.bars) {
14291
- log(`No options bars data found in response for ${symbolsStr}`, { type: 'warn' });
14298
+ log(`No options bars data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
14292
14299
  break;
14293
14300
  }
14294
14301
  // Combine bars for each symbol
@@ -14300,7 +14307,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14300
14307
  allBars[symbol] = [...allBars[symbol], ...bars];
14301
14308
  pageBarsCount += bars.length;
14302
14309
  // Track date range for this page
14303
- bars.forEach(bar => {
14310
+ bars.forEach((bar) => {
14304
14311
  const barDate = new Date(bar.t);
14305
14312
  if (!earliestTimestamp || barDate < earliestTimestamp) {
14306
14313
  earliestTimestamp = barDate;
@@ -14319,7 +14326,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14319
14326
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
14320
14327
  : 'unknown range';
14321
14328
  log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
14322
- type: 'info'
14329
+ type: 'info',
14323
14330
  });
14324
14331
  // Prevent infinite loops
14325
14332
  if (pageCount > 1000) {
@@ -14328,9 +14335,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14328
14335
  }
14329
14336
  }
14330
14337
  // Final summary
14331
- const symbolCounts = Object.entries(allBars).map(([symbol, bars]) => `${symbol}: ${bars.length}`).join(', ');
14338
+ const symbolCounts = Object.entries(allBars)
14339
+ .map(([symbol, bars]) => `${symbol}: ${bars.length}`)
14340
+ .join(', ');
14332
14341
  log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
14333
- type: 'info'
14342
+ type: 'info',
14334
14343
  });
14335
14344
  return {
14336
14345
  bars: allBars,
@@ -14354,11 +14363,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14354
14363
  let totalTradesCount = 0;
14355
14364
  let pageCount = 0;
14356
14365
  // Initialize trades arrays for each symbol
14357
- symbols.forEach(symbol => {
14366
+ symbols.forEach((symbol) => {
14358
14367
  allTrades[symbol] = [];
14359
14368
  });
14360
- log(`Starting historical options trades fetch for ${symbolsStr} (${params.start || 'no start'} to ${params.end || 'no end'})`, {
14361
- type: 'info'
14369
+ log(`Starting historical options trades fetch for ${symbolsStr.length} symbols (${params.start || 'no start'} to ${params.end || 'no end'})`, {
14370
+ type: 'info',
14362
14371
  });
14363
14372
  while (hasMorePages) {
14364
14373
  pageCount++;
@@ -14368,7 +14377,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14368
14377
  };
14369
14378
  const response = await this.makeRequest('/options/trades', 'GET', requestParams, 'v1beta1');
14370
14379
  if (!response.trades) {
14371
- log(`No options trades data found in response for ${symbolsStr}`, { type: 'warn' });
14380
+ log(`No options trades data found in response for ${symbolsStr.length} symbols`, { type: 'warn' });
14372
14381
  break;
14373
14382
  }
14374
14383
  // Combine trades for each symbol
@@ -14380,7 +14389,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14380
14389
  allTrades[symbol] = [...allTrades[symbol], ...trades];
14381
14390
  pageTradesCount += trades.length;
14382
14391
  // Track date range for this page
14383
- trades.forEach(trade => {
14392
+ trades.forEach((trade) => {
14384
14393
  const tradeDate = new Date(trade.t);
14385
14394
  if (!earliestTimestamp || tradeDate < earliestTimestamp) {
14386
14395
  earliestTimestamp = tradeDate;
@@ -14398,8 +14407,8 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14398
14407
  const dateRangeStr = earliestTimestamp && latestTimestamp
14399
14408
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
14400
14409
  : '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'
14410
+ log(`Page ${pageCount}: Fetched ${pageTradesCount.toLocaleString()} option trades (total: ${totalTradesCount.toLocaleString()}) for ${symbolsStr.length} symbols, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
14411
+ type: 'info',
14403
14412
  });
14404
14413
  // Prevent infinite loops
14405
14414
  if (pageCount > 1000) {
@@ -14408,9 +14417,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14408
14417
  }
14409
14418
  }
14410
14419
  // Final summary
14411
- const symbolCounts = Object.entries(allTrades).map(([symbol, trades]) => `${symbol}: ${trades.length}`).join(', ');
14420
+ const symbolCounts = Object.entries(allTrades)
14421
+ .map(([symbol, trades]) => `${symbol}: ${trades.length}`)
14422
+ .join(', ');
14412
14423
  log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
14413
- type: 'info'
14424
+ type: 'info',
14414
14425
  });
14415
14426
  return {
14416
14427
  trades: allTrades,
@@ -14555,7 +14566,9 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14555
14566
  ...(symbol && { symbols: symbol }),
14556
14567
  ...(mergedParams.limit && { limit: Math.min(50, maxLimit - fetchedCount).toString() }),
14557
14568
  ...(mergedParams.sort && { sort: mergedParams.sort }),
14558
- ...(mergedParams.include_content !== undefined ? { include_content: mergedParams.include_content.toString() } : {}),
14569
+ ...(mergedParams.include_content !== undefined
14570
+ ? { include_content: mergedParams.include_content.toString() }
14571
+ : {}),
14559
14572
  ...(pageToken && { page_token: pageToken }),
14560
14573
  });
14561
14574
  const url = `${this.v1beta1url}/news?${queryParams}`;