Skip to content

Commit 0f5997a

Browse files
added scenario analysis tokens endpoint action
1 parent b79de6b commit 0f5997a

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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.SCENARIO_ANALYSIS;
6+
7+
export default {
8+
key: "token_metrics-get-scenario-analysis",
9+
name: "Get Scenario Analysis",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/scenario-analysis)`,
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+
// Pagination props
25+
limit: {
26+
propDefinition: [
27+
tokenMetrics,
28+
"limit",
29+
],
30+
description: "Limit the number of items in response. Defaults to 50",
31+
default: 50,
32+
},
33+
page: {
34+
propDefinition: [
35+
tokenMetrics,
36+
"page",
37+
],
38+
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",
39+
default: 1,
40+
},
41+
},
42+
async run({ $ }) {
43+
// Build parameters using utility function
44+
const params = buildParams(this, endpoint.filters);
45+
46+
try {
47+
const response = await this.tokenMetrics.getScenarioAnalysis({
48+
$,
49+
params,
50+
});
51+
52+
// Generate summary using utility function
53+
const filterSummary = generateFilterSummary(this, endpoint.filters);
54+
55+
// Use $ context for export
56+
if ($ && $.export) {
57+
const dataLength = response.data?.length || 0;
58+
$.export("$summary", `Successfully retrieved scenario analysis for ${dataLength} tokens${filterSummary}`);
59+
}
60+
61+
return response;
62+
} catch (error) {
63+
// Enhanced error handling
64+
const errorMessage = error.response?.data?.message || error.message || "An error occurred";
65+
const statusCode = error.response?.status;
66+
67+
if ($ && $.export) {
68+
$.export("$summary", `Error: ${errorMessage}`);
69+
}
70+
71+
// Throw a more descriptive error
72+
throw new Error(`Token Metrics API Error (${statusCode || 'Unknown'}): ${errorMessage}`);
73+
}
74+
},
75+
};

components/token_metrics/common/constants.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ export const ENDPOINTS = {
180180
"fdv",
181181
],
182182
},
183+
SCENARIO_ANALYSIS: {
184+
path: "/scenario-analysis",
185+
description: "Get the price prediction based on different Crypto Market scenario",
186+
filters: [
187+
"token_id",
188+
"symbol",
189+
],
190+
},
183191
};
184192

185193
// 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
@@ -251,5 +251,15 @@ export default {
251251
params,
252252
});
253253
},
254+
async getScenarioAnalysis({
255+
$ = this,
256+
params = {},
257+
}) {
258+
return this.makeApiCall({
259+
$,
260+
endpoint: "/scenario-analysis",
261+
params,
262+
});
263+
},
254264
},
255265
};

0 commit comments

Comments
 (0)