@tradejs/node 3.0.1 → 3.1.1

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.
Files changed (43) hide show
  1. package/README.md +4 -0
  2. package/dist/ai.d.mts +26 -4
  3. package/dist/ai.d.ts +26 -4
  4. package/dist/ai.js +162 -165
  5. package/dist/ai.mjs +4 -1
  6. package/dist/backtest.js +515 -188
  7. package/dist/backtest.mjs +6 -4
  8. package/dist/chunk-3TWULKHV.mjs +595 -0
  9. package/dist/chunk-FB5NUEOQ.mjs +295 -0
  10. package/dist/chunk-LAJ7NA3Q.mjs +377 -0
  11. package/dist/{chunk-VRXU4E4O.mjs → chunk-SEQJ6V6B.mjs} +165 -446
  12. package/dist/{chunk-OGAWBO3Z.mjs → chunk-W26Y6IRP.mjs} +22 -3
  13. package/dist/chunk-XN7BC7XK.mjs +295 -0
  14. package/dist/cli.js +152 -161
  15. package/dist/cli.mjs +4 -2
  16. package/dist/connectors.d.mts +5 -2
  17. package/dist/connectors.d.ts +5 -2
  18. package/dist/connectors.js +329 -8
  19. package/dist/connectors.mjs +5 -1
  20. package/dist/registry-DHTLjQcr.d.mts +17 -0
  21. package/dist/registry-DHTLjQcr.d.ts +17 -0
  22. package/dist/registry.d.mts +2 -15
  23. package/dist/registry.d.ts +2 -15
  24. package/dist/registry.js +176 -161
  25. package/dist/registry.mjs +5 -2
  26. package/dist/runtimeDashboard.d.mts +12 -0
  27. package/dist/runtimeDashboard.d.ts +12 -0
  28. package/dist/runtimeDashboard.js +8502 -0
  29. package/dist/runtimeDashboard.mjs +1000 -0
  30. package/dist/runtimeStrategies.d.mts +38 -0
  31. package/dist/runtimeStrategies.d.ts +38 -0
  32. package/dist/runtimeStrategies.js +798 -0
  33. package/dist/runtimeStrategies.mjs +264 -0
  34. package/dist/runtimeTrades.d.mts +31 -0
  35. package/dist/runtimeTrades.d.ts +31 -0
  36. package/dist/runtimeTrades.js +321 -0
  37. package/dist/runtimeTrades.mjs +11 -0
  38. package/dist/strategies.d.mts +2 -2
  39. package/dist/strategies.d.ts +2 -2
  40. package/dist/strategies.js +194 -165
  41. package/dist/strategies.mjs +24 -379
  42. package/package.json +27 -6
  43. package/dist/chunk-V3YMKE4I.mjs +0 -271
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  askAI,
3
- getStrategyManifest,
4
3
  getStrategyProfileMlAdapter,
5
4
  resolveStrategyPolicyProfile,
