import { z } from "zod";
import { fetchMarkets } from "../services/gamma.js";
const schema = z.object({
timeframe: z
.enum(["24h", "7d", "30d"])
.optional()
.default("24h")
.describe("Time period for volume ranking (default: 24h)"),
limit: z
.number()
.max(100)
.optional()
.default(10)
.describe("Number of markets to return (default: 10, max: 100)"),
});
const volumeField: Record<string, string> = {
"24h": "volume24hr",
"7d": "volume24hr", // Gamma API only has volume24hr; 7d/30d use total volume
"30d": "volume",
};
export const getTrendingMarketsTool = {
name: "get_trending_markets",
description:
"Get markets with highest trading volume for timeframe. Returns active markets sorted by volume. Example: timeframe=24h, limit=10.",
parameters: schema,
execute: async (args: z.infer<typeof schema>) => {
try {
const order = volumeField[args.timeframe] ?? "volume24hr";
const data = await fetchMarkets({
limit: args.limit,
order,
ascending: false,
active: true,
closed: false,
});
return JSON.stringify(data, null, 2);
} catch (error) {
return JSON.stringify({ error: error instanceof Error ? error.message : String(error) });
}
},
};