import { z } from "zod";
import { fetchMarkets } from "../services/gamma.js";
const schema = z.object({
hours: z
.number()
.optional()
.default(24)
.describe("Number of hours to look ahead (default: 24)"),
limit: z
.number()
.max(100)
.optional()
.default(20)
.describe("Maximum number of results (default: 20, max: 100)"),
});
export const getClosingSoonMarketsTool = {
name: "get_closing_soon_markets",
description:
"Get markets closing within specified hours. Returns active markets sorted by endDate. Example: hours=24, limit=20.",
parameters: schema,
execute: async (args: z.infer<typeof schema>) => {
try {
const now = new Date();
const future = new Date(now.getTime() + args.hours * 60 * 60 * 1000);
const data = await fetchMarkets({
limit: args.limit,
order: "endDate",
ascending: true,
active: true,
closed: false,
end_date_min: now.toISOString(),
end_date_max: future.toISOString(),
});
return JSON.stringify(data, null, 2);
} catch (error) {
return JSON.stringify({ error: error instanceof Error ? error.message : String(error) });
}
},
};