@tradejs/app 1.0.0

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 (126) hide show
  1. package/README.md +12 -0
  2. package/bin/tradejs-app.mjs +54 -0
  3. package/next-env.d.ts +6 -0
  4. package/next.config.mjs +31 -0
  5. package/package.json +60 -0
  6. package/src/app/actions/ai.ts +33 -0
  7. package/src/app/actions/backtest.ts +55 -0
  8. package/src/app/actions/kline.ts +18 -0
  9. package/src/app/actions/scanner.ts +10 -0
  10. package/src/app/actions/signal.ts +19 -0
  11. package/src/app/api/ai/route.ts +151 -0
  12. package/src/app/api/auth/[...nextauth]/route.ts +5 -0
  13. package/src/app/api/backtest/files/route.ts +60 -0
  14. package/src/app/api/backtest/order-log/[strategy]/[name]/route.ts +47 -0
  15. package/src/app/api/backtest/result/[strategy]/[name]/route.ts +63 -0
  16. package/src/app/api/backtest/test/[strategy]/[name]/route.ts +57 -0
  17. package/src/app/api/cron/route.ts +4 -0
  18. package/src/app/api/derivatives/[symbol]/[interval]/route.ts +57 -0
  19. package/src/app/api/derivatives/summary/route.ts +20 -0
  20. package/src/app/api/files/screenshot/[name]/route.ts +42 -0
  21. package/src/app/api/indicators/route.ts +24 -0
  22. package/src/app/api/kline/[provider]/[symbol]/[interval]/route.ts +123 -0
  23. package/src/app/api/scanner/[provider]/route.ts +41 -0
  24. package/src/app/api/scanner/route.ts +31 -0
  25. package/src/app/api/signal/[symbol]/[signalId]/route.ts +42 -0
  26. package/src/app/api/spread/[symbol]/[interval]/route.ts +57 -0
  27. package/src/app/api/spread/summary/route.ts +20 -0
  28. package/src/app/auth.ts +76 -0
  29. package/src/app/components/Backtest/CompareList/index.tsx +34 -0
  30. package/src/app/components/Backtest/TestCard/Chart/index.tsx +118 -0
  31. package/src/app/components/Backtest/TestCard/Chart/utils/index.ts +81 -0
  32. package/src/app/components/Backtest/TestCard/CompareButton/index.tsx +21 -0
  33. package/src/app/components/Backtest/TestCard/ConfigDrawer/JsonCodeBlock.tsx +46 -0
  34. package/src/app/components/Backtest/TestCard/ConfigDrawer/index.tsx +94 -0
  35. package/src/app/components/Backtest/TestCard/DeleteButton/index.tsx +128 -0
  36. package/src/app/components/Backtest/TestCard/FavoriteIndicator/index.tsx +18 -0
  37. package/src/app/components/Backtest/TestCard/OpenDashboardButton/index.tsx +40 -0
  38. package/src/app/components/Backtest/TestCard/OpenReportButton/index.tsx +24 -0
  39. package/src/app/components/Backtest/TestCard/Root/index.tsx +55 -0
  40. package/src/app/components/Backtest/TestCard/Skeleton/index.tsx +21 -0
  41. package/src/app/components/Backtest/TestCard/Stat/index.tsx +119 -0
  42. package/src/app/components/Backtest/TestCard/Title/index.tsx +84 -0
  43. package/src/app/components/Backtest/TestCard/context.ts +14 -0
  44. package/src/app/components/Backtest/TestCard/index.ts +28 -0
  45. package/src/app/components/Backtest/TestList/index.tsx +124 -0
  46. package/src/app/components/Dashboard/AiDrawer/Message.tsx +34 -0
  47. package/src/app/components/Dashboard/AiDrawer/index.tsx +163 -0
  48. package/src/app/components/Dashboard/KlineChart/figures/backtestFigureTypes.ts +7 -0
  49. package/src/app/components/Dashboard/KlineChart/figures/backtestMarkersPointFigure.ts +76 -0
  50. package/src/app/components/Dashboard/KlineChart/figures/circle.ts +15 -0
  51. package/src/app/components/Dashboard/KlineChart/figures/diamond.ts +25 -0
  52. package/src/app/components/Dashboard/KlineChart/figures/entryLinePointFigure.ts +1 -0
  53. package/src/app/components/Dashboard/KlineChart/figures/entryPointsPointFigure.ts +1 -0
  54. package/src/app/components/Dashboard/KlineChart/figures/entryZonePointFigure.ts +1 -0
  55. package/src/app/components/Dashboard/KlineChart/figures/index.ts +213 -0
  56. package/src/app/components/Dashboard/KlineChart/figures/label.ts +14 -0
  57. package/src/app/components/Dashboard/KlineChart/figures/rectangle.ts +20 -0
  58. package/src/app/components/Dashboard/KlineChart/figures/square.ts +21 -0
  59. package/src/app/components/Dashboard/KlineChart/figures/star.ts +39 -0
  60. package/src/app/components/Dashboard/KlineChart/figures/tradeZonePointFigure.ts +44 -0
  61. package/src/app/components/Dashboard/KlineChart/figures/trendLinePointFigure.ts +37 -0
  62. package/src/app/components/Dashboard/KlineChart/figures/trendLinePointsPointFigure.ts +26 -0
  63. package/src/app/components/Dashboard/KlineChart/figures/triangle.ts +23 -0
  64. package/src/app/components/Dashboard/KlineChart/hooks/index.ts +14 -0
  65. package/src/app/components/Dashboard/KlineChart/hooks/indicatorShared.ts +30 -0
  66. package/src/app/components/Dashboard/KlineChart/hooks/useAtrIndicator.ts +75 -0
  67. package/src/app/components/Dashboard/KlineChart/hooks/useBacktest.ts +533 -0
  68. package/src/app/components/Dashboard/KlineChart/hooks/useBbIndicator.ts +74 -0
  69. package/src/app/components/Dashboard/KlineChart/hooks/useBtcCorrelation.ts +155 -0
  70. package/src/app/components/Dashboard/KlineChart/hooks/useBtcIndicator.ts +185 -0
  71. package/src/app/components/Dashboard/KlineChart/hooks/useEmaIndicator.ts +62 -0
  72. package/src/app/components/Dashboard/KlineChart/hooks/useMaIndicator.ts +62 -0
  73. package/src/app/components/Dashboard/KlineChart/hooks/useManagedIndicator.ts +140 -0
  74. package/src/app/components/Dashboard/KlineChart/hooks/usePluginIndicators.ts +212 -0
  75. package/src/app/components/Dashboard/KlineChart/hooks/useResize.ts +29 -0
  76. package/src/app/components/Dashboard/KlineChart/hooks/useSetup.ts +122 -0
  77. package/src/app/components/Dashboard/KlineChart/hooks/useSignal.ts +85 -0
  78. package/src/app/components/Dashboard/KlineChart/hooks/useSpreadIndicator.ts +243 -0
  79. package/src/app/components/Dashboard/KlineChart/hooks/useSupportResistanceLines.ts +125 -0
  80. package/src/app/components/Dashboard/KlineChart/hooks/useTrendLine.ts +139 -0
  81. package/src/app/components/Dashboard/KlineChart/hooks/useVolIndicator.ts +18 -0
  82. package/src/app/components/Dashboard/KlineChart/hooks/useWmaIndicator.ts +62 -0
  83. package/src/app/components/Dashboard/KlineChart/index.tsx +169 -0
  84. package/src/app/components/Dashboard/KlineChart/styles.ts +70 -0
  85. package/src/app/components/Dashboard/MainChart/index.tsx +35 -0
  86. package/src/app/components/Shared/AppShell.tsx +28 -0
  87. package/src/app/components/Shared/FavoriteButton/index.tsx +23 -0
  88. package/src/app/components/Shared/Filters/Backtest/index.tsx +164 -0
  89. package/src/app/components/Shared/Filters/FavoriteIndicator/index.tsx +18 -0
  90. package/src/app/components/Shared/Filters/Indicators/index.tsx +21 -0
  91. package/src/app/components/Shared/Filters/Interval/index.tsx +31 -0
  92. package/src/app/components/Shared/Filters/Interval/intervals.ts +6 -0
  93. package/src/app/components/Shared/Filters/Provider/index.tsx +32 -0
  94. package/src/app/components/Shared/Filters/Root/index.tsx +28 -0
  95. package/src/app/components/Shared/Filters/Symbol/index.tsx +49 -0
  96. package/src/app/components/Shared/Filters/context.ts +17 -0
  97. package/src/app/components/Shared/Filters/index.ts +17 -0
  98. package/src/app/components/Shared/Sidebar/index.tsx +72 -0
  99. package/src/app/components/UI/ColorMode/index.tsx +112 -0
  100. package/src/app/components/UI/EmptyState/index.tsx +28 -0
  101. package/src/app/components/UI/OverlaySpinner/index.tsx +23 -0
  102. package/src/app/components/UI/Segment/index.tsx +23 -0
  103. package/src/app/components/UI/Select/index.tsx +81 -0
  104. package/src/app/components/UI/SelectWithSearch/index.tsx +104 -0
  105. package/src/app/components/UI/Switcher/index.tsx +24 -0
  106. package/src/app/components/UI/Toaster/index.tsx +45 -0
  107. package/src/app/components/UI/index.ts +8 -0
  108. package/src/app/favicon.ico +0 -0
  109. package/src/app/globals.css +5 -0
  110. package/src/app/layout.tsx +31 -0
  111. package/src/app/page.tsx +14 -0
  112. package/src/app/provider.tsx +39 -0
  113. package/src/app/routes/backtest/[test]/page.tsx +33 -0
  114. package/src/app/routes/backtest/page.tsx +374 -0
  115. package/src/app/routes/dashboard/[provider]/[symbol]/[interval]/page.tsx +124 -0
  116. package/src/app/routes/dashboard/page.tsx +20 -0
  117. package/src/app/routes/derivatives/page.tsx +202 -0
  118. package/src/app/routes/signin/page.tsx +155 -0
  119. package/src/app/store/data.ts +144 -0
  120. package/src/app/store/filters.ts +29 -0
  121. package/src/app/store/index.ts +13 -0
  122. package/src/app/store/indicators.ts +229 -0
  123. package/src/app/store/tests.ts +464 -0
  124. package/src/app/store/tickers.ts +89 -0
  125. package/src/proxy.ts +142 -0
  126. package/tsconfig.json +40 -0
