@tradejs/node 3.1.0 → 3.1.2

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/README.md CHANGED
@@ -80,3 +80,5 @@ import { createStrategyRuntime } from '@tradejs/node/strategies';
80
80
  - Do not import it into browser/client bundles.
81
81
  - For plugin/config declaration and browser-safe helpers, use `@tradejs/core`.
82
82
  - For shared contracts, use `@tradejs/types`.
83
+
84
+ Keywords: ai, claude, codex.
package/dist/ai.js CHANGED
@@ -652,6 +652,7 @@ var createStrategyRegistryState = () => ({
652
652
  strategyCreators: /* @__PURE__ */ new Map(),
653
653
  strategyManifestsMap: /* @__PURE__ */ new Map(),
654
654
  strategyEntriesMap: /* @__PURE__ */ new Map(),
655
+ strategySourcesMap: /* @__PURE__ */ new Map(),
655
656
  pluginsLoadPromise: null
656
657
  });
657
658
  var registryStateByProjectRoot = sharedStrategyRegistry.registryStateByProjectRoot;
package/dist/ai.mjs CHANGED
@@ -14,7 +14,8 @@ import {
14
14
  runAiPrompt,
15
15
  runAiPromptLocal,
16
16
  trimSeriesDeep
17
- } from "./chunk-KOQSLFT2.mjs";
17
+ } from "./chunk-SEQJ6V6B.mjs";
18
+ import "./chunk-XN7BC7XK.mjs";
18
19
  import "./chunk-WS5DYEVZ.mjs";
19
20
  import "./chunk-Y6FXYEAI.mjs";
20
21
  export {
package/dist/backtest.js CHANGED
@@ -934,6 +934,7 @@ var createStrategyRegistryState = () => ({
934
934
  strategyCreators: /* @__PURE__ */ new Map(),
935
935
  strategyManifestsMap: /* @__PURE__ */ new Map(),
936
936
  strategyEntriesMap: /* @__PURE__ */ new Map(),
937
+ strategySourcesMap: /* @__PURE__ */ new Map(),
937
938
  pluginsLoadPromise: null
938
939
  });
939
940
  var registryStateByProjectRoot = sharedStrategyRegistry.registryStateByProjectRoot;
@@ -1004,6 +1005,7 @@ var registerEntries = (entries, source, state) => {
1004
1005
  }
1005
1006
  state.strategyManifestsMap.set(strategyName, entry.manifest);
1006
1007
  state.strategyEntriesMap.set(strategyName, entry);
1008
+ state.strategySourcesMap.set(strategyName, source);
1007
1009
  materializeStrategyCreator(strategyName, state);
1008
1010
  }
1009
1011
  };
@@ -4424,6 +4426,7 @@ var executeEntryOrder = async ({
4424
4426
  deploymentId: signal.deploymentId,
4425
4427
  policyProfileId: signal.policyProfileId,
4426
4428
  runtimeConfigId: signal.runtimeConfigId,
4429
+ runtimeReleaseVersion: signal.runtimeReleaseVersion,
4427
4430
  runtimeLineage: signal.runtimeLineage,
4428
4431
  ...signal.aiAnalysis ? { aiAnalysis: signal.aiAnalysis } : {}
4429
4432
  });
