1inch-agent-kit
Version:
AI Agent Kit for 1inch - Connect any LLM to 1inch DeFi protocols
61 lines • 2.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLineChart = getLineChart;
exports.getCandleChart = getCandleChart;
exports.chartsAPI = chartsAPI;
const fetcher_1 = require("../../utils/fetcher");
/**
* Get historical line chart data for a specific token pair and period
*/
async function getLineChart(params) {
const apiKey = process.env.ONEINCH_API_KEY;
if (!apiKey) {
throw new Error("1inch API key is required. Set ONEINCH_API_KEY environment variable.");
}
const fetcher = new fetcher_1.OneInchFetcher(apiKey);
const url = `/charts/v1.0/chart/line/${params.token0}/${params.token1}/${params.period}/${params.chainId}`;
return await fetcher.get(url);
}
/**
* Get historical candle chart data for a specific token pair and period
*/
async function getCandleChart(params) {
const apiKey = process.env.ONEINCH_API_KEY;
if (!apiKey) {
throw new Error("1inch API key is required. Set ONEINCH_API_KEY environment variable.");
}
const fetcher = new fetcher_1.OneInchFetcher(apiKey);
const url = `/charts/v1.0/chart/aggregated/candle/${params.token0}/${params.token1}/${params.seconds}/${params.chainId}`;
return await fetcher.get(url);
}
/**
* Main charts API function that can handle both line and candle charts
*/
async function chartsAPI(params) {
if (params.type === "line") {
if (!params.period) {
throw new Error("Period is required for line charts. Supported periods: 24H, 1W, 1M, 1Y, AllTime");
}
return await getLineChart({
token0: params.token0,
token1: params.token1,
period: params.period,
chainId: params.chainId
});
}
else if (params.type === "candle") {
if (!params.seconds) {
throw new Error("Seconds is required for candle charts. Supported seconds: 300, 900, 3600, 14400, 86400, 604800");
}
return await getCandleChart({
token0: params.token0,
token1: params.token1,
seconds: params.seconds,
chainId: params.chainId
});
}
else {
throw new Error("Invalid chart type. Must be 'line' or 'candle'");
}
}
//# sourceMappingURL=index.js.map