@@ -0,0 +1,81 @@
1
+ 'use client';
2
+
3
+ import { useMemo } from 'react';
4
+ import {
5
+ Portal,
6
+ Stack,
7
+ Span,
8
+ Select as UISelect,
9
+ createListCollection,
10
+ } from '@chakra-ui/react';
11
+ import { Items } from '@tradejs/types';
12
+
13
+ interface SelectProps {
14
+ defaultValue: string[];
15
+ value?: string[];
16
+ items: Items;
17
+ placeholder?: string;
18
+ width?: string | number;
19
+ multiple?: boolean;
20
+ size?: 'xs' | 'sm' | 'md' | 'lg';
21
+ onChange?: (value: string[]) => void;
22
+ }
23
+
24
+ export const Select = ({
25
+ defaultValue,
26
+ value,
27
+ items,
28
+ multiple = false,
29
+ placeholder = 'Select',
30
+ width = '320px',
31
+ size = 'sm',
32
+ onChange,
33
+ }: SelectProps) => {
34
+ const collection = useMemo(
35
+ () =>
36
+ createListCollection({
37
+ items,
38
+ }),
39
+ [items],
40
+ );
41
+
42
+ return (
43
+ <UISelect.Root
44
+ collection={collection}
45
+ {...(value ? { value } : { defaultValue })}
46
+ onValueChange={(details) => onChange?.(details.value)}
47
+ size={size}
48
+ multiple={multiple}
49
+ width={width}
50
+ >
51
+ <UISelect.HiddenSelect />
52
+ <UISelect.Control>
53
+ <UISelect.Trigger>
54
+ <UISelect.ValueText placeholder={placeholder} />
55
+ </UISelect.Trigger>
56
+ <UISelect.IndicatorGroup>
57
+ <UISelect.Indicator />
58
+ </UISelect.IndicatorGroup>
59
+ </UISelect.Control>
60
+ <Portal>
61
+ <UISelect.Positioner>
62
+ <UISelect.Content>
63
+ {collection.items.map((item) => (
64
+ <UISelect.Item item={item} key={item.value}>
65
+ <Stack gap="0">
66
+ <UISelect.ItemText>{item.label}</UISelect.ItemText>
67
+ {item.description && (
68
+ <Span color="fg.muted" textStyle="xs">
69
+ {item.description}
70
+ </Span>
71
+ )}
72
+ </Stack>
73
+ <UISelect.ItemIndicator />
74
+ </UISelect.Item>
75
+ ))}
76
+ </UISelect.Content>
77
+ </UISelect.Positioner>
78
+ </Portal>
79
+ </UISelect.Root>
80
+ );
81
+ };
@@ -0,0 +1,104 @@
1
+ 'use client';
2
+
3
+ import _ from 'lodash';
4
+ import { useEffect, useState } from 'react';
5
+ import {
6
+ Portal,
7
+ Stack,
8
+ HStack,
9
+ Span,
10
+ Combobox,
11
+ useFilter,
12
+ useListCollection,
13
+ } from '@chakra-ui/react';
14
+ import { Items } from '@tradejs/types';
15
+
16
+ interface SelectWithSearchProps {
17
+ defaultValue: string[];
18
+ defaultInputValue?: string;
19
+ items: Items;
20
+ placeholder?: string;
21
+ emptyState?: string;
22
+ width?: string | number;
23
+ multiple?: boolean;
24
+ size?: 'xs' | 'sm' | 'md' | 'lg';
25
+ onChange?: (value: string[]) => void;
26
+ }
27
+
28
+ export const SelectWithSearch = ({
29
+ defaultValue,
30
+ defaultInputValue,
31
+ items,
32
+ multiple = false,
33
+ placeholder = 'Select',
34
+ emptyState = 'No items found',
35
+ width = '320px',
36
+ size = 'sm',
37
+ onChange,
38
+ }: SelectWithSearchProps) => {
39
+ const { contains } = useFilter({ sensitivity: 'base' });
40
+ const [inputValue, setInputValue] = useState(
41
+ defaultInputValue ?? defaultValue?.[0],
42
+ );
43
+
44
+ const { collection, filter, set } = useListCollection({
45
+ initialItems: items,
46
+ filter: contains,
47
+ });
48
+
49
+ useEffect(() => {
50
+ set(items);
51
+ }, [items, set]);
52
+
53
+ return (
54
+ <Combobox.Root
55
+ collection={collection}
56
+ defaultValue={defaultValue}
57
+ inputValue={inputValue}
58
+ onValueChange={(details) => onChange?.(details.value)}
59
+ onInputValueChange={(e) => {
60
+ filter(e.inputValue);
61
+ setInputValue(e.inputValue);
62
+ }}
63
+ onOpenChange={(details) => {
64
+ if (details.open) {
65
+ filter('');
66
+ setInputValue('');
67
+ }
68
+ }}
69
+ width={width}
70
+ multiple={multiple}
71
+ size={size}
72
+ openOnClick
73
+ >
74
+ <Combobox.Control>
75
+ <Combobox.Input placeholder={placeholder} />
76
+ <Combobox.IndicatorGroup>
77
+ <Combobox.Trigger />
78
+ </Combobox.IndicatorGroup>
79
+ </Combobox.Control>
80
+ <Portal>
81
+ <Combobox.Positioner>
82
+ <Combobox.Content>
83
+ <Combobox.Empty>{emptyState}</Combobox.Empty>
84
+ {collection.items.map((item) => (
85
+ <Combobox.Item item={item} key={item.value}>
86
+ <HStack gap={2}>
87
+ <Stack gap="0">
88
+ {item.label}
89
+ {item.description && (
90
+ <Span color="fg.muted" textStyle="xs">
91
+ {item.description}
92
+ </Span>
93
+ )}
94
+ </Stack>
95
+ <Combobox.ItemIndicator />
96
+ </HStack>
97
+ </Combobox.Item>
98
+ ))}
99
+ </Combobox.Content>
100
+ </Combobox.Positioner>
101
+ </Portal>
102
+ </Combobox.Root>
103
+ );
104
+ };
@@ -0,0 +1,24 @@
1
+ 'use client';
2
+
3
+ import { Switch } from '@chakra-ui/react';
4
+
5
+ interface SwitcherProps {
6
+ defaultValue: boolean;
7
+ label: string;
8
+ onChange?: (value: boolean) => void;
9
+ }
10
+
11
+ export const Switcher = ({ defaultValue, label, onChange }: SwitcherProps) => {
12
+ return (
13
+ <Switch.Root
14
+ checked={defaultValue}
15
+ onCheckedChange={(e) => onChange?.(e.checked)}
16
+ >
17
+ <Switch.HiddenInput />
18
+ <Switch.Control>
19
+ <Switch.Thumb />
20
+ </Switch.Control>
21
+ <Switch.Label>{label}</Switch.Label>
22
+ </Switch.Root>
23
+ );
24
+ };
@@ -0,0 +1,45 @@
1
+ 'use client';
2
+
3
+ import { Portal, Toast, Toaster, createToaster } from '@chakra-ui/react';
4
+
5
+ export const toaster = createToaster({
6
+ placement: 'bottom-end',
7
+ offsets: '1rem',
8
+ pauseOnPageIdle: true,
9
+ });
10
+
11
+ export const AppToaster = () => {
12
+ return (
13
+ <Portal>
14
+ <Toaster toaster={toaster}>
15
+ {(toast) => (
16
+ <Toast.Root
17
+ width={{ base: 'calc(100vw - 2rem)', md: 'sm' }}
18
+ maxW="calc(100vw - 2rem)"
19
+ bg="gray.700"
20
+ color="gray.100"
21
+ borderWidth="1px"
22
+ borderColor="gray.600"
23
+ >
24
+ <Toast.Indicator
25
+ color={
26
+ toast.type === 'success'
27
+ ? 'green.400'
28
+ : toast.type === 'error'
29
+ ? 'red.400'
30
+ : toast.type === 'warning'
31
+ ? 'orange.300'
32
+ : 'gray.300'
33
+ }
34
+ />
35
+ <Toast.Title>{toast.title}</Toast.Title>
36
+ {toast.description ? (
37
+ <Toast.Description>{toast.description}</Toast.Description>
38
+ ) : null}
39
+ <Toast.CloseTrigger />
40
+ </Toast.Root>
41
+ )}
42
+ </Toaster>
43
+ </Portal>
44
+ );
45
+ };
@@ -0,0 +1,8 @@
1
+ export { Select } from './Select';
2
+ export { SelectWithSearch } from './SelectWithSearch';
3
+ export { Segment } from './Segment';
4
+ export { Switcher } from './Switcher';
5
+ export { ColorModeProvider } from './ColorMode';
6
+ export { OverlaySpinner } from './OverlaySpinner';
7
+ export { EmptyState } from './EmptyState';
8
+ export { AppToaster, toaster } from './Toaster';
Binary file
@@ -0,0 +1,5 @@
1
+ /* [data-nextjs-devtools-button],
2
+ [data-nextjs-devtools-bubble],
3
+ [data-nextjs-devtools] {
4
+ left: 76px !important;
5
+ } */
@@ -0,0 +1,31 @@
1
+ import type { Metadata } from 'next';
2
+ import { Inter } from 'next/font/google';
3
+ import { ClientOnly } from '@chakra-ui/react';
4
+ import { AppShell } from '@shared/AppShell';
5
+ import Provider from './provider';
6
+ import './globals.css';
7
+
8
+ const inter = Inter({ subsets: ['latin'] });
9
+
10
+ export const metadata: Metadata = {
11
+ title: 'TradeJS App',
12
+ description: 'Trading Strategies Framework',
13
+ };
14
+
15
+ export default function RootLayout({
16
+ children,
17
+ }: Readonly<{
18
+ children: React.ReactNode;
19
+ }>) {
20
+ return (
21
+ <html lang="en" suppressHydrationWarning>
22
+ <body className={inter.className}>
23
+ <ClientOnly>
24
+ <Provider>
25
+ <AppShell>{children}</AppShell>
26
+ </Provider>
27
+ </ClientOnly>
28
+ </body>
29
+ </html>
30
+ );
31
+ }
@@ -0,0 +1,14 @@
1
+ 'use client';
2
+
3
+ import { useEffect } from 'react';
4
+ import { useRouter } from 'next/navigation';
5
+
6
+ export default function Home() {
7
+ const router = useRouter();
8
+
9
+ useEffect(() => {
10
+ router.replace('/routes/dashboard');
11
+ }, [router]);
12
+
13
+ return <main></main>;
14
+ }
@@ -0,0 +1,39 @@
1
+ 'use client';
2
+
3
+ import {
4
+ ChakraProvider,
5
+ createSystem,
6
+ defaultConfig,
7
+ defineConfig,
8
+ } from '@chakra-ui/react';
9
+ import { SessionProvider } from 'next-auth/react';
10
+ import { AppToaster, ColorModeProvider } from '@UI';
11
+
12
+ const config = defineConfig({
13
+ theme: {
14
+ tokens: {
15
+ cursor: {
16
+ button: { value: 'pointer' },
17
+ },
18
+ },
19
+ },
20
+ });
21
+
22
+ const system = createSystem(defaultConfig, config);
23
+
24
+ export default function Provider({
25
+ children,
26
+ }: Readonly<{
27
+ children: React.ReactNode;
28
+ }>) {
29
+ return (
30
+ <ChakraProvider value={system}>
31
+ <ColorModeProvider forcedTheme="dark">
32
+ <SessionProvider>
33
+ {children}
34
+ <AppToaster />
35
+ </SessionProvider>
36
+ </ColorModeProvider>
37
+ </ChakraProvider>
38
+ );
39
+ }
@@ -0,0 +1,33 @@
1
+ 'use client';
2
+
3
+ import React from 'react';
4
+ import { Box, ClientOnly } from '@chakra-ui/react';
5
+ import { useParams } from 'next/navigation';
6
+ import { TestCard } from '@components/Backtest/TestCard';
7
+
8
+ const BacktestReport = () => {
9
+ const { test: testName } = useParams();
10
+
11
+ if (typeof testName !== 'string') {
12
+ return null;
13
+ }
14
+
15
+ return (
16
+ <ClientOnly>
17
+ <Box minH="100vh" bg="gray.900">
18
+ <Box minW="1200px" pl={4} pt={4}>
19
+ <TestCard.Root testName={testName} noWrapper={true}>
20
+ <TestCard.Title>
21
+ <TestCard.FavoriteIndicator />
22
+ <TestCard.ConfigDrawer />
23
+ </TestCard.Title>
24
+ <TestCard.Chart height="500px" />
25
+ <TestCard.StatTable />
26
+ </TestCard.Root>
27
+ </Box>
28
+ </Box>
29
+ </ClientOnly>
30
+ );
31
+ };
32
+
33
+ export default BacktestReport;