1
1
import {
2
- Action ,
3
- composeContext ,
4
- elizaLogger ,
5
- generateText ,
6
- ModelClass ,
7
- parseJSONObjectFromText ,
8
- } from "@elizaOS /core" ;
2
+ Action ,
3
+ composeContext ,
4
+ elizaLogger ,
5
+ generateText ,
6
+ ModelClass ,
7
+ parseJSONObjectFromText ,
8
+ } from "@elizaos /core" ;
9
9
10
10
export const analyzeTradeAction : Action = {
11
- name : "ANALYZE_TRADE" ,
12
- description : "Analyze a token for trading opportunities" ,
13
- similes : [
14
- "ANALYZE" ,
15
- "ANALYZE_TOKEN" ,
16
- "TRADE" ,
17
- "ANALYZE_TRADE" ,
18
- "EVALUATE" ,
19
- "ASSESS" ,
20
- ] ,
21
- examples : [ ] ,
22
- validate : async ( ) => true ,
23
- handler : async ( runtime , memory , state , params , callback ) => {
24
- try {
25
- // composeState
26
- if ( ! state ) {
27
- state = await runtime . composeState ( memory ) ;
28
- } else state = await runtime . updateRecentMessageState ( state ) ;
11
+ name : "ANALYZE_TRADE" ,
12
+ description : "Analyze a token for trading opportunities" ,
13
+ similes : [
14
+ "ANALYZE" ,
15
+ "ANALYZE_TOKEN" ,
16
+ "TRADE" ,
17
+ "ANALYZE_TRADE" ,
18
+ "EVALUATE" ,
19
+ "ASSESS" ,
20
+ ] ,
21
+ examples : [ ] ,
22
+ validate : async ( ) => true ,
23
+ handler : async ( runtime , memory , state , params , callback ) => {
24
+ try {
25
+ // composeState
26
+ if ( ! state ) {
27
+ state = await runtime . composeState ( memory ) ;
28
+ } else state = await runtime . updateRecentMessageState ( state ) ;
29
29
30
- const tokenData = {
31
- walletBalance : params . walletBalance ,
32
- tokenAddress : params . tokenAddress ,
33
- price : params . price ,
34
- volume : params . volume ,
35
- marketCap : params . marketCap ,
36
- liquidity : params . liquidity ,
37
- holderDistribution : params . holderDistribution ,
38
- trustScore : params . trustScore ,
39
- dexscreener : params . dexscreener ,
40
- position : params . position ,
41
- } ;
30
+ const tokenData = {
31
+ walletBalance : params . walletBalance ,
32
+ tokenAddress : params . tokenAddress ,
33
+ price : params . price ,
34
+ volume : params . volume ,
35
+ marketCap : params . marketCap ,
36
+ liquidity : params . liquidity ,
37
+ holderDistribution : params . holderDistribution ,
38
+ trustScore : params . trustScore ,
39
+ dexscreener : params . dexscreener ,
40
+ position : params . position ,
41
+ } ;
42
42
43
- // Direct prompt instead of template
44
- const prompt = `Analyze the following token data and provide a trading recommendation.
43
+ // Direct prompt instead of template
44
+ const prompt = `Analyze the following token data and provide a trading recommendation.
45
45
Return the response as a JSON object with the following structure:
46
46
{
47
47
"recommendation": "BUY" | "SELL" | "HOLD",
@@ -54,41 +54,41 @@ Return the response as a JSON object with the following structure:
54
54
Token Data:
55
55
${ JSON . stringify ( tokenData , null , 2 ) } `;
56
56
57
- // Generate analysis using direct prompt
58
- const content = await generateText ( {
59
- runtime,
60
- context : prompt ,
61
- modelClass : ModelClass . LARGE ,
62
- } ) ;
57
+ // Generate analysis using direct prompt
58
+ const content = await generateText ( {
59
+ runtime,
60
+ context : prompt ,
61
+ modelClass : ModelClass . LARGE ,
62
+ } ) ;
63
63
64
- if ( ! content ) {
65
- throw new Error ( "No analysis generated" ) ;
66
- }
64
+ if ( ! content ) {
65
+ throw new Error ( "No analysis generated" ) ;
66
+ }
67
67
68
- elizaLogger . log ( `Raw analysis response:` , content ) ;
68
+ elizaLogger . log ( `Raw analysis response:` , content ) ;
69
69
70
- // Parse the response to get the recommended action
71
- const recommendation = parseJSONObjectFromText ( content ) ;
72
- elizaLogger . log (
73
- `Parsed recommendation for ${ params . tokenAddress } :` ,
74
- recommendation ,
75
- ) ;
70
+ // Parse the response to get the recommended action
71
+ const recommendation = parseJSONObjectFromText ( content ) ;
72
+ elizaLogger . log (
73
+ `Parsed recommendation for ${ params . tokenAddress } :` ,
74
+ recommendation
75
+ ) ;
76
76
77
- // Send result through callback
78
- if ( callback ) {
79
- await callback ( {
80
- text : JSON . stringify ( recommendation ) ,
81
- type : "analysis" ,
82
- } ) ;
83
- }
77
+ // Send result through callback
78
+ if ( callback ) {
79
+ await callback ( {
80
+ text : JSON . stringify ( recommendation ) ,
81
+ type : "analysis" ,
82
+ } ) ;
83
+ }
84
84
85
- return true ;
86
- } catch ( error ) {
87
- elizaLogger . error ( `Analysis failed:` , {
88
- error : error instanceof Error ? error . message : "Unknown error" ,
89
- stack : error instanceof Error ? error . stack : undefined ,
90
- } ) ;
91
- return false ;
92
- }
93
- } ,
85
+ return true ;
86
+ } catch ( error ) {
87
+ elizaLogger . error ( `Analysis failed:` , {
88
+ error : error instanceof Error ? error . message : "Unknown error" ,
89
+ stack : error instanceof Error ? error . stack : undefined ,
90
+ } ) ;
91
+ return false ;
92
+ }
93
+ } ,
94
94
} ;
0 commit comments