Skip to main content
Glama
jianchundev

Binance Cryptocurrency MCP

by jianchundev

get_book_ticker

Retrieve real-time best bid/ask prices and quantities for Binance cryptocurrency trading pairs to monitor market liquidity and execute trades.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolNoTrading pair symbol, e.g. BTCUSDT
symbolsNoArray of multiple trading pair symbols

Implementation Reference

  • Complete registration and handler implementation of get_book_ticker tool. This block contains the server.tool() call that registers the tool, including its schema definition (lines 340-343) and the async handler function (lines 344-366) that makes a GET request to Binance's /api/v3/ticker/bookTicker endpoint.
    // Order Book Ticker
    server.tool(
        "get_book_ticker",
        {
            symbol: z.string().optional().describe("Trading pair symbol, e.g. BTCUSDT"),
            symbols: z.array(z.string()).optional().describe("Array of multiple trading pair symbols")
        },
        async (args: { symbol?: string; symbols?: string[] }) => {
            try {
                let params = {};
                if (args.symbol) {
                    params = { symbol: args.symbol };
                } else if (args.symbols) {
                    params = { symbols: JSON.stringify(args.symbols) };
                }
    
                const response = await axios.get(`${BASE_URL}/api/v3/ticker/bookTicker`, {
                    params,
                    ...getProxyConfig(),
                });
                return {
                    content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }]
                };
            } catch (error: any) {
                return {
                    content: [{ type: "text", text: `Failed to get order book ticker: ${error.message}` }],
                    isError: true
                };
            }
        }
    );
  • Input validation schema for get_book_ticker tool using zod. Defines two optional parameters: 'symbol' for a single trading pair, or 'symbols' for an array of multiple trading pairs.
    {
        symbol: z.string().optional().describe("Trading pair symbol, e.g. BTCUSDT"),
        symbols: z.array(z.string()).optional().describe("Array of multiple trading pair symbols")
    },
  • Helper function getProxyConfig() that provides proxy configuration for HTTP requests. Supports both SOCKS5 proxy (preferred) and HTTP proxy fallback. This utility is used by get_book_ticker and other tools in the registerTools function.
    function getProxyConfig(): any {
        // 优先使用SOCKS5代理
        if (socksProxyURL) {
            try {
                const agent = new SocksProxyAgent(socksProxyURL);
                return { httpsAgent: agent, httpAgent: agent };
            } catch (error) {
                console.error(`Failed to create SOCKS proxy agent: ${error}`);
            }
        }
        
        // 回退到HTTP代理
        if (httpProxyURL) {
            try {
                const urlInfo = new URL(httpProxyURL);
                return {
                    proxy: {
                        host: urlInfo.hostname,
                        port: parseInt(urlInfo.port) || (urlInfo.protocol === 'https:' ? 443 : 80),
                        protocol: urlInfo.protocol.replace(":", "")
                    }
                };
            } catch (error) {
                console.error(`Failed to parse HTTP proxy URL: ${error}`);
            }
        }
        
        return {};
    }

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/jianchundev/binance-mcp'

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