Skip to content

Commit b79de6b

Browse files
added quantmetrics tokens endpoint action
1 parent 34182b3 commit b79de6b

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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.QUANTMETRICS;
6+
7+
export default {
8+
key: "token_metrics-get-quantmetrics",
9+
name: "Get Quantmetrics",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/quantmetrics)`,
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: "Comma Separated Token IDs. Click here to access the list of token IDs. Example: 3375,3306",
19+
},
20+
symbol: {
21+
...FILTER_DEFINITIONS.symbol,
22+
description: "Comma Separated Token Symbols. Click here to access the list of token symbols. Example: BTC,ETH",
23+
},
24+
category: {
25+
...FILTER_DEFINITIONS.category,
26+
description: "Comma separated category name. Click here to access the list of categories. Example: layer-1,nft",
27+
},
28+
exchange: {
29+
...FILTER_DEFINITIONS.exchange,
30+
description: "Comma separated exchange name. Click here to access the list of exchanges. Example: binance,gate",
31+
},
32+
marketCap: {
33+
...FILTER_DEFINITIONS.market_cap,
34+
description: "Minimum MarketCap in $. Example: 1000000000",
35+
},
36+
volume: {
37+
...FILTER_DEFINITIONS.volume,
38+
description: "Minimum 24h trading volume in $. Example: 1000000000",
39+
},
40+
fdv: {
41+
...FILTER_DEFINITIONS.fdv,
42+
description: "Minimum fully diluted valuation in $. Example: 1000000000",
43+
},
44+
// Pagination props
45+
limit: {
46+
propDefinition: [
47+
tokenMetrics,
48+
"limit",
49+
],
50+
description: "Limit the number of items in response. Defaults to 50",
51+
default: 50,
52+
},
53+
page: {
54+
propDefinition: [
55+
tokenMetrics,
56+
"page",
57+
],
58+
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",
59+
default: 1,
60+
},
61+
},
62+
async run({ $ }) {
63+
// Build parameters using utility function
64+
const params = buildParams(this, endpoint.filters);
65+
66+
try {
67+
const response = await this.tokenMetrics.getQuantmetrics({
68+
$,
69+
params,
70+
});
71+
72+
// Generate summary using utility function
73+
const filterSummary = generateFilterSummary(this, endpoint.filters);
74+
75+
// Use $ context for export
76+
if ($ && $.export) {
77+
const dataLength = response.data?.length || 0;
78+
$.export("$summary", `Successfully retrieved quantmetrics for ${dataLength} tokens${filterSummary}`);
79+
}
80+
81+
return response;
82+
} catch (error) {
83+
// Enhanced error handling
84+
const errorMessage = error.response?.data?.message || error.message || "An error occurred";
85+
const statusCode = error.response?.status;
86+
87+
if ($ && $.export) {
88+
$.export("$summary", `Error: ${errorMessage}`);
89+
}
90+
91+
// Throw a more descriptive error
92+
throw new Error(`Token Metrics API Error (${statusCode || 'Unknown'}): ${errorMessage}`);
93+
}
94+
},
95+
};

components/token_metrics/common/constants.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ export const ENDPOINTS = {
167167
"token_id",
168168
],
169169
},
170+
QUANTMETRICS: {
171+
path: "/quantmetrics",
172+
description: "Get the latest quantitative metrics for tokens. Note that Token Metrics pricing data starts on 2019-01-01 for most tokens. More historical data will be available soon",
173+
filters: [
174+
"token_id",
175+
"symbol",
176+
"category",
177+
"exchange",
178+
"market_cap",
179+
"volume",
180+
"fdv",
181+
],
182+
},
170183
};
171184

172185
// 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
@@ -241,5 +241,15 @@ export default {
241241
params,
242242
});
243243
},
244+
async getQuantmetrics({
245+
$ = this,
246+
params = {},
247+
}) {
248+
return this.makeApiCall({
249+
$,
250+
endpoint: "/quantmetrics",
251+
params,
252+
});
253+
},
244254
},
245255
};

0 commit comments

Comments
 (0)