import { z } from "zod";
import { getPrice } from "../services/clob-public.js";
const schema = z.object({
token_id: z.string().describe("Token ID"),
side: z
.enum(["BUY", "SELL", "BOTH"])
.optional()
.default("BOTH")
.describe("Price side to fetch (default: BOTH)"),
});
export const getCurrentPriceTool = {
name: "get_current_price",
description:
"Get CLOB /price for BUY/SELL and return bid/ask/mid. Source: clobTokenIds from list_active_markets or get_market_details. If token has no active CLOB/order book, returns 404. Example: token_id=clobTokenIds[0], side=BOTH.",
parameters: schema,
execute: async (args: z.infer<typeof schema>) => {
try {
const data = await getPrice(args.token_id);
if (args.side === "BUY") return JSON.stringify({ bid: data.bid }, null, 2);
if (args.side === "SELL") return JSON.stringify({ ask: data.ask }, null, 2);
return JSON.stringify(data, null, 2);
} catch (error) {
return JSON.stringify({ error: error instanceof Error ? error.message : String(error) });
}
},
};