Skip to main content
Glama
mbarinov

OKX MCP Server

by mbarinov

get_positions

Retrieve all derivative positions from OKX trading accounts to monitor portfolio exposure and track trading performance.

Instructions

Get all derivative positions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'get_positions' tool. It fetches positions from the OKX API client and returns them as formatted JSON, with error handling.
    export default async function get_positions({}: InferSchema<typeof schema>) { try { const positions = await okxApiClient.getPositions(); return { content: [{ type: 'text', text: JSON.stringify(positions, null, 2) }], }; } catch (error) { const message = error instanceof Error ? error.message : 'An unknown error occurred'; return { content: [{ type: 'text', text: JSON.stringify({ error: message }, null, 2) }], }; } }
  • The input schema for the 'get_positions' tool, which is empty indicating no parameters are required.
    export const schema = {};
  • Metadata for registering the 'get_positions' tool, including name, description, and annotations for UI hints.
    export const metadata = { name: 'get_positions', description: 'Get all derivative positions', annotations: { title: 'Get Positions', readOnlyHint: true, destructiveHint: false, idempotentHint: true, }, };
  • Helper method in OkxApiClient that retrieves positions from the OKX API and maps the response to a simplified format.
    async getPositions() { try { const response = await client.getPositions(); return response.map((position) => ({ symbol: position.instId, size: parseFloat(position.pos), entryPrice: parseFloat(position.avgPx), unrealizedPnl: parseFloat(position.upl), margin: parseFloat(position.margin), })); } catch (error) { console.error("Error fetching positions:", error); throw error; } }

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/mbarinov/okx-mcp'

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