import { z } from "zod";
import { wsManager } from "../services/websocket-manager.js";
const schema = z.object({
token_ids: z
.array(z.string())
.min(1)
.describe("List of token IDs to monitor orderbooks for"),
depth: z
.number()
.min(1)
.max(100)
.optional()
.default(10)
.describe("Number of price levels to include (default: 10)"),
callback_type: z
.enum(["notification", "log"])
.optional()
.default("notification")
.describe("How to receive updates"),
});
export const subscribeOrderbookUpdatesTool = {
name: "subscribe_orderbook_updates",
description:
"Subscribe to real-time orderbook updates by token_ids (clobTokenIds). Source: list_active_markets/get_market_details. Use get_realtime_status to inspect events. Example: token_ids=[clobTokenIds[0]].",
parameters: schema,
execute: async (args: z.infer<typeof schema>) => {
try {
const id = wsManager.subscribe({
type: "book",
assets: args.token_ids,
callbackType: args.callback_type,
});
return JSON.stringify({ subscription_id: id, status: "subscribed", tokens: args.token_ids });
} catch (error) {
return JSON.stringify({ error: error instanceof Error ? error.message : String(error) });
}
},
};