@adaptic/utils 0.0.971 → 0.0.973

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
@@ -3262,11 +3262,16 @@ class AlpacaMarketDataAPI extends require$$0$1.EventEmitter {
3262
3262
  async getPreviousClose(symbol, referenceDate) {
3263
3263
  const date = referenceDate || new Date();
3264
3264
  const prevMarketDate = getLastFullTradingDate(date);
3265
+ // Alpaca bars use inclusive-start, exclusive-end (t >= start AND t < end).
3266
+ // When start === end the range is empty and zero bars are returned.
3267
+ // Set end to the next calendar day to capture exactly one daily bar.
3268
+ const endDate = new Date(prevMarketDate.date);
3269
+ endDate.setDate(endDate.getDate() + 1);
3265
3270
  const response = await this.getHistoricalBars({
3266
3271
  symbols: [symbol],
3267
3272
  timeframe: "1Day",
3268
3273
  start: prevMarketDate.date.toISOString(),
3269
- end: prevMarketDate.date.toISOString(),
3274
+ end: endDate.toISOString(),
3270
3275
  limit: 1,
3271
3276
  });
3272
3277
  if (!response.bars[symbol] || response.bars[symbol].length === 0) {
@@ -50902,6 +50907,13 @@ var orderUtils$1 = /*#__PURE__*/Object.freeze({
50902
50907
  });
50903
50908
 
50904
50909
  const LOG_SOURCE$7 = "TrailingStops";
50910
+ /**
50911
+ * Alpaca's hard upper limit for `trail_percent` on trailing-stop orders.
50912
+ * Submissions exceeding this value are rejected with HTTP 422 / code 42210000
50913
+ * ("trail_percent must be <= 25"). See:
50914
+ * https://docs.alpaca.markets/reference/postorder
50915
+ */
50916
+ const ALPACA_MAX_TRAIL_PERCENT = 25;
50905
50917
  /**
50906
50918
  * Internal logging helper with consistent source
50907
50919
  */
@@ -50929,13 +50941,13 @@ function validateTrailingStopParams(params) {
50929
50941
  if (params.trailPercent !== undefined && params.trailPrice !== undefined) {
50930
50942
  throw new TrailingStopValidationError("Cannot specify both trailPercent and trailPrice");
50931
50943
  }
50932
- // Validate trailPercent range
50944
+ // Validate trailPercent range — Alpaca rejects values > 25 with HTTP 422.
50933
50945
  if (params.trailPercent !== undefined) {
50934
50946
  if (params.trailPercent <= 0) {
50935
50947
  throw new TrailingStopValidationError("trailPercent must be greater than 0");
50936
50948
  }
50937
- if (params.trailPercent > 100) {
50938
- throw new TrailingStopValidationError("trailPercent cannot exceed 100");
50949
+ if (params.trailPercent > ALPACA_MAX_TRAIL_PERCENT) {
50950
+ throw new TrailingStopValidationError(`trailPercent cannot exceed ${ALPACA_MAX_TRAIL_PERCENT} (Alpaca API limit)`);
50939
50951
  }
50940
50952
  }
50941
50953
  // Validate trailPrice
@@ -51378,6 +51390,7 @@ var trailingStops = {
51378
51390
 
51379
51391
  var trailingStops$1 = /*#__PURE__*/Object.freeze({
51380
51392
  __proto__: null,
51393
+ ALPACA_MAX_TRAIL_PERCENT: ALPACA_MAX_TRAIL_PERCENT,
51381
51394
  TrailingStopValidationError: TrailingStopValidationError,
51382
51395
  cancelTrailingStop: cancelTrailingStop,
51383
51396
  cancelTrailingStopsForSymbol: cancelTrailingStopsForSymbol,
@@ -58575,6 +58588,7 @@ var smartOrders = {
58575
58588
 
58576
58589
  var smartOrders$1 = /*#__PURE__*/Object.freeze({
58577
58590
  __proto__: null,
58591
+ ALPACA_MAX_TRAIL_PERCENT: ALPACA_MAX_TRAIL_PERCENT,
58578
58592
  TrailingStopValidationError: TrailingStopValidationError,
58579
58593
  buyWithStopLoss: buyWithStopLoss,
58580
58594
  buyWithTrailingStop: buyWithTrailingStop,