import { z } from "zod";
import { getPriceHistory } from "../services/clob-public.js";
const schema = z.object({
token_id: z.string().describe("The token ID to get price history for"),
interval: z.string().optional().describe("Time interval (e.g., '1d', '1h', '1m')"),
fidelity: z.number().optional().describe("Number of data points to return"),
startTs: z.number().optional().describe("Start timestamp (unix seconds)"),
endTs: z.number().optional().describe("End timestamp (unix seconds)"),
});
export const getPriceHistoryTool = {
name: "get_price_history",
description:
"Get historical price data for a token. Source: clobTokenIds from list_active_markets or get_market_details. If no history, returns history=[]. Example: token_id=clobTokenIds[0], interval=1h.",
parameters: schema,
execute: async (args: z.infer<typeof schema>) => {
try {
const data = await getPriceHistory(args.token_id, args.interval, args.fidelity, args.startTs, args.endTs);
return JSON.stringify(data, null, 2);
} catch (error) {
return JSON.stringify({ error: error instanceof Error ? error.message : String(error) });
}
},
};