-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathindicator.tsx
More file actions
84 lines (77 loc) · 2.71 KB
/
Copy pathindicator.tsx
File metadata and controls
84 lines (77 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { checkIndicatorsAction } from "@/server/actions/indicator";
import { z } from 'zod';
// Define the schema for the tool's parameters
const indicatorToolParameters = z.object({
indicator: z.enum(['rsi', 'sma', 'bb', 'macd']).describe('The indicator to check'),
parameters: z.object({
period: z.number().optional().describe('The period for the indicator'),
fast: z.number().optional(),
slow: z.number().optional(),
signal: z.number().optional(),
}),
contractAddress: z.string().describe('The contract address of the token to check'),
fromTimestamp: z.number().optional().describe('The timestamp to start checking from'),
});
// Define the tool
export const indicatorTools = {
checkIndicators: {
displayName: '📈 Indicator Tool',
description: 'Check financial indicators like RSI, SMA, BB, and MACD for a given contract address.',
parameters: indicatorToolParameters,
execute: async (input: z.infer<typeof indicatorToolParameters>) => {
try {
// Call the existing checkIndicatorsAction function
const result = await checkIndicatorsAction(input);
if(!result?.data) {
return {
success: false,
error: 'Unable to fetch indicator data.',
};
}
if (result?.data?.success) {
return {
success: true,
data: result.data.data,
suppressFollowUp: true,
};
} else {
return {
success: false,
error: result.data.error,
};
}
} catch (error) {
return {
success: false,
error: 'Unexpected error during indicator check',
};
}
},
render: (result: unknown) => {
const typedResult = result as {
success: boolean;
data?: number;
error?: string;
};
if (!typedResult.success) {
return (
<div className="relative overflow-hidden rounded-2xl bg-muted p-4">
<div className="flex items-center gap-3">
<p className="text-md text-center">
{typedResult.error || 'Unable to fetch indicator data.'}
</p>
</div>
</div>
);
}
return (
<div className="space-y-4">
<div className="rounded-lg bg-muted p-4">
<p className="text-sm text-muted-foreground">Indicator Result</p>
<p className="font-medium">{typedResult.data}</p>
</div>
</div>
);
},
},
};