@tradejs/core 3.1.29-beta.292 → 3.1.29-beta.296
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/strategies.js +10 -4
- package/dist/strategies.mjs +10 -4
- package/package.json +2 -2
package/dist/strategies.js
CHANGED
|
@@ -12097,9 +12097,10 @@ var resolveTakeProfitPrice = ({
|
|
|
12097
12097
|
direction,
|
|
12098
12098
|
takeProfits
|
|
12099
12099
|
}) => {
|
|
12100
|
-
if (!Array.isArray(takeProfits)
|
|
12101
|
-
throw new Error("strategyApi.entry requires
|
|
12100
|
+
if (!Array.isArray(takeProfits)) {
|
|
12101
|
+
throw new Error("strategyApi.entry requires a takeProfits array");
|
|
12102
12102
|
}
|
|
12103
|
+
if (takeProfits.length === 0) return null;
|
|
12103
12104
|
const prices = takeProfits.map((tp) => tp?.price).filter((price) => isFiniteNumber2(price));
|
|
12104
12105
|
if (prices.length === 0) {
|
|
12105
12106
|
throw new Error("strategyApi.entry requires finite takeProfit prices");
|
|
@@ -12281,8 +12282,13 @@ var createStrategyAPI = ({
|
|
|
12281
12282
|
"strategyApi.entry requires finite orderPlan.stopLossPrice"
|
|
12282
12283
|
);
|
|
12283
12284
|
}
|
|
12285
|
+
if (orderPlan.stopLossDistance != null && (!isFiniteNumber2(orderPlan.stopLossDistance) || orderPlan.stopLossDistance <= 0 || orderPlan.positionIntent === "increase")) {
|
|
12286
|
+
throw new Error(
|
|
12287
|
+
"strategyApi.entry requires a positive stopLossDistance for an opening order"
|
|
12288
|
+
);
|
|
12289
|
+
}
|
|
12284
12290
|
const resolvedCode = code ?? toDefaultEntryCode(String(strategy), direction);
|
|
12285
|
-
const riskRatio = calculateRiskRatio({
|
|
12291
|
+
const riskRatio = takeProfitPrice == null ? 0 : calculateRiskRatio({
|
|
12286
12292
|
direction,
|
|
12287
12293
|
currentPrice,
|
|
12288
12294
|
takeProfitPrice,
|
|
@@ -12298,7 +12304,7 @@ var createStrategyAPI = ({
|
|
|
12298
12304
|
timestamp,
|
|
12299
12305
|
prices: {
|
|
12300
12306
|
currentPrice,
|
|
12301
|
-
takeProfitPrice,
|
|
12307
|
+
takeProfitPrice: takeProfitPrice ?? currentPrice,
|
|
12302
12308
|
stopLossPrice,
|
|
12303
12309
|
riskRatio
|
|
12304
12310
|
},
|
package/dist/strategies.mjs
CHANGED
|
@@ -1333,9 +1333,10 @@ var resolveTakeProfitPrice = ({
|
|
|
1333
1333
|
direction,
|
|
1334
1334
|
takeProfits
|
|
1335
1335
|
}) => {
|
|
1336
|
-
if (!Array.isArray(takeProfits)
|
|
1337
|
-
throw new Error("strategyApi.entry requires
|
|
1336
|
+
if (!Array.isArray(takeProfits)) {
|
|
1337
|
+
throw new Error("strategyApi.entry requires a takeProfits array");
|
|
1338
1338
|
}
|
|
1339
|
+
if (takeProfits.length === 0) return null;
|
|
1339
1340
|
const prices = takeProfits.map((tp) => tp?.price).filter((price) => isFiniteNumber(price));
|
|
1340
1341
|
if (prices.length === 0) {
|
|
1341
1342
|
throw new Error("strategyApi.entry requires finite takeProfit prices");
|
|
@@ -1517,8 +1518,13 @@ var createStrategyAPI = ({
|
|
|
1517
1518
|
"strategyApi.entry requires finite orderPlan.stopLossPrice"
|
|
1518
1519
|
);
|
|
1519
1520
|
}
|
|
1521
|
+
if (orderPlan.stopLossDistance != null && (!isFiniteNumber(orderPlan.stopLossDistance) || orderPlan.stopLossDistance <= 0 || orderPlan.positionIntent === "increase")) {
|
|
1522
|
+
throw new Error(
|
|
1523
|
+
"strategyApi.entry requires a positive stopLossDistance for an opening order"
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1520
1526
|
const resolvedCode = code ?? toDefaultEntryCode(String(strategy), direction);
|
|
1521
|
-
const riskRatio = calculateRiskRatio({
|
|
1527
|
+
const riskRatio = takeProfitPrice == null ? 0 : calculateRiskRatio({
|
|
1522
1528
|
direction,
|
|
1523
1529
|
currentPrice,
|
|
1524
1530
|
takeProfitPrice,
|
|
@@ -1534,7 +1540,7 @@ var createStrategyAPI = ({
|
|
|
1534
1540
|
timestamp,
|
|
1535
1541
|
prices: {
|
|
1536
1542
|
currentPrice,
|
|
1537
|
-
takeProfitPrice,
|
|
1543
|
+
takeProfitPrice: takeProfitPrice ?? currentPrice,
|
|
1538
1544
|
stopLossPrice,
|
|
1539
1545
|
riskRatio
|
|
1540
1546
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/core",
|
|
3
|
-
"version": "3.1.29-beta.
|
|
3
|
+
"version": "3.1.29-beta.296",
|
|
4
4
|
"description": "MIT-licensed browser-safe API for TradeJS config, strategy authoring, figures, and shared helpers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
}
|
|
154
154
|
},
|
|
155
155
|
"dependencies": {
|
|
156
|
-
"@tradejs/types": "^3.1.29-beta.
|
|
156
|
+
"@tradejs/types": "^3.1.29-beta.296",
|
|
157
157
|
"date-fns": "^3.6.0",
|
|
158
158
|
"fast-technical-indicators": "^1.1.4",
|
|
159
159
|
"klinecharts": "10.0.0-alpha9",
|