Skip to content

Commit 026e5c1

Browse files
added daily ohlcv endpoint action
1 parent 5d78903 commit 026e5c1

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.DAILY_OHLCV;
6+
7+
export default {
8+
key: "token_metrics-get-daily-ohlcv",
9+
name: "Get Daily OHLCV",
10+
description: `${endpoint.description}. [See the documentation](https://developers.tokenmetrics.com/reference/daily-ohlcv)`,
11+
version: "0.0.1",
12+
type: "action",
13+
props: {
14+
tokenMetrics,
15+
// Filter props based on endpoint configuration and screenshot
16+
tokenId: {
17+
...FILTER_DEFINITIONS.token_id,
18+
description: "Comma Separated Token IDs. Click here to access the list of token IDs. Example: 3375",
19+
},
20+
symbol: {
21+
...FILTER_DEFINITIONS.symbol,
22+
description: "Comma Separated Token Symbols. Click here to access the list of token symbols. Example: BTC",
23+
},
24+
tokenName: {
25+
...FILTER_DEFINITIONS.token_name,
26+
description: "Comma Separated Crypto Asset Names (e.g., Bitcoin, Ethereum). Click here to access the list of token names. Example: Bitcoin",
27+
},
28+
startDate: {
29+
...FILTER_DEFINITIONS.start_date,
30+
description: "Start Date accepts date as a string - YYYY-MM-DD format. Note: The Start Date cannot be earlier than the past 30 days from the current date. Example: 2025-01-01",
31+
},
32+
endDate: {
33+
...FILTER_DEFINITIONS.end_date,
34+
description: "End Date accepts date as a string - YYYY-MM-DD format. Example: 2025-01-23",
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.getDailyOhlcv({
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 ${dataLength} daily OHLCV 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
@@ -46,6 +46,17 @@ export const ENDPOINTS = {
4646
"end_date",
4747
],
4848
},
49+
DAILY_OHLCV: {
50+
path: "/daily-ohlcv",
51+
description: "Get daily OHLCV (Open, High, Low, Close, Volume) data for tokens",
52+
filters: [
53+
"token_id",
54+
"symbol",
55+
"token_name",
56+
"start_date",
57+
"end_date",
58+
],
59+
},
4960
};
5061

5162
// 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
@@ -101,5 +101,15 @@ export default {
101101
params,
102102
});
103103
},
104+
async getDailyOhlcv({
105+
$ = this,
106+
params = {},
107+
}) {
108+
return this.makeApiCall({
109+
$,
110+
endpoint: "/daily-ohlcv",
111+
params,
112+
});
113+
},
104114
},
105115
};

0 commit comments

Comments
 (0)