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
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | No | Trading pair symbol, e.g. BTCUSDT | |
| symbols | No | Array of multiple trading pair symbols |
Implementation Reference
- src/index.ts:337-367 (handler)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 }; } } ); - src/index.ts:340-343 (schema)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") }, - src/index.ts:406-434 (helper)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 {}; }