Skip to content

Commit 674f23f

Browse files
added technology grades historical tokens endpoint action
1 parent 7668376 commit 674f23f

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.TECHNOLOGY_GRADES_HISTORICAL;
6+
7+
export default {
8+
key: "token_metrics-get-technology-grades-historical",
9+
name: "Get Technology Grades Historical",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/technology-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.getTechnologyGradesHistorical({
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 technology 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
@@ -113,6 +113,17 @@ export const ENDPOINTS = {
113113
"symbol",
114114
],
115115
},
116+
TECHNOLOGY_GRADES_HISTORICAL: {
117+
path: "/technology-grade-history",
118+
description: "Get historical Technology Grade data for a token, including activity score, security score, repository score, collaboration score, and DeFi scanner score over time",
119+
filters: [
120+
"token_id",
121+
"token_name",
122+
"symbol",
123+
"start_date",
124+
"end_date",
125+
],
126+
},
116127
};
117128

118129
// 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
@@ -171,5 +171,15 @@ export default {
171171
params,
172172
});
173173
},
174+
async getTechnologyGradesHistorical({
175+
$ = this,
176+
params = {},
177+
}) {
178+
return this.makeApiCall({
179+
$,
180+
endpoint: "/technology-grade-history",
181+
params,
182+
});
183+
},
174184
},
175185
};

0 commit comments

Comments
 (0)