@tradejs/node 3.1.28-beta.253 → 3.1.28-beta.255

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/backtest.js CHANGED
@@ -4515,6 +4515,19 @@ var applyProtectiveOrders = async ({
4515
4515
  takeProfits,
4516
4516
  stopLossPrice
4517
4517
  }) => {
4518
+ if (connector.setPositionProtection) {
4519
+ const protectionOk = await connector.setPositionProtection({
4520
+ symbol,
4521
+ direction,
4522
+ qty,
4523
+ takeProfits,
4524
+ stopLossPrice
4525
+ });
4526
+ if (!protectionOk) {
4527
+ throw new Error("SET_POSITION_PROTECTION_FAILED");
4528
+ }
4529
+ return;
4530
+ }
4518
4531
  if (Array.isArray(takeProfits) && takeProfits.length > 0) {
4519
4532
  const tpOk = await connector.setTakeProfits({
4520
4533
  symbol,
@@ -7469,12 +7482,6 @@ var createTestConnector = (connector, context) => {
7469
7482
  entryPrice: roundPrice(tradeResult.entryPrice),
7470
7483
  requestedExitPrice: roundNullablePrice(tradeResult.requestedExitPrice),
7471
7484
  exitPrice: roundNullablePrice(tradeResult.exitPrice),
7472
- grossProfit: (0, import_math.round)(tradeResult.grossProfit),
7473
- netProfit: (0, import_math.round)(tradeResult.netProfit),
7474
- openFee: (0, import_math.round)(tradeResult.openFee),
7475
- closeFee: (0, import_math.round)(tradeResult.closeFee),
7476
- fundingFee: roundNullable2(tradeResult.fundingFee),
7477
- totalFee: (0, import_math.round)(tradeResult.totalFee),
7478
7485
  entrySlippagePrice: (0, import_math.round)(tradeResult.entrySlippagePrice),
7479
7486
  entrySlippageBps: (0, import_math.round)(tradeResult.entrySlippageBps),
7480
7487
  entryBaseSlippageBps: (0, import_math.round)(tradeResult.entryBaseSlippageBps),
@@ -7482,18 +7489,13 @@ var createTestConnector = (connector, context) => {
7482
7489
  entrySpreadSlippageBps: (0, import_math.round)(tradeResult.entrySpreadSlippageBps),
7483
7490
  entryMarketImpactBps: (0, import_math.round)(tradeResult.entryMarketImpactBps),
7484
7491
  entryDelayRiskBps: roundNullable2(tradeResult.entryDelayRiskBps),
7485
- entrySlippageCost: (0, import_math.round)(tradeResult.entrySlippageCost),
7486
7492
  exitSlippagePrice: roundNullable2(tradeResult.exitSlippagePrice),
7487
7493
  exitSlippageBps: roundNullable2(tradeResult.exitSlippageBps),
7488
7494
  exitBaseSlippageBps: roundNullable2(tradeResult.exitBaseSlippageBps),
7489
7495
  exitSpreadBps: roundNullable2(tradeResult.exitSpreadBps),
7490
7496
  exitSpreadSlippageBps: roundNullable2(tradeResult.exitSpreadSlippageBps),
7491
7497
  exitMarketImpactBps: roundNullable2(tradeResult.exitMarketImpactBps),
7492
- exitDelayRiskBps: roundNullable2(tradeResult.exitDelayRiskBps),
7493
- exitSlippageCost: (0, import_math.round)(tradeResult.exitSlippageCost),
7494
- totalSlippageCost: (0, import_math.round)(tradeResult.totalSlippageCost),
7495
- qty: (0, import_math.round)(tradeResult.qty),
7496
- closedQty: (0, import_math.round)(tradeResult.closedQty)
7498
+ exitDelayRiskBps: roundNullable2(tradeResult.exitDelayRiskBps)
7497
7499
  };
7498
7500
  };
7499
7501
  const appendExitToTradeResult = ({
@@ -7655,7 +7657,7 @@ var createTestConnector = (connector, context) => {
7655
7657
  for (const tradeResult of finalizedCycleResults) {
7656
7658
  closedSignalResults.push({
7657
7659
  signalId: tradeResult.signalId,
7658
- profit: (0, import_math.round)(tradeResult.netProfit),
7660
+ profit: tradeResult.netProfit,
7659
7661
  tradeResult
7660
7662
  });
7661
7663
  }
@@ -7664,7 +7666,7 @@ var createTestConnector = (connector, context) => {
7664
7666
  if (tradeResult) finalizedCycleResults = [tradeResult];
7665
7667
  closedSignalResults.push({
7666
7668
  signalId: currentSignalId,
7667
- profit: (0, import_math.round)(currentPositionProfit),
7669
+ profit: tradeResult?.netProfit ?? currentPositionProfit,
7668
7670
  ...tradeResult ? { tradeResult } : {}
7669
7671
  });
7670
7672
  }
@@ -7679,12 +7681,10 @@ var createTestConnector = (connector, context) => {
7679
7681
  timestamp,
7680
7682
  amount: (0, import_math.round)(amount)
7681
7683
  },
7682
- netProfit: finalizedCycleResults.length ? (0, import_math.round)(
7683
- finalizedCycleResults.reduce(
7684
- (total, tradeResult) => total + tradeResult.netProfit,
7685
- 0
7686
- )
7687
- ) : (0, import_math.round)(currentPositionProfit)
7684
+ netProfit: finalizedCycleResults.length ? finalizedCycleResults.reduce(
7685
+ (total, tradeResult) => total + tradeResult.netProfit,
7686
+ 0
7687
+ ) : currentPositionProfit
7688
7688
  });
7689
7689
  currentPosition = null;
7690
7690
  currentSignalId = null;
package/dist/backtest.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  buildMlPayload,
7
7
  enrichSignalWithMarketContextStages
8
- } from "./chunk-VQSGH7YA.mjs";
8
+ } from "./chunk-JDFPF2RG.mjs";
9
9
  import {
10
10
  buildAiPayload,
11
11
  getStrategyCreator
@@ -411,12 +411,6 @@ var createTestConnector = (connector, context) => {
411
411
  entryPrice: roundPrice(tradeResult.entryPrice),
412
412
  requestedExitPrice: roundNullablePrice(tradeResult.requestedExitPrice),
413
413
  exitPrice: roundNullablePrice(tradeResult.exitPrice),
414
- grossProfit: round(tradeResult.grossProfit),
415
- netProfit: round(tradeResult.netProfit),
416
- openFee: round(tradeResult.openFee),
417
- closeFee: round(tradeResult.closeFee),
418
- fundingFee: roundNullable(tradeResult.fundingFee),
419
- totalFee: round(tradeResult.totalFee),
420
414
  entrySlippagePrice: round(tradeResult.entrySlippagePrice),
421
415
  entrySlippageBps: round(tradeResult.entrySlippageBps),
422
416
  entryBaseSlippageBps: round(tradeResult.entryBaseSlippageBps),
@@ -424,18 +418,13 @@ var createTestConnector = (connector, context) => {
424
418
  entrySpreadSlippageBps: round(tradeResult.entrySpreadSlippageBps),
425
419
  entryMarketImpactBps: round(tradeResult.entryMarketImpactBps),
426
420
  entryDelayRiskBps: roundNullable(tradeResult.entryDelayRiskBps),
427
- entrySlippageCost: round(tradeResult.entrySlippageCost),
428
421
  exitSlippagePrice: roundNullable(tradeResult.exitSlippagePrice),
429
422
  exitSlippageBps: roundNullable(tradeResult.exitSlippageBps),
430
423
  exitBaseSlippageBps: roundNullable(tradeResult.exitBaseSlippageBps),
431
424
  exitSpreadBps: roundNullable(tradeResult.exitSpreadBps),
432
425
  exitSpreadSlippageBps: roundNullable(tradeResult.exitSpreadSlippageBps),
433
426
  exitMarketImpactBps: roundNullable(tradeResult.exitMarketImpactBps),
434
- exitDelayRiskBps: roundNullable(tradeResult.exitDelayRiskBps),
435
- exitSlippageCost: round(tradeResult.exitSlippageCost),
436
- totalSlippageCost: round(tradeResult.totalSlippageCost),
437
- qty: round(tradeResult.qty),
438
- closedQty: round(tradeResult.closedQty)
427
+ exitDelayRiskBps: roundNullable(tradeResult.exitDelayRiskBps)
439
428
  };
440
429
  };
441
430
  const appendExitToTradeResult = ({
@@ -597,7 +586,7 @@ var createTestConnector = (connector, context) => {
597
586
  for (const tradeResult of finalizedCycleResults) {
598
587
  closedSignalResults.push({
599
588
  signalId: tradeResult.signalId,
600
- profit: round(tradeResult.netProfit),
589
+ profit: tradeResult.netProfit,
601
590
  tradeResult
602
591
  });
603
592
  }
@@ -606,7 +595,7 @@ var createTestConnector = (connector, context) => {
606
595
  if (tradeResult) finalizedCycleResults = [tradeResult];
607
596
  closedSignalResults.push({
608
597
  signalId: currentSignalId,
609
- profit: round(currentPositionProfit),
598
+ profit: tradeResult?.netProfit ?? currentPositionProfit,
610
599
  ...tradeResult ? { tradeResult } : {}
611
600
  });
612
601
  }
@@ -621,12 +610,10 @@ var createTestConnector = (connector, context) => {
621
610
  timestamp,
622
611
  amount: round(amount)
623
612
  },
624
- netProfit: finalizedCycleResults.length ? round(
625
- finalizedCycleResults.reduce(
626
- (total, tradeResult) => total + tradeResult.netProfit,
627
- 0
628
- )
629
- ) : round(currentPositionProfit)
613
+ netProfit: finalizedCycleResults.length ? finalizedCycleResults.reduce(
614
+ (total, tradeResult) => total + tradeResult.netProfit,
615
+ 0
616
+ ) : currentPositionProfit
630
617
  });
631
618
  currentPosition = null;
632
619
  currentSignalId = null;
@@ -2925,6 +2925,19 @@ var applyProtectiveOrders = async ({
2925
2925
  takeProfits,
2926
2926
  stopLossPrice
2927
2927
  }) => {
2928
+ if (connector.setPositionProtection) {
2929
+ const protectionOk = await connector.setPositionProtection({
2930
+ symbol,
2931
+ direction,
2932
+ qty,
2933
+ takeProfits,
2934
+ stopLossPrice
2935
+ });
2936
+ if (!protectionOk) {
2937
+ throw new Error("SET_POSITION_PROTECTION_FAILED");
2938
+ }
2939
+ return;
2940
+ }
2928
2941
  if (Array.isArray(takeProfits) && takeProfits.length > 0) {
2929
2942
  const tpOk = await connector.setTakeProfits({
2930
2943
  symbol,
package/dist/registry.js CHANGED
@@ -4553,6 +4553,19 @@ var applyProtectiveOrders = async ({
4553
4553
  takeProfits,
4554
4554
  stopLossPrice
4555
4555
  }) => {
4556
+ if (connector.setPositionProtection) {
4557
+ const protectionOk = await connector.setPositionProtection({
4558
+ symbol,
4559
+ direction,
4560
+ qty,
4561
+ takeProfits,
4562
+ stopLossPrice
4563
+ });
4564
+ if (!protectionOk) {
4565
+ throw new Error("SET_POSITION_PROTECTION_FAILED");
4566
+ }
4567
+ return;
4568
+ }
4556
4569
  if (Array.isArray(takeProfits) && takeProfits.length > 0) {
4557
4570
  const tpOk = await connector.setTakeProfits({
4558
4571
  symbol,
package/dist/registry.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import "./chunk-VQSGH7YA.mjs";
1
+ import "./chunk-JDFPF2RG.mjs";
2
2
  import {
3
3
  ensureIndicatorPluginsLoaded,
4
4
  ensureStrategyPluginsLoaded,
@@ -5534,6 +5534,19 @@ var applyProtectiveOrders = async ({
5534
5534
  takeProfits,
5535
5535
  stopLossPrice
5536
5536
  }) => {
5537
+ if (connector.setPositionProtection) {
5538
+ const protectionOk = await connector.setPositionProtection({
5539
+ symbol,
5540
+ direction,
5541
+ qty,
5542
+ takeProfits,
5543
+ stopLossPrice
5544
+ });
5545
+ if (!protectionOk) {
5546
+ throw new Error("SET_POSITION_PROTECTION_FAILED");
5547
+ }
5548
+ return;
5549
+ }
5537
5550
  if (Array.isArray(takeProfits) && takeProfits.length > 0) {
5538
5551
  const tpOk = await connector.setTakeProfits({
5539
5552
  symbol,
@@ -8272,7 +8285,7 @@ var buildStrategyRevisionChanges = ({
8272
8285
  endTime
8273
8286
  }) => {
8274
8287
  const changes = [];
8275
- let previousRevision;
8288
+ let previousStrategy;
8276
8289
  let wasPresent = false;
8277
8290
  for (const event of [...events].sort(
8278
8291
  (left, right) => left.observedAt - right.observedAt || left.eventId.localeCompare(right.eventId)
@@ -8281,17 +8294,20 @@ var buildStrategyRevisionChanges = ({
8281
8294
  (item) => item.strategyName === strategyName
8282
8295
  );
8283
8296
  if (!strategy) {
8284
- previousRevision = void 0;
8285
8297
  wasPresent = false;
8286
8298
  continue;
8287
8299
  }
8288
- if ((!wasPresent || strategy.strategyRevision !== previousRevision) && event.observedAt >= startTime && event.observedAt <= endTime) {
8300
+ if ((!wasPresent || strategy.strategyRevision !== previousStrategy?.strategyRevision) && event.observedAt >= startTime && event.observedAt <= endTime) {
8301
+ const strategyPackageChanged = Boolean(
8302
+ previousStrategy?.strategyPackage && previousStrategy.strategyPackageVersion && strategy.strategyPackage && strategy.strategyPackageVersion && (strategy.strategyPackage !== previousStrategy.strategyPackage || strategy.strategyPackageVersion !== previousStrategy.strategyPackageVersion)
8303
+ );
8289
8304
  changes.push({
8290
8305
  timestamp: event.observedAt,
8291
- strategyRevision: strategy.strategyRevision
8306
+ strategyRevision: strategy.strategyRevision,
8307
+ kind: strategyPackageChanged ? "strategy_package" : "other"
8292
8308
  });
8293
8309
  }
8294
- previousRevision = strategy.strategyRevision;
8310
+ previousStrategy = strategy;
8295
8311
  wasPresent = true;
8296
8312
  }
8297
8313
  return changes;
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  getConnectorCreatorByProvider
11
11
  } from "./chunk-QVKUROR2.mjs";
12
- import "./chunk-VQSGH7YA.mjs";
12
+ import "./chunk-JDFPF2RG.mjs";
13
13
  import "./chunk-UITD6LG6.mjs";
14
14
  import "./chunk-LZDXRXIU.mjs";
15
15
  import "./chunk-Y6FXYEAI.mjs";
@@ -375,7 +375,7 @@ var buildStrategyRevisionChanges = ({
375
375
  endTime
376
376
  }) => {
377
377
  const changes = [];
378
- let previousRevision;
378
+ let previousStrategy;
379
379
  let wasPresent = false;
380
380
  for (const event of [...events].sort(
381
381
  (left, right) => left.observedAt - right.observedAt || left.eventId.localeCompare(right.eventId)
@@ -384,17 +384,20 @@ var buildStrategyRevisionChanges = ({
384
384
  (item) => item.strategyName === strategyName
385
385
  );
386
386
  if (!strategy) {
387
- previousRevision = void 0;
388
387
  wasPresent = false;
389
388
  continue;
390
389
  }
391
- if ((!wasPresent || strategy.strategyRevision !== previousRevision) && event.observedAt >= startTime && event.observedAt <= endTime) {
390
+ if ((!wasPresent || strategy.strategyRevision !== previousStrategy?.strategyRevision) && event.observedAt >= startTime && event.observedAt <= endTime) {
391
+ const strategyPackageChanged = Boolean(
392
+ previousStrategy?.strategyPackage && previousStrategy.strategyPackageVersion && strategy.strategyPackage && strategy.strategyPackageVersion && (strategy.strategyPackage !== previousStrategy.strategyPackage || strategy.strategyPackageVersion !== previousStrategy.strategyPackageVersion)
393
+ );
392
394
  changes.push({
393
395
  timestamp: event.observedAt,
394
- strategyRevision: strategy.strategyRevision
396
+ strategyRevision: strategy.strategyRevision,
397
+ kind: strategyPackageChanged ? "strategy_package" : "other"
395
398
  });
396
399
  }
397
- previousRevision = strategy.strategyRevision;
400
+ previousStrategy = strategy;
398
401
  wasPresent = true;
399
402
  }
400
403
  return changes;
@@ -4531,6 +4531,19 @@ var applyProtectiveOrders = async ({
4531
4531
  takeProfits,
4532
4532
  stopLossPrice
4533
4533
  }) => {
4534
+ if (connector.setPositionProtection) {
4535
+ const protectionOk = await connector.setPositionProtection({
4536
+ symbol,
4537
+ direction,
4538
+ qty,
4539
+ takeProfits,
4540
+ stopLossPrice
4541
+ });
4542
+ if (!protectionOk) {
4543
+ throw new Error("SET_POSITION_PROTECTION_FAILED");
4544
+ }
4545
+ return;
4546
+ }
4534
4547
  if (Array.isArray(takeProfits) && takeProfits.length > 0) {
4535
4548
  const tpOk = await connector.setTakeProfits({
4536
4549
  symbol,
@@ -9,7 +9,7 @@ import {
9
9
  resolveRuntimeComposition,
10
10
  verifyRuntimeDeclaration
11
11
  } from "./chunk-K2YQ3MQC.mjs";
12
- import "./chunk-VQSGH7YA.mjs";
12
+ import "./chunk-JDFPF2RG.mjs";
13
13
  import "./chunk-UITD6LG6.mjs";
14
14
  import "./chunk-LZDXRXIU.mjs";
15
15
  import "./chunk-Y6FXYEAI.mjs";
@@ -4794,6 +4794,19 @@ var applyProtectiveOrders = async ({
4794
4794
  takeProfits,
4795
4795
  stopLossPrice
4796
4796
  }) => {
4797
+ if (connector.setPositionProtection) {
4798
+ const protectionOk = await connector.setPositionProtection({
4799
+ symbol,
4800
+ direction,
4801
+ qty,
4802
+ takeProfits,
4803
+ stopLossPrice
4804
+ });
4805
+ if (!protectionOk) {
4806
+ throw new Error("SET_POSITION_PROTECTION_FAILED");
4807
+ }
4808
+ return;
4809
+ }
4797
4810
  if (Array.isArray(takeProfits) && takeProfits.length > 0) {
4798
4811
  const tpOk = await connector.setTakeProfits({
4799
4812
  symbol,
@@ -23,7 +23,7 @@ import {
23
23
  resolveHyperliquidPerpFromSignalSymbol,
24
24
  resolveStrategyConfig,
25
25
  validateEntryProtectionAtArrival
26
- } from "./chunk-VQSGH7YA.mjs";
26
+ } from "./chunk-JDFPF2RG.mjs";
27
27
  import {
28
28
  DEFAULT_AI_MODEL,
29
29
  MAX_AI_SERIES_POINTS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradejs/node",
3
- "version": "3.1.28-beta.253",
3
+ "version": "3.1.28-beta.255",
4
4
  "description": "Node-only runtime for the TradeJS TypeScript framework: strategies, backtests, Pine strategy loading, and plugin registries.",
5
5
  "keywords": [
6
6
  "tradejs",
@@ -89,9 +89,9 @@
89
89
  "dependencies": {
90
90
  "@langchain/core": "^1.2.3",
91
91
  "@langchain/openai": "^1.5.5",
92
- "@tradejs/core": "^3.1.28-beta.253",
93
- "@tradejs/infra": "^3.1.28-beta.253",
94
- "@tradejs/types": "^3.1.28-beta.253",
92
+ "@tradejs/core": "^3.1.28-beta.255",
93
+ "@tradejs/infra": "^3.1.28-beta.255",
94
+ "@tradejs/types": "^3.1.28-beta.255",
95
95
  "@types/node": "^24",
96
96
  "chalk": "4.1.2",
97
97
  "ioredis": "5.11.1",
@@ -104,10 +104,10 @@
104
104
  "typescript": "^5.9"
105
105
  },
106
106
  "devDependencies": {
107
- "@tradejs/indicators": "^3.1.28-beta.253",
107
+ "@tradejs/indicators": "^3.1.28-beta.255",
108
108
  "@tradejs/strategy-adaptive-momentum-ribbon": "3.0.2",
109
109
  "@tradejs/strategy-hyperliquid-consensus": "3.0.2",
110
- "@tradejs/strategy-kit": "3.0.4",
110
+ "@tradejs/strategy-kit": "3.0.5",
111
111
  "@tradejs/strategy-trend-line": "3.0.2",
112
112
  "@tradejs/strategy-volume-divergence": "3.0.2",
113
113
  "tsup": "^8.5.1"