Skip to content

Commit 5a9ce83

Browse files
added tm grades tokens endpoint action
1 parent 256b743 commit 5a9ce83

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import tokenMetrics from "../../token_metrics.app.mjs";
2+
import { ENDPOINTS, FILTER_DEFINITIONS } from "../../common/constants.mjs";
3+
import { buildParams, generateFilterSummary } from "../../common/utils.mjs";
4+
5+
const endpoint = ENDPOINTS.TM_GRADES;
6+
7+
export default {
8+
key: "token_metrics-get-tm-grades",
9+
name: "Get TM Grades",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/tm-grade)`,
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
tokenMetrics,
15+
// Filter props based on endpoint configuration and screenshot
16+
tokenId: {
17+
...FILTER_DEFINITIONS.token_id,
18+
description: "Click here to access the list of token IDs. Example: 3375",
19+
},
20+
tokenName: {
21+
...FILTER_DEFINITIONS.token_name,
22+
description: "Crypto Asset Names (e.g., Bitcoin, Ethereum). Click here to access the list of token names.",
23+
},
24+
symbol: {
25+
...FILTER_DEFINITIONS.symbol,
26+
description: "Click here to access the list of token symbols. Example: BTC,ETH",
27+
},
28+
// Pagination props
29+
limit: {
30+
propDefinition: [
31+
tokenMetrics,
32+
"limit",
33+
],
34+
description: "Limit the number of items in response. Defaults to 50",
35+
default: 50,
36+
},
37+
page: {
38+
propDefinition: [
39+
tokenMetrics,
40+
"page",
41+
],
42+
description: "Enables pagination and data retrieval control by skipping a specified number of items before fetching data. Page should be a non-negative integer, with 1 indicating the beginning of the dataset. Defaults to 1",
43+
default: 1,
44+
},
45+
},
46+
async run({ $ }) {
47+
// Build parameters using utility function
48+
const params = buildParams(this, endpoint.filters);
49+
50+
try {
51+
const response = await this.tokenMetrics.getTmGrades({
52+
$,
53+
params,
54+
});
55+
56+
// Generate summary using utility function
57+
const filterSummary = generateFilterSummary(this, endpoint.filters);
58+
59+
// Use $ context for export
60+
if ($ && $.export) {
61+
const dataLength = response.data?.length || 0;
62+
$.export("$summary", `Successfully retrieved TM grades for ${dataLength} tokens${filterSummary}`);
63+
}
64+
65+
return response;
66+
} catch (error) {
67+
// Enhanced error handling
68+
const errorMessage = error.response?.data?.message || error.message || "An error occurred";
69+
const statusCode = error.response?.status;
70+
71+
if ($ && $.export) {
72+
$.export("$summary", `Error: ${errorMessage}`);
73+
}
74+
75+
// Throw a more descriptive error
76+
throw new Error(`Token Metrics API Error (${statusCode || 'Unknown'}): ${errorMessage}`);
77+
}
78+
},
79+
};

components/token_metrics/common/constants.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ export const ENDPOINTS = {
6464
"type",
6565
],
6666
},
67+
TM_GRADES: {
68+
path: "/tm-grade",
69+
description: "Get the latest TM Grade for a token, including trader grade change, quant grade, signals, momentum, and 24-hour percentage changes for both TM Grade and Trader Grade",
70+
filters: [
71+
"token_id",
72+
"token_name",
73+
"symbol",
74+
],
75+
},
6776
};
6877

6978
// Common filter definitions that can be reused across endpoints

components/token_metrics/token_metrics.app.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,15 @@ export default {
121121
params,
122122
});
123123
},
124+
async getTmGrades({
125+
$ = this,
126+
params = {},
127+
}) {
128+
return this.makeApiCall({
129+
$,
130+
endpoint: "/tm-grade",
131+
params,
132+
});
133+
},
124134
},
125135
};

0 commit comments

Comments
 (0)