@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.
@@ -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;
@@ -13997,7 +14000,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
13997
14000
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
13998
14001
  : 'unknown range';
13999
14002
  log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
14000
- type: 'info'
14003
+ type: 'info',
14001
14004
  });
14002
14005
  // Prevent infinite loops
14003
14006
  if (pageCount > 1000) {
@@ -14006,9 +14009,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14006
14009
  }
14007
14010
  }
14008
14011
  // Final summary
14009
- 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(', ');
14010
14015
  log(`Historical bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
14011
- type: 'info'
14016
+ type: 'info',
14012
14017
  });
14013
14018
  return {
14014
14019
  bars: allBars,
@@ -14276,11 +14281,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14276
14281
  let totalBarsCount = 0;
14277
14282
  let pageCount = 0;
14278
14283
  // Initialize bar arrays for each symbol
14279
- symbols.forEach(symbol => {
14284
+ symbols.forEach((symbol) => {
14280
14285
  allBars[symbol] = [];
14281
14286
  });
14282
- log(`Starting historical options bars fetch for ${symbolsStr} (${params.timeframe}, ${params.start || 'no start'} to ${params.end || 'no end'})`, {
14283
- 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',
14284
14289
  });
14285
14290
  while (hasMorePages) {
14286
14291
  pageCount++;
@@ -14290,7 +14295,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14290
14295
  };
14291
14296
  const response = await this.makeRequest('/options/bars', 'GET', requestParams, 'v1beta1');
14292
14297
  if (!response.bars) {
14293
- 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' });
14294
14299
  break;
14295
14300
  }
14296
14301
  // Combine bars for each symbol
@@ -14302,7 +14307,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14302
14307
  allBars[symbol] = [...allBars[symbol], ...bars];
14303
14308
  pageBarsCount += bars.length;
14304
14309
  // Track date range for this page
14305
- bars.forEach(bar => {
14310
+ bars.forEach((bar) => {
14306
14311
  const barDate = new Date(bar.t);
14307
14312
  if (!earliestTimestamp || barDate < earliestTimestamp) {
14308
14313
  earliestTimestamp = barDate;
@@ -14321,7 +14326,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14321
14326
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
14322
14327
  : 'unknown range';
14323
14328
  log(`Page ${pageCount}: Fetched ${pageBarsCount.toLocaleString()} option bars (total: ${totalBarsCount.toLocaleString()}) for ${symbolsStr}, date range: ${dateRangeStr}${hasMorePages ? ', more pages available' : ', complete'}`, {
14324
- type: 'info'
14329
+ type: 'info',
14325
14330
  });
14326
14331
  // Prevent infinite loops
14327
14332
  if (pageCount > 1000) {
@@ -14330,9 +14335,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14330
14335
  }
14331
14336
  }
14332
14337
  // Final summary
14333
- 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(', ');
14334
14341
  log(`Historical options bars fetch complete: ${totalBarsCount.toLocaleString()} total bars across ${pageCount} pages (${symbolCounts})`, {
14335
- type: 'info'
14342
+ type: 'info',
14336
14343
  });
14337
14344
  return {
14338
14345
  bars: allBars,
@@ -14356,11 +14363,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14356
14363
  let totalTradesCount = 0;
14357
14364
  let pageCount = 0;
14358
14365
  // Initialize trades arrays for each symbol
14359
- symbols.forEach(symbol => {
14366
+ symbols.forEach((symbol) => {
14360
14367
  allTrades[symbol] = [];
14361
14368
  });
14362
- log(`Starting historical options trades fetch for ${symbolsStr} (${params.start || 'no start'} to ${params.end || 'no end'})`, {
14363
- 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',
14364
14371
  });
14365
14372
  while (hasMorePages) {
14366
14373
  pageCount++;
@@ -14370,7 +14377,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14370
14377
  };
14371
14378
  const response = await this.makeRequest('/options/trades', 'GET', requestParams, 'v1beta1');
14372
14379
  if (!response.trades) {
14373
- 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' });
14374
14381
  break;
14375
14382
  }
14376
14383
  // Combine trades for each symbol
@@ -14382,7 +14389,7 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14382
14389
  allTrades[symbol] = [...allTrades[symbol], ...trades];
14383
14390
  pageTradesCount += trades.length;
14384
14391
  // Track date range for this page
14385
- trades.forEach(trade => {
14392
+ trades.forEach((trade) => {
14386
14393
  const tradeDate = new Date(trade.t);
14387
14394
  if (!earliestTimestamp || tradeDate < earliestTimestamp) {
14388
14395
  earliestTimestamp = tradeDate;
@@ -14400,8 +14407,8 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14400
14407
  const dateRangeStr = earliestTimestamp && latestTimestamp
14401
14408
  ? `${earliestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })} to ${latestTimestamp.toLocaleDateString('en-US', { timeZone: 'America/New_York' })}`
14402
14409
  : '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'
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',
14405
14412
  });
14406
14413
  // Prevent infinite loops
14407
14414
  if (pageCount > 1000) {
@@ -14410,9 +14417,11 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14410
14417
  }
14411
14418
  }
14412
14419
  // Final summary
14413
- 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(', ');
14414
14423
  log(`Historical options trades fetch complete: ${totalTradesCount.toLocaleString()} total trades across ${pageCount} pages (${symbolCounts})`, {
14415
- type: 'info'
14424
+ type: 'info',
14416
14425
  });
14417
14426
  return {
14418
14427
  trades: allTrades,
@@ -14557,7 +14566,9 @@ class AlpacaMarketDataAPI extends require$$0$3.EventEmitter {
14557
14566
  ...(symbol && { symbols: symbol }),
14558
14567
  ...(mergedParams.limit && { limit: Math.min(50, maxLimit - fetchedCount).toString() }),
14559
14568
  ...(mergedParams.sort && { sort: mergedParams.sort }),
14560
- ...(mergedParams.include_content !== undefined ? { include_content: mergedParams.include_content.toString() } : {}),
14569
+ ...(mergedParams.include_content !== undefined
14570
+ ? { include_content: mergedParams.include_content.toString() }
14571
+ : {}),
14561
14572
  ...(pageToken && { page_token: pageToken }),
14562
14573
  });
14563
14574
  const url = `${this.v1beta1url}/news?${queryParams}`;