Skip to content

Commit 43fa7ca

Browse files
added fundamental grades historical tokens endpoint action
1 parent 1254807 commit 43fa7ca

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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_HISTORICAL;
6+
7+
export default {
8+
key: "token_metrics-get-fundamental-grades-historical",
9+
name: "Get Fundamental Grades Historical",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/fundamental-grade-history)`,
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+
startDate: {
29+
...FILTER_DEFINITIONS.start_date,
30+
description: "Start Date accepts date as a string - YYYY-MM-DD format. Example: 2025-07-01",
31+
},
32+
endDate: {
33+
...FILTER_DEFINITIONS.end_date,
34+
description: "End Date accepts date as a string - YYYY-MM-DD format. Example: 2025-07-05",
35+
},
36+
// Pagination props
37+
limit: {
38+
propDefinition: [
39+
tokenMetrics,
40+
"limit",
41+
],
42+
description: "Limit the number of items in response. Defaults to 50",
43+
default: 50,
44+
},
45+
page: {
46+
propDefinition: [
47+
tokenMetrics,
48+
"page",
49+
],
50+
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",
51+
default: 1,
52+
},
53+
},
54+
async run({ $ }) {
55+
// Build parameters using utility function
56+
const params = buildParams(this, endpoint.filters);
57+
58+
try {
59+
const response = await this.tokenMetrics.getFundamentalGradesHistorical({
60+
$,
61+
params,
62+
});
63+
64+
// Generate summary using utility function
65+
const filterSummary = generateFilterSummary(this, endpoint.filters);
66+
67+
// Use $ context for export
68+
if ($ && $.export) {
69+
const dataLength = response.data?.length || 0;
70+
$.export("$summary", `Successfully retrieved historical fundamental grades for ${dataLength} records${filterSummary}`);
71+
}
72+
73+
return response;
74+
} catch (error) {
75+
// Enhanced error handling
76+
const errorMessage = error.response?.data?.message || error.message || "An error occurred";
77+
const statusCode = error.response?.status;
78+
79+
if ($ && $.export) {
80+
$.export("$summary", `Error: ${errorMessage}`);
81+
}
82+
83+
// Throw a more descriptive error
84+
throw new Error(`Token Metrics API Error (${statusCode || 'Unknown'}): ${errorMessage}`);
85+
}
86+
},
87+
};

components/token_metrics/common/constants.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ export const ENDPOINTS = {
9393
"symbol",
9494
],
9595
},
96+
FUNDAMENTAL_GRADES_HISTORICAL: {
97+
path: "/fundamental-grade-history",
98+
description: "Get historical Fundamental Grade insights for a token, including grade class, community score, exchange score, VC score, tokenomics score, and DeFi scanner score over time",
99+
filters: [
100+
"token_id",
101+
"token_name",
102+
"symbol",
103+
"start_date",
104+
"end_date",
105+
],
106+
},
96107
};
97108

98109
// 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
@@ -151,5 +151,15 @@ export default {
151151
params,
152152
});
153153
},
154+
async getFundamentalGradesHistorical({
155+
$ = this,
156+
params = {},
157+
}) {
158+
return this.makeApiCall({
159+
$,
160+
endpoint: "/fundamental-grade-history",
161+
params,
162+
});
163+
},
154164
},
155165
};

0 commit comments

Comments
 (0)