@discomedia/utils 1.0.33 → 1.0.34

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.
@@ -13862,6 +13862,21 @@ function getLastFullTradingDateImpl(currentDate = new Date()) {
13862
13862
  function getLastFullTradingDate(currentDate = new Date()) {
13863
13863
  return getLastFullTradingDateImpl(currentDate);
13864
13864
  }
13865
+ /**
13866
+ * Returns the trading date for a given time. Note: Just trims the date string; does not validate if the date is a market day.
13867
+ * @param time - a string, number (unix timestamp), or Date object representing the time
13868
+ * @returns the trading date as a string in YYYY-MM-DD format
13869
+ */
13870
+ /**
13871
+ * Returns the trading date for a given time in YYYY-MM-DD format (NY time).
13872
+ * @param time - string, number, or Date
13873
+ * @returns trading date string
13874
+ */
13875
+ function getTradingDate(time) {
13876
+ const date = typeof time === 'number' ? new Date(time) : typeof time === 'string' ? new Date(time) : time;
13877
+ const nyDate = toNYTime(date);
13878
+ return `${nyDate.getUTCFullYear()}-${String(nyDate.getUTCMonth() + 1).padStart(2, '0')}-${String(nyDate.getUTCDate()).padStart(2, '0')}`;
13879
+ }
13865
13880
 
13866
13881
  const log = (message, options = { type: 'info' }) => {
13867
13882
  log$1(message, { ...options, source: 'AlpacaMarketDataAPI' });
@@ -15778,9 +15793,18 @@ class AlpacaTradingAPI {
15778
15793
  // Get the most recent hourly data point
15779
15794
  const mostRecentHourly = recentHourlyData[recentHourlyData.length - 1];
15780
15795
  const mostRecentIndex = mostRecentHourly.index;
15781
- // Calculate the timestamp for the new daily entry (most recent day + 1 day worth of seconds)
15782
- const oneDayInSeconds = 24 * 60 * 60;
15783
- const newDailyTimestamp = mostRecentHourly.timestamp + oneDayInSeconds;
15796
+ // Calculate the timestamp for the new daily entry.
15797
+ // Alpaca's daily history timestamps are at 00:00:00Z for the calendar day
15798
+ // following the NY trading date. Derive the trading date in NY time from the
15799
+ // most recent intraday timestamp, then set the new daily timestamp to
15800
+ // midnight UTC of the next calendar day.
15801
+ const mostRecentMs = mostRecentHourly.timestamp * 1000; // hourly timestamps are seconds
15802
+ const tradingDateStr = getTradingDate(new Date(mostRecentMs)); // e.g., '2025-09-05' (NY trading date)
15803
+ const [yearStr, monthStr, dayStr] = tradingDateStr.split('-');
15804
+ const year = Number(yearStr);
15805
+ const month = Number(monthStr); // 1-based
15806
+ const day = Number(dayStr);
15807
+ const newDailyTimestamp = Math.floor(Date.UTC(year, month - 1, day + 1, 0, 0, 0, 0) / 1000);
15784
15808
  // Create a new daily history entry with the most recent hourly values
15785
15809
  const updatedDailyHistory = {
15786
15810
  ...dailyHistory,