Skip to main content
Glama
gtorreal
by gtorreal

get_orderbook

Retrieve current order book for any Buda.com market. Bids sorted highest first, asks lowest first, with price in quote currency and amount in base currency.

Instructions

Returns the current order book for a Buda.com market as typed objects with float price and amount fields. Bids are sorted highest-price first; asks lowest-price first. Prices are in the quote currency; amounts are in the base currency. Example: 'What are the top 5 buy and sell orders for BTC-CLP right now?'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
market_idYesMarket ID (e.g. 'BTC-CLP', 'ETH-BTC').
limitNoMaximum number of levels to return per side (default: all).

Implementation Reference

  • The async handler function for get_orderbook. Validates market_id, fetches order book from Buda API via cache, slices bids/asks by optional limit, maps price/amount to floats, and returns the result.
      async ({ market_id, limit }) => {
        try {
          const validationError = validateMarketId(market_id);
          if (validationError) {
            return {
              content: [{ type: "text", text: JSON.stringify({ error: validationError, code: "INVALID_MARKET_ID" }) }],
              isError: true,
            };
          }
    
          const id = market_id.toLowerCase();
          const data = await cache.getOrFetch<OrderBookResponse>(
            `orderbook:${id}`,
            CACHE_TTL.ORDERBOOK,
            () => client.get<OrderBookResponse>(`/markets/${id}/order_book`),
          );
    
          const book = data.order_book;
          const bids = limit ? book.bids.slice(0, limit) : book.bids;
          const asks = limit ? book.asks.slice(0, limit) : book.asks;
    
          const result = {
            bids: bids.map(([price, amount]) => ({
              price: parseFloat(price),
              amount: parseFloat(amount),
            })),
            asks: asks.map(([price, amount]) => ({
              price: parseFloat(price),
              amount: parseFloat(amount),
            })),
            bid_count: book.bids.length,
            ask_count: book.asks.length,
          };
    
          return {
            content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
          };
        } catch (err) {
          const msg = formatApiError(err);
          return {
            content: [{ type: "text", text: JSON.stringify(msg) }],
            isError: true,
          };
        }
      },
    );
  • The schema definition for get_orderbook, including its name, description, and inputSchema with market_id (string, required) and limit (number, optional).
    export const toolSchema = {
      name: "get_orderbook",
      description:
        "Returns the current order book for a Buda.com market as typed objects with float price and amount fields. " +
        "Bids are sorted highest-price first; asks lowest-price first. " +
        "Prices are in the quote currency; amounts are in the base currency. " +
        "Example: 'What are the top 5 buy and sell orders for BTC-CLP right now?'",
      inputSchema: {
        type: "object" as const,
        properties: {
          market_id: {
            type: "string",
            description: "Market ID (e.g. 'BTC-CLP', 'ETH-BTC').",
          },
          limit: {
            type: "number",
            description: "Maximum number of levels to return per side (default: all).",
          },
        },
        required: ["market_id"],
      },
    };
  • Registration function that calls server.tool() with the schema name, description, Zod-validated params, and the handler.
    export function register(server: McpServer, client: BudaClient, cache: MemoryCache): void {
      server.tool(
        toolSchema.name,
        toolSchema.description,
        {
          market_id: z
            .string()
            .describe("Market ID (e.g. 'BTC-CLP', 'ETH-BTC')."),
          limit: z
            .number()
            .int()
            .positive()
            .optional()
            .describe("Maximum number of levels to return per side (default: all)."),
        },
        async ({ market_id, limit }) => {
          try {
            const validationError = validateMarketId(market_id);
            if (validationError) {
              return {
                content: [{ type: "text", text: JSON.stringify({ error: validationError, code: "INVALID_MARKET_ID" }) }],
                isError: true,
              };
            }
    
            const id = market_id.toLowerCase();
            const data = await cache.getOrFetch<OrderBookResponse>(
              `orderbook:${id}`,
              CACHE_TTL.ORDERBOOK,
              () => client.get<OrderBookResponse>(`/markets/${id}/order_book`),
            );
    
            const book = data.order_book;
            const bids = limit ? book.bids.slice(0, limit) : book.bids;
            const asks = limit ? book.asks.slice(0, limit) : book.asks;
    
            const result = {
              bids: bids.map(([price, amount]) => ({
                price: parseFloat(price),
                amount: parseFloat(amount),
              })),
              asks: asks.map(([price, amount]) => ({
                price: parseFloat(price),
                amount: parseFloat(amount),
              })),
              bid_count: book.bids.length,
              ask_count: book.asks.length,
            };
    
            return {
              content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
            };
          } catch (err) {
            const msg = formatApiError(err);
            return {
              content: [{ type: "text", text: JSON.stringify(msg) }],
              isError: true,
            };
          }
        },
      );
    }
  • src/index.ts:12-38 (registration)
    Import and registration of the orderbook tool in the main stdio server entry point.
    import * as orderbook from "./tools/orderbook.js";
    import * as trades from "./tools/trades.js";
    import * as volume from "./tools/volume.js";
    import * as spread from "./tools/spread.js";
    import * as compareMarkets from "./tools/compare_markets.js";
    import * as priceHistory from "./tools/price_history.js";
    import * as arbitrage from "./tools/arbitrage.js";
    import * as marketSummary from "./tools/market_summary.js";
    import * as simulateOrder from "./tools/simulate_order.js";
    import * as positionSize from "./tools/calculate_position_size.js";
    import * as marketSentiment from "./tools/market_sentiment.js";
    import * as technicalIndicators from "./tools/technical_indicators.js";
    import * as banks from "./tools/banks.js";
    import * as quotation from "./tools/quotation.js";
    import * as stableLiquidity from "./tools/stable_liquidity.js";
    import { handleMarketSummary } from "./tools/market_summary.js";
    
    const client = new BudaClient();
    
    const server = new McpServer({
      name: "buda-mcp",
      version: VERSION,
    });
    
    markets.register(server, client, cache);
    ticker.register(server, client, cache);
    orderbook.register(server, client, cache);
  • Type definitions for OrderBook (asks/bids as string tuple arrays) and OrderBookResponse used by the handler.
    export interface OrderBook {
      asks: [string, string][];
      bids: [string, string][];
    }
    
    export interface OrderBookResponse {
      order_book: OrderBook;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It discloses sorting order, currency meanings, and typed objects, but does not mention data freshness, rate limits, or authorization requirements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences plus an example, concise and front-loaded with the main purpose. Every sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description adequately explains return values (price, amount, sorting, typed). It includes an example query. Minor missing detail: does not explicitly state that limit is optional, but schema indicates that.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so description adds little beyond schema for parameter meaning. The example provides context for the limit parameter but no new semantic details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it returns the current order book for a Buda.com market with typed objects, sorted bids and asks, and includes an example query. This distinguishes it from sibling tools like get_ticker or get_market_summary.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The example query implies when to use the tool (e.g., asking for top buy/sell orders), and the description's focus on order book data differentiates it from other tools. However, there is no explicit statement about when not to use it or alternatives for related data.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gtorreal/buda-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server