6
- runAiPromptLocal,
5
+ runAiPromptLocal
6
+ } from "./chunk-SEQJ6V6B.mjs";
7
+ import {
8
+ getStrategyManifest,
7
9
  setStrategyRuntimeFactory
8
- } from "./chunk-VRXU4E4O.mjs";
10
+ } from "./chunk-XN7BC7XK.mjs";
9
11
  import {
10
12
  getTradejsProjectCwd,
11
13
  loadTradejsConfig
@@ -2774,6 +2776,7 @@ var executeEntryOrder = async ({
2774
2776
  deploymentId: signal.deploymentId,
2775
2777
  policyProfileId: signal.policyProfileId,
2776
2778
  runtimeConfigId: signal.runtimeConfigId,
2779
+ runtimeReleaseVersion: signal.runtimeReleaseVersion,
2777
2780
  runtimeLineage: signal.runtimeLineage,
2778
2781
  ...signal.aiAnalysis ? { aiAnalysis: signal.aiAnalysis } : {}
2779
2782
  });
@@ -3719,6 +3722,9 @@ var createStrategyRuntime = ({
3719
3722
  deploymentId: requestedDeploymentId,
3720
3723
  policyProfileId,
3721
3724
  runtimeConfigId,
3725
+ runtimeReleaseVersion,
3726
+ entriesPaused = false,
3727
+ runtimeLineage,
3722
3728
  runtimeConfigSnapshot,
3723
3729
  data,
3724
3730
  btcData,
@@ -4377,6 +4383,7 @@ var createStrategyRuntime = ({
4377
4383
  });
4378
4384
  const signal = decision.signal;
4379
4385
  if (signal) {
4386
+ if (runtimeLineage) signal.runtimeLineage = runtimeLineage;
4380
4387
  if (universe) signal.universe = universe;
4381
4388
  if (assetClass) signal.assetClass = assetClass;
4382
4389
  if (accountId) signal.accountId = accountId;
@@ -4387,6 +4394,9 @@ var createStrategyRuntime = ({
4387
4394
  signal.signalId = `${signal.signalId}:${runtimeConfigId}`;
4388
4395
  }
4389
4396
  }
4397
+ if (runtimeReleaseVersion) {
4398
+ signal.runtimeReleaseVersion = runtimeReleaseVersion;
4399
+ }
4390
4400
  if (decisionHookCtx.policyProfileId) {
4391
4401
  signal.policyProfileId = decisionHookCtx.policyProfileId;
4392
4402
  }
@@ -4493,6 +4503,15 @@ var createStrategyRuntime = ({
4493
4503
  quality,
4494
4504
  minAiQuality
4495
4505
  });
4506
+ if (entriesPaused) {
4507
+ const skipReason = "RUNTIME_ENTRIES_PAUSED";
4508
+ if (signal) {
4509
+ signal.orderStatus = "skipped";
4510
+ signal.orderSkipReason = skipReason;
4511
+ signal.runtimeReleaseVersion = runtimeReleaseVersion;
4512
+ }
4513
+ return signal ?? skipReason;
4514
+ }
4496
4515
  if (!shouldMakeOrder) {
4497
4516
  if (signal) {
4498
4517
  signal.orderStatus = "skipped";
@@ -0,0 +1,295 @@
1
+ import {
2
+ getTradejsProjectCwd,
3
+ importTradejsModule,
4
+ loadTradejsConfig,
5
+ resolvePluginModuleSpecifier
6
+ } from "./chunk-WS5DYEVZ.mjs";
7
+
8
+ // src/strategy/manifests.ts
9
+ import {
10
+ registerIndicatorEntries,
11
+ resetIndicatorRegistryCache
12
+ } from "@tradejs/core/indicators";
13
+ import { logger } from "@tradejs/infra/logger";
14
+ var SHARED_STRATEGY_REGISTRY_KEY = "__tradejsNodeSharedStrategyRegistryV1__";
15
+ var sharedRegistryScope = globalThis;
16
+ var sharedStrategyRegistry = sharedRegistryScope[SHARED_STRATEGY_REGISTRY_KEY] ?? (sharedRegistryScope[SHARED_STRATEGY_REGISTRY_KEY] = {
17
+ registryStateByProjectRoot: /* @__PURE__ */ new Map()
18
+ });
19
+ var createStrategyRegistryState = () => ({
20
+ strategyCreators: /* @__PURE__ */ new Map(),
21
+ strategyManifestsMap: /* @__PURE__ */ new Map(),
22
+ strategyEntriesMap: /* @__PURE__ */ new Map(),
23
+ strategySourcesMap: /* @__PURE__ */ new Map(),
24
+ pluginsLoadPromise: null
25
+ });
26
+ var registryStateByProjectRoot = sharedStrategyRegistry.registryStateByProjectRoot;
27
+ var getStrategyRegistryState = (cwd = getTradejsProjectCwd()) => {
28
+ const projectRoot = getTradejsProjectCwd(cwd);
29
+ let state = registryStateByProjectRoot.get(projectRoot);
30
+ if (!state) {
31
+ state = createStrategyRegistryState();
32
+ registryStateByProjectRoot.set(projectRoot, state);
33
+ }
34
+ return {
35
+ projectRoot,
36
+ state
37
+ };
38
+ };
39
+ var toUniqueModules = (modules = []) => [
40
+ ...new Set(modules.map((moduleName) => moduleName.trim()).filter(Boolean))
41
+ ];
42
+ var getConfiguredPluginModuleNames = async (cwd = getTradejsProjectCwd()) => {
43
+ const config = await loadTradejsConfig(cwd);
44
+ return {
45
+ strategyModules: toUniqueModules(config.strategies),
46
+ indicatorModules: toUniqueModules(config.indicators)
47
+ };
48
+ };
49
+ var extractModuleEntries = (moduleExport, key) => {
50
+ if (!moduleExport || typeof moduleExport !== "object") {
51
+ return null;
52
+ }
53
+ const candidate = moduleExport;
54
+ if (Array.isArray(candidate[key])) {
55
+ return candidate[key];
56
+ }
57
+ const defaultExport = candidate.default;
58
+ if (defaultExport && Array.isArray(defaultExport[key])) {
59
+ return defaultExport[key];
60
+ }
61
+ return null;
62
+ };
63
+ var extractStrategyPluginDefinition = (moduleExport) => {
64
+ const strategyEntries = extractModuleEntries(
65
+ moduleExport,
66
+ "strategyEntries"
67
+ );
68
+ return strategyEntries ? { strategyEntries } : null;
69
+ };
70
+ var extractIndicatorPluginDefinition = (moduleExport) => {
71
+ const indicatorEntries = extractModuleEntries(
72
+ moduleExport,
73
+ "indicatorEntries"
74
+ );
75
+ return indicatorEntries ? { indicatorEntries } : null;
76
+ };
77
+ var registerEntries = (entries, source, state) => {
78
+ for (const entry of entries) {
79
+ const strategyName = entry.manifest?.name;
80
+ if (!strategyName) {
81
+ logger.warn("Skip strategy entry without name from %s", source);
82
+ continue;
83
+ }
84
+ if (state.strategyCreators.has(strategyName)) {
85
+ logger.warn(
86
+ 'Skip duplicate strategy "%s" from %s: already registered',
87
+ strategyName,
88
+ source
89
+ );
90
+ continue;
91
+ }
92
+ state.strategyManifestsMap.set(strategyName, entry.manifest);
93
+ state.strategyEntriesMap.set(strategyName, entry);
94
+ state.strategySourcesMap.set(strategyName, source);
95
+ materializeStrategyCreator(strategyName, state);
96
+ }
97
+ };
98
+ var materializeStrategyCreator = (strategyName, state) => {
99
+ if (state.strategyCreators.has(strategyName) || !sharedStrategyRegistry.strategyRuntimeFactory) {
100
+ return;
101
+ }
102
+ const entry = state.strategyEntriesMap.get(strategyName);
103
+ if (!entry) return;
104
+ state.strategyCreators.set(
105
+ strategyName,
106
+ sharedStrategyRegistry.strategyRuntimeFactory({
107
+ strategyName,
108
+ defaults: entry.defaults,
109
+ createCore: entry.createCore,
110
+ manifest: entry.manifest,
111
+ detectorKey: entry.detectorKey,
112
+ detectorNoSignalSkipReason: entry.detectorNoSignalSkipReason,
113
+ resolveRegisteredManifest: (name) => state.strategyManifestsMap.get(name)
114
+ })
115
+ );
116
+ };
117
+ var setStrategyRuntimeFactory = (factory) => {
118
+ sharedStrategyRegistry.strategyRuntimeFactory = factory;
119
+ for (const state of registryStateByProjectRoot.values()) {
120
+ for (const strategyName of state.strategyEntriesMap.keys()) {
121
+ materializeStrategyCreator(strategyName, state);
122
+ }
123
+ }
124
+ };
125
+ var importStrategyPluginModule = async (moduleName, cwd = getTradejsProjectCwd()) => {
126
+ if (typeof importTradejsModule === "function") {
127
+ return importTradejsModule(moduleName, cwd);
128
+ }
129
+ return import(
130
+ /* webpackIgnore: true */
131
+ moduleName
132
+ );
133
+ };
134
+ var ensureStrategyPluginsLoaded = async (cwd = getTradejsProjectCwd()) => {
135
+ const { projectRoot, state } = getStrategyRegistryState(cwd);
136
+ if (!state.pluginsLoadPromise) {
137
+ resetIndicatorRegistryCache(projectRoot);
138
+ state.pluginsLoadPromise = (async () => {
139
+ const { strategyModules, indicatorModules } = await getConfiguredPluginModuleNames(projectRoot);
140
+ const strategySet = new Set(strategyModules);
141
+ const indicatorSet = new Set(indicatorModules);
142
+ const pluginModuleNames = [
143
+ .../* @__PURE__ */ new Set([...strategyModules, ...indicatorModules])
144
+ ];
145
+ if (!pluginModuleNames.length) {
146
+ return;
147
+ }
148
+ for (const moduleName of pluginModuleNames) {
149
+ try {
150
+ const resolvedModuleName = resolvePluginModuleSpecifier(
151
+ moduleName,
152
+ projectRoot
153
+ );
154
+ const moduleExport = await importStrategyPluginModule(
155
+ resolvedModuleName,
156
+ projectRoot
157
+ );
158
+ if (strategySet.has(moduleName)) {
159
+ const pluginDefinition = extractStrategyPluginDefinition(moduleExport);
160
+ if (!pluginDefinition) {
161
+ logger.warn(
162
+ 'Skip strategy plugin "%s": export { strategyEntries } is missing',
163
+ moduleName
164
+ );
165
+ } else {
166
+ registerEntries(
167
+ pluginDefinition.strategyEntries,
168
+ moduleName,
169
+ state
170
+ );
171
+ }
172
+ }
173
+ if (indicatorSet.has(moduleName)) {
174
+ const indicatorPluginDefinition = extractIndicatorPluginDefinition(moduleExport);
175
+ if (!indicatorPluginDefinition) {
176
+ logger.warn(
177
+ 'Skip indicator plugin "%s": export { indicatorEntries } is missing',
178
+ moduleName
179
+ );
180
+ } else {
181
+ registerIndicatorEntries(
182
+ indicatorPluginDefinition.indicatorEntries,
183
+ moduleName,
184
+ projectRoot
185
+ );
186
+ }
187
+ }
188
+ if (!strategySet.has(moduleName) && !indicatorSet.has(moduleName)) {
189
+ logger.warn(
190
+ 'Skip plugin "%s": no strategy/indicator sections requested in config',
191
+ moduleName
192
+ );
193
+ }
194
+ } catch (error) {
195
+ logger.warn(
196
+ 'Failed to load plugin "%s": %s',
197
+ moduleName,
198
+ String(error)
199
+ );
200
+ }
201
+ }
202
+ })();
203
+ }
204
+ await state.pluginsLoadPromise;
205
+ };
206
+ var ensureIndicatorPluginsLoaded = async (cwd = getTradejsProjectCwd()) => ensureStrategyPluginsLoaded(cwd);
207
+ var getStrategyCreator = async (name, cwd = getTradejsProjectCwd()) => {
208
+ await ensureStrategyPluginsLoaded(cwd);
209
+ const { state } = getStrategyRegistryState(cwd);
210
+ return state.strategyCreators.get(name);
211
+ };
212
+ var getStrategyDefaults = async (name, cwd = getTradejsProjectCwd()) => {
213
+ await ensureStrategyPluginsLoaded(cwd);
214
+ const { state } = getStrategyRegistryState(cwd);
215
+ return state.strategyEntriesMap.get(name)?.defaults;
216
+ };
217
+ var getStrategyPluginSource = async (name, cwd = getTradejsProjectCwd()) => {
218
+ await ensureStrategyPluginsLoaded(cwd);
219
+ const { state } = getStrategyRegistryState(cwd);
220
+ return state.strategySourcesMap.get(name);
221
+ };
222
+ var getAvailableStrategyNames = async (cwd = getTradejsProjectCwd()) => {
223
+ await ensureStrategyPluginsLoaded(cwd);
224
+ const { state } = getStrategyRegistryState(cwd);
225
+ return [...state.strategyCreators.keys()].sort((a, b) => a.localeCompare(b));
226
+ };
227
+ var getRegisteredStrategies = (cwd = getTradejsProjectCwd()) => {
228
+ const { state } = getStrategyRegistryState(cwd);
229
+ return Object.fromEntries(state.strategyCreators.entries());
230
+ };
231
+ var getRegisteredManifests = (cwd = getTradejsProjectCwd()) => {
232
+ const { state } = getStrategyRegistryState(cwd);
233
+ return [...state.strategyManifestsMap.values()];
234
+ };
235
+ var getStrategyManifest = (name, cwd = getTradejsProjectCwd()) => {
236
+ if (!name) {
237
+ return void 0;
238
+ }
239
+ const { state } = getStrategyRegistryState(cwd);
240
+ return state.strategyManifestsMap.get(name);
241
+ };
242
+ var isKnownStrategy = (name, cwd = getTradejsProjectCwd()) => {
243
+ const { state } = getStrategyRegistryState(cwd);
244
+ return state.strategyCreators.has(name);
245
+ };
246
+ var registerStrategyEntries = (entries, cwd = getTradejsProjectCwd()) => {
247
+ const { state } = getStrategyRegistryState(cwd);
248
+ registerEntries(entries, "runtime", state);
249
+ };
250
+ var resetStrategyRegistryCache = (cwd) => {
251
+ const normalizedCwd = String(cwd ?? "").trim();
252
+ if (!normalizedCwd) {
253
+ registryStateByProjectRoot.clear();
254
+ resetIndicatorRegistryCache();
255
+ return;
256
+ }
257
+ const projectRoot = getTradejsProjectCwd(normalizedCwd);
258
+ registryStateByProjectRoot.delete(projectRoot);
259
+ resetIndicatorRegistryCache(projectRoot);
260
+ };
261
+ var strategies = new Proxy(
262
+ {},
263
+ {
264
+ get: (_target, property) => {
265
+ if (typeof property !== "string") {
266
+ return void 0;
267
+ }
268
+ return getStrategyRegistryState().state.strategyCreators.get(property);
269
+ },
270
+ ownKeys: () => {
271
+ return [...getStrategyRegistryState().state.strategyCreators.keys()];
272
+ },
273
+ getOwnPropertyDescriptor: () => ({
274
+ enumerable: true,
275
+ configurable: true
276
+ })
277
+ }
278
+ );
279
+
280
+ export {
281
+ setStrategyRuntimeFactory,
282
+ ensureStrategyPluginsLoaded,
283
+ ensureIndicatorPluginsLoaded,
284
+ getStrategyCreator,
285
+ getStrategyDefaults,
286
+ getStrategyPluginSource,
287
+ getAvailableStrategyNames,
288
+ getRegisteredStrategies,
289
+ getRegisteredManifests,
290
+ getStrategyManifest,
291
+ isKnownStrategy,
292
+ registerStrategyEntries,
293
+ resetStrategyRegistryCache,
294
+ strategies
295
+ };