@@ -5348,6 +5351,9 @@ var createStrategyRuntime = ({
5348
5351
  deploymentId: requestedDeploymentId,
5349
5352
  policyProfileId,
5350
5353
  runtimeConfigId,
5354
+ runtimeReleaseVersion,
5355
+ entriesPaused = false,
5356
+ runtimeLineage,
5351
5357
  runtimeConfigSnapshot,
5352
5358
  data,
5353
5359
  btcData,
@@ -6006,6 +6012,7 @@ var createStrategyRuntime = ({
6006
6012
  });
6007
6013
  const signal = decision.signal;
6008
6014
  if (signal) {
6015
+ if (runtimeLineage) signal.runtimeLineage = runtimeLineage;
6009
6016
  if (universe) signal.universe = universe;
6010
6017
  if (assetClass) signal.assetClass = assetClass;
6011
6018
  if (accountId) signal.accountId = accountId;
@@ -6016,6 +6023,9 @@ var createStrategyRuntime = ({
6016
6023
  signal.signalId = `${signal.signalId}:${runtimeConfigId}`;
6017
6024
  }
6018
6025
  }
6026
+ if (runtimeReleaseVersion) {
6027
+ signal.runtimeReleaseVersion = runtimeReleaseVersion;
6028
+ }
6019
6029
  if (decisionHookCtx.policyProfileId) {
6020
6030
  signal.policyProfileId = decisionHookCtx.policyProfileId;
6021
6031
  }
@@ -6122,6 +6132,15 @@ var createStrategyRuntime = ({
6122
6132
  quality,
6123
6133
  minAiQuality
6124
6134
  });
6135
+ if (entriesPaused) {
6136
+ const skipReason = "RUNTIME_ENTRIES_PAUSED";
6137
+ if (signal) {
6138
+ signal.orderStatus = "skipped";
6139
+ signal.orderSkipReason = skipReason;
6140
+ signal.runtimeReleaseVersion = runtimeReleaseVersion;
6141
+ }
6142
+ return signal ?? skipReason;
6143
+ }
6125
6144
  if (!shouldMakeOrder) {
6126
6145
  if (signal) {
6127
6146
  signal.orderStatus = "skipped";
package/dist/backtest.mjs CHANGED
@@ -5,11 +5,13 @@ import {
5
5
  import {
6
6
  buildMlPayload,
7
7
  enrichSignalWithMarketContextStages
8
- } from "./chunk-MKLTJQLY.mjs";
8
+ } from "./chunk-W26Y6IRP.mjs";
9
+ import {
10
+ buildAiPayload
11
+ } from "./chunk-SEQJ6V6B.mjs";
9
12
  import {
10
- buildAiPayload,
11
13
  getStrategyCreator
12
- } from "./chunk-KOQSLFT2.mjs";
14
+ } from "./chunk-XN7BC7XK.mjs";
13
15
  import {
14
16
  getTradejsProjectCwd
15
17
  } from "./chunk-WS5DYEVZ.mjs";
@@ -1,9 +1,6 @@
1
1
  import {
2
- getTradejsProjectCwd,
3
- importTradejsModule,
4
- loadTradejsConfig,
5
- resolvePluginModuleSpecifier
6
- } from "./chunk-WS5DYEVZ.mjs";
2
+ getStrategyManifest
3
+ } from "./chunk-XN7BC7XK.mjs";
7
4
 
8
5
  // src/ai.ts
9
6
  import {
@@ -584,271 +581,6 @@ var buildAiMarketContext = (signal) => ({
584
581
  }
585
582
  });
586
583
 
587
- // src/strategy/manifests.ts
588
- import {
589
- registerIndicatorEntries,
590
- resetIndicatorRegistryCache
591
- } from "@tradejs/core/indicators";
592
- import { logger } from "@tradejs/infra/logger";
593
- var SHARED_STRATEGY_REGISTRY_KEY = "__tradejsNodeSharedStrategyRegistryV1__";
594
- var sharedRegistryScope = globalThis;
595
- var sharedStrategyRegistry = sharedRegistryScope[SHARED_STRATEGY_REGISTRY_KEY] ?? (sharedRegistryScope[SHARED_STRATEGY_REGISTRY_KEY] = {
596
- registryStateByProjectRoot: /* @__PURE__ */ new Map()
597
- });
598
- var createStrategyRegistryState = () => ({
599
- strategyCreators: /* @__PURE__ */ new Map(),
600
- strategyManifestsMap: /* @__PURE__ */ new Map(),
601
- strategyEntriesMap: /* @__PURE__ */ new Map(),
602
- pluginsLoadPromise: null
603
- });
604
- var registryStateByProjectRoot = sharedStrategyRegistry.registryStateByProjectRoot;
605
- var getStrategyRegistryState = (cwd = getTradejsProjectCwd()) => {
606
- const projectRoot = getTradejsProjectCwd(cwd);
607
- let state = registryStateByProjectRoot.get(projectRoot);
608
- if (!state) {
609
- state = createStrategyRegistryState();
610
- registryStateByProjectRoot.set(projectRoot, state);
611
- }
612
- return {
613
- projectRoot,
614
- state
615
- };
616
- };
617
- var toUniqueModules = (modules = []) => [
618
- ...new Set(modules.map((moduleName) => moduleName.trim()).filter(Boolean))
619
- ];
620
- var getConfiguredPluginModuleNames = async (cwd = getTradejsProjectCwd()) => {
621
- const config = await loadTradejsConfig(cwd);
622
- return {
623
- strategyModules: toUniqueModules(config.strategies),
624
- indicatorModules: toUniqueModules(config.indicators)
625
- };
626
- };
627
- var extractModuleEntries = (moduleExport, key) => {
628
- if (!moduleExport || typeof moduleExport !== "object") {
629
- return null;
630
- }
631
- const candidate = moduleExport;
632
- if (Array.isArray(candidate[key])) {
633
- return candidate[key];
634
- }
635
- const defaultExport = candidate.default;
636
- if (defaultExport && Array.isArray(defaultExport[key])) {
637
- return defaultExport[key];
638
- }
639
- return null;
640
- };
641
- var extractStrategyPluginDefinition = (moduleExport) => {
642
- const strategyEntries = extractModuleEntries(
643
- moduleExport,
644
- "strategyEntries"
645
- );
646
- return strategyEntries ? { strategyEntries } : null;
647
- };
648
- var extractIndicatorPluginDefinition = (moduleExport) => {
649
- const indicatorEntries = extractModuleEntries(
650
- moduleExport,
651
- "indicatorEntries"
652
- );
653
- return indicatorEntries ? { indicatorEntries } : null;
654
- };
655
- var registerEntries = (entries, source, state) => {
656
- for (const entry of entries) {
657
- const strategyName = entry.manifest?.name;
658
- if (!strategyName) {
659
- logger.warn("Skip strategy entry without name from %s", source);
660
- continue;
661
- }
662
- if (state.strategyCreators.has(strategyName)) {
663
- logger.warn(
664
- 'Skip duplicate strategy "%s" from %s: already registered',
665
- strategyName,
666
- source
667
- );
668
- continue;
669
- }
670
- state.strategyManifestsMap.set(strategyName, entry.manifest);
671
- state.strategyEntriesMap.set(strategyName, entry);
672
- materializeStrategyCreator(strategyName, state);
673
- }
674
- };
675
- var materializeStrategyCreator = (strategyName, state) => {
676
- if (state.strategyCreators.has(strategyName) || !sharedStrategyRegistry.strategyRuntimeFactory) {
677
- return;
678
- }
679
- const entry = state.strategyEntriesMap.get(strategyName);
680
- if (!entry) return;
681
- state.strategyCreators.set(
682
- strategyName,
683
- sharedStrategyRegistry.strategyRuntimeFactory({
684
- strategyName,
685
- defaults: entry.defaults,
686
- createCore: entry.createCore,
687
- manifest: entry.manifest,
688
- detectorKey: entry.detectorKey,
689
- detectorNoSignalSkipReason: entry.detectorNoSignalSkipReason,
690
- resolveRegisteredManifest: (name) => state.strategyManifestsMap.get(name)
691
- })
692
- );
693
- };
694
- var setStrategyRuntimeFactory = (factory) => {
695
- sharedStrategyRegistry.strategyRuntimeFactory = factory;
696
- for (const state of registryStateByProjectRoot.values()) {
697
- for (const strategyName of state.strategyEntriesMap.keys()) {
698
- materializeStrategyCreator(strategyName, state);
699
- }
700
- }
701
- };
702
- var importStrategyPluginModule = async (moduleName, cwd = getTradejsProjectCwd()) => {
703
- if (typeof importTradejsModule === "function") {
704
- return importTradejsModule(moduleName, cwd);
705
- }
706
- return import(
707
- /* webpackIgnore: true */
708
- moduleName
709
- );
710
- };
711
- var ensureStrategyPluginsLoaded = async (cwd = getTradejsProjectCwd()) => {
712
- const { projectRoot, state } = getStrategyRegistryState(cwd);
713
- if (!state.pluginsLoadPromise) {
714
- resetIndicatorRegistryCache(projectRoot);
715
- state.pluginsLoadPromise = (async () => {
716
- const { strategyModules, indicatorModules } = await getConfiguredPluginModuleNames(projectRoot);
717
- const strategySet = new Set(strategyModules);
718
- const indicatorSet = new Set(indicatorModules);
719
- const pluginModuleNames = [
720
- .../* @__PURE__ */ new Set([...strategyModules, ...indicatorModules])
721
- ];
722
- if (!pluginModuleNames.length) {
723
- return;
724
- }
725
- for (const moduleName of pluginModuleNames) {
726
- try {
727
- const resolvedModuleName = resolvePluginModuleSpecifier(
728
- moduleName,
729
- projectRoot
730
- );
731
- const moduleExport = await importStrategyPluginModule(
732
- resolvedModuleName,
733
- projectRoot
734
- );
735
- if (strategySet.has(moduleName)) {
736
- const pluginDefinition = extractStrategyPluginDefinition(moduleExport);
737
- if (!pluginDefinition) {
738
- logger.warn(
739
- 'Skip strategy plugin "%s": export { strategyEntries } is missing',
740
- moduleName
741
- );
742
- } else {
743
- registerEntries(
744
- pluginDefinition.strategyEntries,
745
- moduleName,
746
- state
747
- );
748
- }
749
- }
750
- if (indicatorSet.has(moduleName)) {
751
- const indicatorPluginDefinition = extractIndicatorPluginDefinition(moduleExport);
752
- if (!indicatorPluginDefinition) {
753
- logger.warn(
754
- 'Skip indicator plugin "%s": export { indicatorEntries } is missing',
755
- moduleName
756
- );
757
- } else {
758
- registerIndicatorEntries(
759
- indicatorPluginDefinition.indicatorEntries,
760
- moduleName,
761
- projectRoot
762
- );
763
- }
764
- }
765
- if (!strategySet.has(moduleName) && !indicatorSet.has(moduleName)) {
766
- logger.warn(
767
- 'Skip plugin "%s": no strategy/indicator sections requested in config',
768
- moduleName
769
- );
770
- }
771
- } catch (error) {
772
- logger.warn(
773
- 'Failed to load plugin "%s": %s',
774
- moduleName,
775
- String(error)
776
- );
777
- }
778
- }
779
- })();
780
- }
781
- await state.pluginsLoadPromise;
782
- };
783
- var ensureIndicatorPluginsLoaded = async (cwd = getTradejsProjectCwd()) => ensureStrategyPluginsLoaded(cwd);
784
- var getStrategyCreator = async (name, cwd = getTradejsProjectCwd()) => {
785
- await ensureStrategyPluginsLoaded(cwd);
786
- const { state } = getStrategyRegistryState(cwd);
787
- return state.strategyCreators.get(name);
788
- };
789
- var getStrategyDefaults = async (name, cwd = getTradejsProjectCwd()) => {
790
- await ensureStrategyPluginsLoaded(cwd);
791
- const { state } = getStrategyRegistryState(cwd);
792
- return state.strategyEntriesMap.get(name)?.defaults;
793
- };
794
- var getAvailableStrategyNames = async (cwd = getTradejsProjectCwd()) => {
795
- await ensureStrategyPluginsLoaded(cwd);
796
- const { state } = getStrategyRegistryState(cwd);
797
- return [...state.strategyCreators.keys()].sort((a, b) => a.localeCompare(b));
798
- };
799
- var getRegisteredStrategies = (cwd = getTradejsProjectCwd()) => {
800
- const { state } = getStrategyRegistryState(cwd);
801
- return Object.fromEntries(state.strategyCreators.entries());
802
- };
803
- var getRegisteredManifests = (cwd = getTradejsProjectCwd()) => {
804
- const { state } = getStrategyRegistryState(cwd);
805
- return [...state.strategyManifestsMap.values()];
806
- };
807
- var getStrategyManifest = (name, cwd = getTradejsProjectCwd()) => {
808
- if (!name) {
809
- return void 0;
810
- }
811
- const { state } = getStrategyRegistryState(cwd);
812
- return state.strategyManifestsMap.get(name);
813
- };
814
- var isKnownStrategy = (name, cwd = getTradejsProjectCwd()) => {
815
- const { state } = getStrategyRegistryState(cwd);
816
- return state.strategyCreators.has(name);
817
- };
818
- var registerStrategyEntries = (entries, cwd = getTradejsProjectCwd()) => {
819
- const { state } = getStrategyRegistryState(cwd);
820
- registerEntries(entries, "runtime", state);
821
- };
822
- var resetStrategyRegistryCache = (cwd) => {
823
- const normalizedCwd = String(cwd ?? "").trim();
824
- if (!normalizedCwd) {
825
- registryStateByProjectRoot.clear();
826
- resetIndicatorRegistryCache();
827
- return;
828
- }
829
- const projectRoot = getTradejsProjectCwd(normalizedCwd);
830
- registryStateByProjectRoot.delete(projectRoot);
831
- resetIndicatorRegistryCache(projectRoot);
832
- };
833
- var strategies = new Proxy(
834
- {},
835
- {
836
- get: (_target, property) => {
837
- if (typeof property !== "string") {
838
- return void 0;
839
- }
840
- return getStrategyRegistryState().state.strategyCreators.get(property);
841
- },
842
- ownKeys: () => {
843
- return [...getStrategyRegistryState().state.strategyCreators.keys()];
844
- },
845
- getOwnPropertyDescriptor: () => ({
846
- enumerable: true,
847
- configurable: true
848
- })
849
- }
850
- );
851
-
852
584
  // src/strategy/policyProfiles.ts
853
585
  var profileMatches = (profile, universe, assetClass) => {
854
586
  const { appliesTo } = profile;
@@ -1439,19 +1171,6 @@ export {
1439
1171
  MAX_AI_SERIES_POINTS,
1440
1172
  trimSeriesDeep,
1441
1173
  buildCompactAiIndicatorsSnapshot,
1442
- setStrategyRuntimeFactory,
1443
- ensureStrategyPluginsLoaded,
1444
- ensureIndicatorPluginsLoaded,
1445
- getStrategyCreator,
1446
- getStrategyDefaults,
1447
- getAvailableStrategyNames,
1448
- getRegisteredStrategies,
1449
- getRegisteredManifests,
1450
- getStrategyManifest,
1451
- isKnownStrategy,
1452
- registerStrategyEntries,
1453
- resetStrategyRegistryCache,
1454
- strategies,
1455
1174
  resolveStrategyPolicyProfile,
1456
1175
  getStrategyProfileMlAdapter,
1457
1176
  DEFAULT_AI_MODEL,
@@ -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-KOQSLFT2.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";