Skip to content

Commit 256b743

Browse files
added moonshot tokens endpoint action
1 parent 026e5c1 commit 256b743

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.MOONSHOT_TOKENS;
6+
7+
export default {
8+
key: "token_metrics-get-moonshot-tokens",
9+
name: "Get Moonshot Tokens",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/moonshot-tokens)`,
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
tokenMetrics,
15+
// Filter props based on endpoint configuration and screenshot
16+
type: {
17+
...FILTER_DEFINITIONS.type,
18+
description: "Accepts 'active' or 'past' to fetch respective moonshots. Defaults to 'active' if not provided",
19+
},
20+
// Pagination props
21+
limit: {
22+
propDefinition: [
23+
tokenMetrics,
24+
"limit",
25+
],
26+
description: "Limit the number of items in response. Defaults to 50",
27+
default: 50,
28+
},
29+
page: {
30+
propDefinition: [
31+
tokenMetrics,
32+
"page",
33+
],
34+
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",
35+
default: 1,
36+
},
37+
},
38+
async run({ $ }) {
39+
// Build parameters using utility function
40+
const params = buildParams(this, endpoint.filters);
41+
42+
try {
43+
const response = await this.tokenMetrics.getMoonshotTokens({
44+
$,
45+
params,
46+
});
47+
48+
// Generate summary using utility function
49+
const filterSummary = generateFilterSummary(this, endpoint.filters);
50+
51+
// Use $ context for export
52+
if ($ && $.export) {
53+
const dataLength = response.data?.length || 0;
54+
const moonshotType = this.type || "active";
55+
$.export("$summary", `Successfully retrieved ${dataLength} ${moonshotType} moonshot tokens${filterSummary}`);
56+
}
57+
58+
return response;
59+
} catch (error) {
60+
// Enhanced error handling
61+
const errorMessage = error.response?.data?.message || error.message || "An error occurred";
62+
const statusCode = error.response?.status;
63+
64+
if ($ && $.export) {
65+
$.export("$summary", `Error: ${errorMessage}`);
66+
}
67+
68+
// Throw a more descriptive error
69+
throw new Error(`Token Metrics API Error (${statusCode || 'Unknown'}): ${errorMessage}`);
70+
}
71+
},
72+
};

components/token_metrics/common/constants.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export const ENDPOINTS = {
5757
"end_date",
5858
],
5959
},
60+
MOONSHOT_TOKENS: {
61+
path: "/moonshot-tokens",
62+
description: "Get the AI-curated token picks (Moonshots) with high breakout potential based on grades, sentiment, volume, and on-chain data to help users trade smarter and faster",
63+
filters: [
64+
"type",
65+
],
66+
},
6067
};
6168

6269
// Common filter definitions that can be reused across endpoints
@@ -147,6 +154,23 @@ export const FILTER_DEFINITIONS = {
147154
},
148155
],
149156
},
157+
type: {
158+
type: "string",
159+
label: "Type",
160+
description: "Accepts 'active' or 'past' to fetch respective moonshots. Defaults to 'active' if not provided",
161+
optional: true,
162+
options: [
163+
{
164+
label: "Active",
165+
value: "active",
166+
},
167+
{
168+
label: "Past",
169+
value: "past",
170+
},
171+
],
172+
default: "active",
173+
},
150174
};
151175

152176
// Common error messages

components/token_metrics/token_metrics.app.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,15 @@ export default {
111111
params,
112112
});
113113
},
114+
async getMoonshotTokens({
115+
$ = this,
116+
params = {},
117+
}) {
118+
return this.makeApiCall({
119+
$,
120+
endpoint: "/moonshot-tokens",
121+
params,
122+
});
123+
},
114124
},
115125
};

0 commit comments

Comments
 (0)