Skip to content

Commit 34182b3

Browse files
added hourly trading signals tokens endpoint action
1 parent 068bf3b commit 34182b3

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-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.HOURLY_TRADING_SIGNALS;
6+
7+
export default {
8+
key: "token_metrics-get-hourly-trading-signals",
9+
name: "Get Hourly Trading Signals",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/hourly-trading-signals)`,
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+
optional: false,
20+
},
21+
// Pagination props
22+
limit: {
23+
propDefinition: [
24+
tokenMetrics,
25+
"limit",
26+
],
27+
description: "Limit the number of items in response. Defaults to 50",
28+
default: 50,
29+
},
30+
page: {
31+
propDefinition: [
32+
tokenMetrics,
33+
"page",
34+
],
35+
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",
36+
default: 1,
37+
},
38+
},
39+
async run({ $ }) {
40+
// Build parameters using utility function
41+
const params = buildParams(this, endpoint.filters);
42+
43+
try {
44+
const response = await this.tokenMetrics.getHourlyTradingSignals({
45+
$,
46+
params,
47+
});
48+
49+
// Generate summary using utility function
50+
const filterSummary = generateFilterSummary(this, endpoint.filters);
51+
52+
// Use $ context for export
53+
if ($ && $.export) {
54+
const dataLength = response.data?.length || 0;
55+
$.export("$summary", `Successfully retrieved hourly trading signals for ${dataLength} records${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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ export const ENDPOINTS = {
160160
"symbol",
161161
],
162162
},
163+
HOURLY_TRADING_SIGNALS: {
164+
path: "/hourly-trading-signals",
165+
description: "Get the hourly AI generated trading signals for long and short positions for all tokens",
166+
filters: [
167+
"token_id",
168+
],
169+
},
163170
};
164171

165172
// 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
@@ -231,5 +231,15 @@ export default {
231231
params,
232232
});
233233
},
234+
async getHourlyTradingSignals({
235+
$ = this,
236+
params = {},
237+
}) {
238+
return this.makeApiCall({
239+
$,
240+
endpoint: "/hourly-trading-signals",
241+
params,
242+
});
243+
},
234244
},
235245
};

0 commit comments

Comments
 (0)