get_open_orders
Retrieve all open orders for any user wallet address on Hyperliquid prediction markets.
Instructions
Get open orders for a user address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | User wallet address |
Implementation Reference
- mcp-server.ts:199-218 (registration)Registration of the 'get_open_orders' tool with the MCP server, using server.tool() and providing the name, description, input schema, and handler.
// --- get_open_orders --- server.tool( 'get_open_orders', 'Get open orders for a user address', { address: z.string().describe('User wallet address') }, async ({ address }) => { const orders = await hlInfo<OpenOrder[]>({ type: 'openOrders', user: address }); const outcomeOrders = orders.filter(o => o.coin.startsWith('#')); if (outcomeOrders.length === 0) { return { content: [{ type: 'text', text: 'No open outcome orders.' }] }; } const lines = outcomeOrders.map(o => { return `${o.side.toUpperCase()} ${o.coin} ${o.sz} @ ${(parseFloat(o.limitPx) * 100).toFixed(1)}% (oid: ${o.oid})`; }); return { content: [{ type: 'text', text: lines.join('\n') }] }; }, ); - mcp-server.ts:203-203 (schema)Input schema for the 'get_open_orders' tool: requires a single 'address' string parameter (user wallet address).
{ address: z.string().describe('User wallet address') }, - mcp-server.ts:204-217 (handler)Handler function that fetches open orders for a user address via hlInfo, filters for outcome orders (coin starts with '#'), and returns formatted text with side, coin, size, price, and order ID.
async ({ address }) => { const orders = await hlInfo<OpenOrder[]>({ type: 'openOrders', user: address }); const outcomeOrders = orders.filter(o => o.coin.startsWith('#')); if (outcomeOrders.length === 0) { return { content: [{ type: 'text', text: 'No open outcome orders.' }] }; } const lines = outcomeOrders.map(o => { return `${o.side.toUpperCase()} ${o.coin} ${o.sz} @ ${(parseFloat(o.limitPx) * 100).toFixed(1)}% (oid: ${o.oid})`; }); return { content: [{ type: 'text', text: lines.join('\n') }] }; }, - mcp-server.ts:21-29 (helper)hlInfo generic helper function that makes HTTP POST requests to the Hyperliquid API /info endpoint, used by the handler to fetch open orders.
async function hlInfo<T>(body: object): Promise<T> { const res = await fetch(`${API_URL}/info`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body), }); if (!res.ok) throw new Error(`HL API error: ${res.status}`); return res.json() as Promise<T>; } - mcp-server.ts:52-55 (helper)TypeScript interface for OpenOrder, defining the shape of open order data returned by the API (coin, limitPx, oid, side, sz, timestamp).
interface OpenOrder { coin: string; limitPx: string; oid: number; side: string; sz: string; timestamp: number; }