Skip to content

Commit 1254807

Browse files
added fundamental grades tokens endpoint action
1 parent fe51956 commit 1254807

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.FUNDAMENTAL_GRADES;
6+
7+
export default {
8+
key: "token_metrics-get-fundamental-grades",
9+
name: "Get Fundamental Grades",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/fundamental-grade)`,
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
tokenMetrics,
15+
// Filter props based on endpoint configuration and API documentation
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.getFundamentalGrades({
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 fundamental 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
@@ -84,6 +84,15 @@ export const ENDPOINTS = {
8484
"end_date",
8585
],
8686
},
87+
FUNDAMENTAL_GRADES: {
88+
path: "/fundamental-grade",
89+
description: "Get the latest Fundamental Grade insights for a token, including grade class, community score, exchange score, VC score, tokenomics score, and DeFi scanner score",
90+
filters: [
91+
"token_id",
92+
"token_name",
93+
"symbol",
94+
],
95+
},
8796
};
8897

8998
// 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
@@ -141,5 +141,15 @@ export default {
141141
params,
142142
});
143143
},
144+
async getFundamentalGrades({
145+
$ = this,
146+
params = {},
147+
}) {
148+
return this.makeApiCall({
149+
$,
150+
endpoint: "/fundamental-grade",
151+
params,
152+
});
153+
},
144154
},
145155
};

0 commit comments

Comments
 (0)