@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,105 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { API } from '@tradejs/core/api';
|
|
5
|
+
import { toaster } from '#ui';
|
|
6
|
+
import { FIXED_SYMBOLS, type ChartWindow } from './derivativesDashboardConfig';
|
|
7
|
+
import { loadDerivativesDashboardData } from './derivativesDashboardLoader';
|
|
8
|
+
import {
|
|
9
|
+
buildDerivativesDashboardViewModel,
|
|
10
|
+
type DerivativesInterval,
|
|
11
|
+
type DetailRow,
|
|
12
|
+
type PriceRow,
|
|
13
|
+
type SummaryResponse,
|
|
14
|
+
} from './derivativesViewModel';
|
|
15
|
+
|
|
16
|
+
export const useDerivativesDashboard = () => {
|
|
17
|
+
const [hours, setHours] = useState('24');
|
|
18
|
+
const [selectedInterval, setSelectedInterval] =
|
|
19
|
+
useState<DerivativesInterval>('1h');
|
|
20
|
+
const [summary, setSummary] = useState<SummaryResponse | null>(null);
|
|
21
|
+
const [detailsBySymbol, setDetailsBySymbol] = useState<
|
|
22
|
+
Record<string, DetailRow[]>
|
|
23
|
+
>({});
|
|
24
|
+
const [pricesBySymbol, setPricesBySymbol] = useState<
|
|
25
|
+
Record<string, PriceRow[]>
|
|
26
|
+
>({});
|
|
27
|
+
const [chartWindow, setChartWindow] = useState<ChartWindow>(() => {
|
|
28
|
+
const endTimestamp = Date.now();
|
|
29
|
+
return {
|
|
30
|
+
startTimestamp: endTimestamp - 24 * 60 * 60 * 1000,
|
|
31
|
+
endTimestamp,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
const [loading, setLoading] = useState(false);
|
|
35
|
+
const [error, setError] = useState('');
|
|
36
|
+
const requestRevision = useRef(0);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const revision = ++requestRevision.current;
|
|
40
|
+
setLoading(true);
|
|
41
|
+
setError('');
|
|
42
|
+
|
|
43
|
+
void loadDerivativesDashboardData({
|
|
44
|
+
hours,
|
|
45
|
+
selectedInterval,
|
|
46
|
+
client: API,
|
|
47
|
+
})
|
|
48
|
+
.then((data) => {
|
|
49
|
+
if (requestRevision.current !== revision) return;
|
|
50
|
+
setSummary(data.summary);
|
|
51
|
+
setDetailsBySymbol(data.detailsBySymbol);
|
|
52
|
+
setPricesBySymbol(data.pricesBySymbol);
|
|
53
|
+
setChartWindow(data.chartWindow);
|
|
54
|
+
})
|
|
55
|
+
.catch((loadError) => {
|
|
56
|
+
if (requestRevision.current !== revision) return;
|
|
57
|
+
const message =
|
|
58
|
+
(loadError as Error)?.message || 'Failed to load derivatives';
|
|
59
|
+
setError(message);
|
|
60
|
+
toaster.error({
|
|
61
|
+
title: 'Failed to load derivatives',
|
|
62
|
+
description: message,
|
|
63
|
+
});
|
|
64
|
+
})
|
|
65
|
+
.finally(() => {
|
|
66
|
+
if (requestRevision.current === revision) setLoading(false);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return () => {
|
|
70
|
+
if (requestRevision.current === revision) requestRevision.current += 1;
|
|
71
|
+
};
|
|
72
|
+
}, [hours, selectedInterval]);
|
|
73
|
+
|
|
74
|
+
const dashboard = useMemo(
|
|
75
|
+
() =>
|
|
76
|
+
buildDerivativesDashboardViewModel({
|
|
77
|
+
symbols: FIXED_SYMBOLS,
|
|
78
|
+
selectedInterval,
|
|
79
|
+
summary,
|
|
80
|
+
detailsBySymbol,
|
|
81
|
+
pricesBySymbol,
|
|
82
|
+
summaryLoading: loading,
|
|
83
|
+
detailLoading: loading,
|
|
84
|
+
summaryError: error,
|
|
85
|
+
detailError: error,
|
|
86
|
+
}),
|
|
87
|
+
[
|
|
88
|
+
detailsBySymbol,
|
|
89
|
+
error,
|
|
90
|
+
loading,
|
|
91
|
+
pricesBySymbol,
|
|
92
|
+
selectedInterval,
|
|
93
|
+
summary,
|
|
94
|
+
],
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
hours,
|
|
99
|
+
setHours,
|
|
100
|
+
selectedInterval,
|
|
101
|
+
setSelectedInterval,
|
|
102
|
+
chartWindow,
|
|
103
|
+
dashboard,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
|
-
import { Box,
|
|
4
|
+
import { Box, ClientOnly, Flex } from '@chakra-ui/react';
|
|
5
5
|
import { usePathname } from 'next/navigation';
|
|
6
6
|
import { FiFolder } from 'react-icons/fi';
|
|
7
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
RuntimeStrategiesResponse,
|
|
9
|
+
StrategyChartsSnapshotResponse,
|
|
10
|
+
} from '@tradejs/types';
|
|
8
11
|
import {
|
|
9
12
|
deleteStrategyCard,
|
|
10
13
|
getAiStrategies,
|
|
@@ -13,14 +16,12 @@ import {
|
|
|
13
16
|
} from '#actions/strategies';
|
|
14
17
|
import { RuntimeStrategyCard } from '#components/Strategies/RuntimeStrategyCard';
|
|
15
18
|
import { RuntimeStrategyCardSkeleton } from '#components/Strategies/RuntimeStrategyCardSkeleton';
|
|
16
|
-
import { RuntimeStrategyConfigDrawer } from '#components/Strategies/RuntimeStrategyConfigDrawer';
|
|
17
19
|
import { StrategySnapshotList } from '#components/Strategies/StrategySnapshotList';
|
|
18
20
|
import { BacktestResultsPageClient } from '#components/Backtest/ResultsPageClient';
|
|
19
21
|
import {
|
|
20
22
|
BulkDeleteToolbar,
|
|
21
23
|
useBulkSelection,
|
|
22
24
|
} from '#components/Shared/BulkSelection';
|
|
23
|
-
import type { RuntimeStrategiesResponse } from '#app/lib/runtimeStrategyContracts';
|
|
24
25
|
import { CARD_PAGE_CONTENT_MAX_WIDTH } from '#app/lib/cardPageLayout';
|
|
25
26
|
import { EmptyState, Segment, Select, toaster } from '#ui';
|
|
26
27
|
|
|
@@ -83,7 +84,6 @@ const RuntimeStrategiesContent = () => {
|
|
|
83
84
|
const [error, setError] = useState('');
|
|
84
85
|
const [runtimeData, setRuntimeData] =
|
|
85
86
|
useState<RuntimeStrategiesResponse | null>(null);
|
|
86
|
-
const [createRuntimeConfigOpen, setCreateRuntimeConfigOpen] = useState(false);
|
|
87
87
|
const [snapshotData, setSnapshotData] =
|
|
88
88
|
useState<StrategyChartsSnapshotResponse | null>(null);
|
|
89
89
|
const isSnapshotMode = mode === 'replay' || mode === 'ai';
|
|
@@ -517,23 +517,8 @@ const RuntimeStrategiesContent = () => {
|
|
|
517
517
|
/>
|
|
518
518
|
) : null}
|
|
519
519
|
</Flex>
|
|
520
|
-
{mode === 'runtime' ? (
|
|
521
|
-
<Button
|
|
522
|
-
ml="auto"
|
|
523
|
-
colorPalette="teal"
|
|
524
|
-
onClick={() => setCreateRuntimeConfigOpen(true)}
|
|
525
|
-
>
|
|
526
|
-
Create
|
|
527
|
-
</Button>
|
|
528
|
-
) : null}
|
|
529
520
|
</Flex>
|
|
530
521
|
|
|
531
|
-
<RuntimeStrategyConfigDrawer
|
|
532
|
-
open={createRuntimeConfigOpen}
|
|
533
|
-
onOpenChange={setCreateRuntimeConfigOpen}
|
|
534
|
-
onSaved={load}
|
|
535
|
-
/>
|
|
536
|
-
|
|
537
522
|
{isSnapshotMode ? (
|
|
538
523
|
<BulkDeleteToolbar
|
|
539
524
|
selectedCount={selectedFilteredCount}
|