@tradejs/app 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.
- package/README.md +2 -0
- package/package.json +10 -11
- package/src/app/actions/strategies.ts +4 -2
- package/src/app/api/ai/route.ts +21 -50
- package/src/app/api/strategies/runtime/route.ts +1 -1
- package/src/app/api/user/runtime-deployments/[deploymentId]/strategies/[strategyName]/control/route.ts +73 -0
- package/src/app/api/user/runtime-deployments/route.ts +55 -8
- package/src/app/api/user/runtime-strategy-releases/route.ts +60 -0
- package/src/app/components/Strategies/RuntimeStrategyCard.presenter.ts +5 -2
- package/src/app/components/Strategies/RuntimeStrategyCard.tsx +65 -7
- package/src/app/components/Strategies/RuntimeStrategyConfigDrawer.tsx +46 -3
- package/src/app/components/Strategies/RuntimeStrategyStatsDrawer.tsx +1 -2
- package/src/app/components/Strategies/StrategyEvidencePopover.tsx +3 -1
- package/src/app/lib/connectorCreator.ts +1 -10
- package/src/app/lib/runtimeStrategyReleaseService.ts +123 -0
- package/src/app/routes/derivatives/DerivativesDashboardView.tsx +900 -0
- package/src/app/routes/derivatives/derivativesDashboardConfig.ts +53 -0
- package/src/app/routes/derivatives/derivativesDashboardLoader.ts +74 -0
- package/src/app/routes/derivatives/page.tsx +18 -1087
- package/src/app/routes/derivatives/useDerivativesDashboard.ts +105 -0
- package/src/app/routes/strategies/StrategiesPageClient.tsx +5 -20
- package/src/app/lib/runtimeDashboard.ts +0 -700
- package/src/app/lib/runtimeStrategies.ts +0 -1107
- package/src/app/lib/runtimeStrategyContracts.ts +0 -85
- package/src/app/lib/runtimeStrategyLineage.ts +0 -264
- package/src/app/lib/runtimeTradeReconciliation.ts +0 -113
- package/src/app/lib/runtimeTradeSync.ts +0 -280
- package/src/app/lib/strategyEvidenceTimeline.ts +0 -298
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRuntimeStrategyDraft,
|
|
3
|
+
listRuntimeStrategyReleases,
|
|
4
|
+
publishRuntimeStrategyRelease,
|
|
5
|
+
saveRuntimeStrategyDraft,
|
|
6
|
+
} from '@tradejs/infra/runtimeStrategyReleases';
|
|
7
|
+
import { getRuntimeStrategyPackageMetadata } from '@tradejs/node/runtimeStrategies';
|
|
8
|
+
import {
|
|
9
|
+
getAvailableStrategyNames,
|
|
10
|
+
getStrategyDefaults,
|
|
11
|
+
} from '@tradejs/node/strategies';
|
|
12
|
+
import type { StrategyConfig } from '@tradejs/types';
|
|
13
|
+
|
|
14
|
+
const OPERATIONAL_KEYS = [
|
|
15
|
+
'ACCOUNT_ID',
|
|
16
|
+
'AI_REPLAY_ANALYSES',
|
|
17
|
+
'DEPLOYMENT_ID',
|
|
18
|
+
'ENABLE',
|
|
19
|
+
'ENV',
|
|
20
|
+
'MAKE_ORDERS',
|
|
21
|
+
'RECORD_RUNTIME_TRADES',
|
|
22
|
+
'configId',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const assertConfig = (value: unknown): StrategyConfig => {
|
|
26
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
27
|
+
throw new Error('Strategy config must be a JSON object');
|
|
28
|
+
}
|
|
29
|
+
const config = value as StrategyConfig;
|
|
30
|
+
const invalidKey = OPERATIONAL_KEYS.find((key) => config[key] !== undefined);
|
|
31
|
+
if (invalidKey) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`${invalidKey} is controlled by the deployment, not config`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return config;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const assertKnownStrategy = async (
|
|
40
|
+
strategyName: string,
|
|
41
|
+
projectRoot: string,
|
|
42
|
+
) => {
|
|
43
|
+
if (!(await getAvailableStrategyNames(projectRoot)).includes(strategyName)) {
|
|
44
|
+
throw new Error(`Unknown strategy: ${strategyName}`);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const getRuntimeStrategyReleaseOptions = async ({
|
|
49
|
+
userName,
|
|
50
|
+
projectRoot,
|
|
51
|
+
}: {
|
|
52
|
+
userName: string;
|
|
53
|
+
projectRoot: string;
|
|
54
|
+
}) => {
|
|
55
|
+
const strategyNames = await getAvailableStrategyNames(projectRoot);
|
|
56
|
+
const strategies = await Promise.all(
|
|
57
|
+
strategyNames.map(async (strategyName) => ({
|
|
58
|
+
strategyName,
|
|
59
|
+
draft: await getRuntimeStrategyDraft(userName, strategyName),
|
|
60
|
+
releases: await listRuntimeStrategyReleases(userName, strategyName),
|
|
61
|
+
})),
|
|
62
|
+
);
|
|
63
|
+
return { strategyNames, strategies };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const saveRuntimeStrategyReleaseDraftForUser = async ({
|
|
67
|
+
userName,
|
|
68
|
+
projectRoot,
|
|
69
|
+
input,
|
|
70
|
+
}: {
|
|
71
|
+
userName: string;
|
|
72
|
+
projectRoot: string;
|
|
73
|
+
input: Record<string, unknown>;
|
|
74
|
+
}) => {
|
|
75
|
+
const strategyName = String(input.strategyName ?? '').trim();
|
|
76
|
+
await assertKnownStrategy(strategyName, projectRoot);
|
|
77
|
+
return saveRuntimeStrategyDraft({
|
|
78
|
+
userName,
|
|
79
|
+
strategyName,
|
|
80
|
+
config: assertConfig(input.config),
|
|
81
|
+
baseReleaseVersion:
|
|
82
|
+
typeof input.baseReleaseVersion === 'number'
|
|
83
|
+
? input.baseReleaseVersion
|
|
84
|
+
: null,
|
|
85
|
+
updatedBy: userName,
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const publishRuntimeStrategyReleaseForUser = async ({
|
|
90
|
+
userName,
|
|
91
|
+
projectRoot,
|
|
92
|
+
strategyName,
|
|
93
|
+
}: {
|
|
94
|
+
userName: string;
|
|
95
|
+
projectRoot: string;
|
|
96
|
+
strategyName: string;
|
|
97
|
+
}) => {
|
|
98
|
+
await assertKnownStrategy(strategyName, projectRoot);
|
|
99
|
+
const draft = await getRuntimeStrategyDraft(userName, strategyName);
|
|
100
|
+
if (!draft) throw new Error(`Draft not found: ${strategyName}`);
|
|
101
|
+
const defaults = (await getStrategyDefaults(strategyName, projectRoot)) ?? {};
|
|
102
|
+
const config: StrategyConfig = { ...defaults, ...draft.config };
|
|
103
|
+
for (const key of OPERATIONAL_KEYS) delete config[key];
|
|
104
|
+
const metadata = await getRuntimeStrategyPackageMetadata({
|
|
105
|
+
strategyName,
|
|
106
|
+
projectRoot,
|
|
107
|
+
});
|
|
108
|
+
const release = await publishRuntimeStrategyRelease({
|
|
109
|
+
userName,
|
|
110
|
+
strategyName,
|
|
111
|
+
config,
|
|
112
|
+
...metadata,
|
|
113
|
+
createdBy: userName,
|
|
114
|
+
});
|
|
115
|
+
await saveRuntimeStrategyDraft({
|
|
116
|
+
userName,
|
|
117
|
+
strategyName,
|
|
118
|
+
config: release.config,
|
|
119
|
+
baseReleaseVersion: release.releaseVersion,
|
|
120
|
+
updatedBy: userName,
|
|
121
|
+
});
|
|
122
|
+
return release;
|
|
123
|
+
};
|