@tradejs/core 2.0.19 → 2.0.21
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.d.mts +1 -1
- package/dist/strategies.d.ts +1 -1
- package/dist/strategies.js +51 -11
- package/dist/strategies.mjs +51 -11
- package/package.json +2 -2
package/dist/strategies.d.mts
CHANGED
|
@@ -129,6 +129,6 @@ interface CreateLastTradeControllerParams {
|
|
|
129
129
|
enabled?: boolean;
|
|
130
130
|
cooldownMs?: number;
|
|
131
131
|
}
|
|
132
|
-
declare const createLastTradeController: (
|
|
132
|
+
declare const createLastTradeController: (params: CreateLastTradeControllerParams) => LastTradeController;
|
|
133
133
|
|
|
134
134
|
export { buildBaseContextGateFeatures, buildDefaultIndicatorPeriods, buildEntrySignalDecision, buildStrategySignal, calculateRiskRatio, createLastTradeController, createStrategyAPI, createStrategyIndicatorsState, getDirectionalTpSlPrices, getSharedStrategyReplayState, getStrategyMarketSnapshot, mapAiRuntimeFromConfig, mapMlRuntimeFromConfig, refreshSignalBaseContextGateFeatures, releaseStrategyIndicatorsReplayCache, releaseStrategyReplayCache, resolveBacktestExecutionPrice };
|
package/dist/strategies.d.ts
CHANGED
|
@@ -129,6 +129,6 @@ interface CreateLastTradeControllerParams {
|
|
|
129
129
|
enabled?: boolean;
|
|
130
130
|
cooldownMs?: number;
|
|
131
131
|
}
|
|
132
|
-
declare const createLastTradeController: (
|
|
132
|
+
declare const createLastTradeController: (params: CreateLastTradeControllerParams) => LastTradeController;
|
|
133
133
|
|
|
134
134
|
export { buildBaseContextGateFeatures, buildDefaultIndicatorPeriods, buildEntrySignalDecision, buildStrategySignal, calculateRiskRatio, createLastTradeController, createStrategyAPI, createStrategyIndicatorsState, getDirectionalTpSlPrices, getSharedStrategyReplayState, getStrategyMarketSnapshot, mapAiRuntimeFromConfig, mapMlRuntimeFromConfig, refreshSignalBaseContextGateFeatures, releaseStrategyIndicatorsReplayCache, releaseStrategyReplayCache, resolveBacktestExecutionPrice };
|
package/dist/strategies.js
CHANGED
|
@@ -11065,23 +11065,46 @@ var getDirectionalTpSlPrices = ({
|
|
|
11065
11065
|
};
|
|
11066
11066
|
|
|
11067
11067
|
// src/utils/strategyHelpers/state.ts
|
|
11068
|
-
var
|
|
11068
|
+
var resolveLastTradeControllerParams = ({
|
|
11069
11069
|
env,
|
|
11070
11070
|
enabled = env ? env === "BACKTEST" : true,
|
|
11071
11071
|
cooldownMs = 864e5
|
|
11072
|
+
}) => ({
|
|
11073
|
+
enabled,
|
|
11074
|
+
cooldownMs
|
|
11075
|
+
});
|
|
11076
|
+
var createStateBackedLastTradeController = ({
|
|
11077
|
+
state,
|
|
11078
|
+
enabled,
|
|
11079
|
+
cooldownMs
|
|
11072
11080
|
}) => {
|
|
11073
|
-
|
|
11081
|
+
const getLastTradeTimestamp = () => state.get().lastTradeTimestamp;
|
|
11074
11082
|
return {
|
|
11075
|
-
isInCooldown: (timestamp) =>
|
|
11076
|
-
|
|
11077
|
-
|
|
11083
|
+
isInCooldown: (timestamp) => {
|
|
11084
|
+
const lastTradeTimestamp = getLastTradeTimestamp();
|
|
11085
|
+
return Boolean(
|
|
11086
|
+
enabled && lastTradeTimestamp != null && timestamp <= lastTradeTimestamp + cooldownMs
|
|
11087
|
+
);
|
|
11088
|
+
},
|
|
11078
11089
|
markTrade: (timestamp) => {
|
|
11079
11090
|
if (!enabled) return;
|
|
11080
|
-
|
|
11091
|
+
state.update((current) => {
|
|
11092
|
+
current.lastTradeTimestamp = timestamp;
|
|
11093
|
+
});
|
|
11081
11094
|
},
|
|
11082
|
-
getLastTradeTimestamp
|
|
11095
|
+
getLastTradeTimestamp
|
|
11083
11096
|
};
|
|
11084
11097
|
};
|
|
11098
|
+
var createLastTradeController = (params) => {
|
|
11099
|
+
const state = { lastTradeTimestamp: null };
|
|
11100
|
+
return createStateBackedLastTradeController({
|
|
11101
|
+
...resolveLastTradeControllerParams(params),
|
|
11102
|
+
state: {
|
|
11103
|
+
get: () => state,
|
|
11104
|
+
update: (fn) => fn(state)
|
|
11105
|
+
}
|
|
11106
|
+
});
|
|
11107
|
+
};
|
|
11085
11108
|
var stableStringify = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
11086
11109
|
if (value == null) {
|
|
11087
11110
|
return String(value);
|
|
@@ -12022,6 +12045,7 @@ var createStrategyAPI = ({
|
|
|
12022
12045
|
sharedReplayKey,
|
|
12023
12046
|
getSharedReplayState
|
|
12024
12047
|
});
|
|
12048
|
+
let lastTradeControllerIndex = 0;
|
|
12025
12049
|
const getBaseContextFromIndicators = (indicators) => isRecordLike(indicators) && isRecordLike(indicators.baseContext) ? indicators.baseContext : void 0;
|
|
12026
12050
|
const getCurrentIndicatorsContext = () => {
|
|
12027
12051
|
ensureBarCache();
|
|
@@ -12174,10 +12198,26 @@ var createStrategyAPI = ({
|
|
|
12174
12198
|
getDecisionPriceContext,
|
|
12175
12199
|
getCurrentPosition,
|
|
12176
12200
|
getDirectionalTpSlPrices: (params) => getDirectionalTpSlPrices(params),
|
|
12177
|
-
createLastTradeController: (params) =>
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12201
|
+
createLastTradeController: (params) => {
|
|
12202
|
+
const resolvedParams = resolveLastTradeControllerParams({
|
|
12203
|
+
env,
|
|
12204
|
+
...params
|
|
12205
|
+
});
|
|
12206
|
+
const controllerIndex = lastTradeControllerIndex;
|
|
12207
|
+
lastTradeControllerIndex += 1;
|
|
12208
|
+
const state = createStateController(
|
|
12209
|
+
`__tradejs:last-trade:${controllerIndex}`,
|
|
12210
|
+
() => ({ lastTradeTimestamp: null }),
|
|
12211
|
+
{
|
|
12212
|
+
configKey: JSON.stringify(resolvedParams),
|
|
12213
|
+
sharedReplay: env === "CRON"
|
|
12214
|
+
}
|
|
12215
|
+
);
|
|
12216
|
+
return createStateBackedLastTradeController({
|
|
12217
|
+
...resolvedParams,
|
|
12218
|
+
state
|
|
12219
|
+
});
|
|
12220
|
+
},
|
|
12181
12221
|
createStateController
|
|
12182
12222
|
};
|
|
12183
12223
|
};
|
package/dist/strategies.mjs
CHANGED
|
@@ -380,23 +380,46 @@ var getDirectionalTpSlPrices = ({
|
|
|
380
380
|
};
|
|
381
381
|
|
|
382
382
|
// src/utils/strategyHelpers/state.ts
|
|
383
|
-
var
|
|
383
|
+
var resolveLastTradeControllerParams = ({
|
|
384
384
|
env,
|
|
385
385
|
enabled = env ? env === "BACKTEST" : true,
|
|
386
386
|
cooldownMs = 864e5
|
|
387
|
+
}) => ({
|
|
388
|
+
enabled,
|
|
389
|
+
cooldownMs
|
|
390
|
+
});
|
|
391
|
+
var createStateBackedLastTradeController = ({
|
|
392
|
+
state,
|
|
393
|
+
enabled,
|
|
394
|
+
cooldownMs
|
|
387
395
|
}) => {
|
|
388
|
-
|
|
396
|
+
const getLastTradeTimestamp = () => state.get().lastTradeTimestamp;
|
|
389
397
|
return {
|
|
390
|
-
isInCooldown: (timestamp) =>
|
|
391
|
-
|
|
392
|
-
|
|
398
|
+
isInCooldown: (timestamp) => {
|
|
399
|
+
const lastTradeTimestamp = getLastTradeTimestamp();
|
|
400
|
+
return Boolean(
|
|
401
|
+
enabled && lastTradeTimestamp != null && timestamp <= lastTradeTimestamp + cooldownMs
|
|
402
|
+
);
|
|
403
|
+
},
|
|
393
404
|
markTrade: (timestamp) => {
|
|
394
405
|
if (!enabled) return;
|
|
395
|
-
|
|
406
|
+
state.update((current) => {
|
|
407
|
+
current.lastTradeTimestamp = timestamp;
|
|
408
|
+
});
|
|
396
409
|
},
|
|
397
|
-
getLastTradeTimestamp
|
|
410
|
+
getLastTradeTimestamp
|
|
398
411
|
};
|
|
399
412
|
};
|
|
413
|
+
var createLastTradeController = (params) => {
|
|
414
|
+
const state = { lastTradeTimestamp: null };
|
|
415
|
+
return createStateBackedLastTradeController({
|
|
416
|
+
...resolveLastTradeControllerParams(params),
|
|
417
|
+
state: {
|
|
418
|
+
get: () => state,
|
|
419
|
+
update: (fn) => fn(state)
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
};
|
|
400
423
|
var stableStringify = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
401
424
|
if (value == null) {
|
|
402
425
|
return String(value);
|
|
@@ -1327,6 +1350,7 @@ var createStrategyAPI = ({
|
|
|
1327
1350
|
sharedReplayKey,
|
|
1328
1351
|
getSharedReplayState
|
|
1329
1352
|
});
|
|
1353
|
+
let lastTradeControllerIndex = 0;
|
|
1330
1354
|
const getBaseContextFromIndicators = (indicators) => isRecordLike(indicators) && isRecordLike(indicators.baseContext) ? indicators.baseContext : void 0;
|
|
1331
1355
|
const getCurrentIndicatorsContext = () => {
|
|
1332
1356
|
ensureBarCache();
|
|
@@ -1479,10 +1503,26 @@ var createStrategyAPI = ({
|
|
|
1479
1503
|
getDecisionPriceContext,
|
|
1480
1504
|
getCurrentPosition,
|
|
1481
1505
|
getDirectionalTpSlPrices: (params) => getDirectionalTpSlPrices(params),
|
|
1482
|
-
createLastTradeController: (params) =>
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1506
|
+
createLastTradeController: (params) => {
|
|
1507
|
+
const resolvedParams = resolveLastTradeControllerParams({
|
|
1508
|
+
env,
|
|
1509
|
+
...params
|
|
1510
|
+
});
|
|
1511
|
+
const controllerIndex = lastTradeControllerIndex;
|
|
1512
|
+
lastTradeControllerIndex += 1;
|
|
1513
|
+
const state = createStateController(
|
|
1514
|
+
`__tradejs:last-trade:${controllerIndex}`,
|
|
1515
|
+
() => ({ lastTradeTimestamp: null }),
|
|
1516
|
+
{
|
|
1517
|
+
configKey: JSON.stringify(resolvedParams),
|
|
1518
|
+
sharedReplay: env === "CRON"
|
|
1519
|
+
}
|
|
1520
|
+
);
|
|
1521
|
+
return createStateBackedLastTradeController({
|
|
1522
|
+
...resolvedParams,
|
|
1523
|
+
state
|
|
1524
|
+
});
|
|
1525
|
+
},
|
|
1486
1526
|
createStateController
|
|
1487
1527
|
};
|
|
1488
1528
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tradejs/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.21",
|
|
4
4
|
"description": "MIT-licensed browser-safe API for TradeJS config, strategy authoring, figures, and shared helpers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tradejs",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
}
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@tradejs/types": "^2.0.
|
|
103
|
+
"@tradejs/types": "^2.0.21",
|
|
104
104
|
"date-fns": "^3.6.0",
|
|
105
105
|
"fast-technical-indicators": "^1.1.4",
|
|
106
106
|
"klinecharts": "10.0.0-alpha9",
|