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