get_positions
Retrieve all derivative positions from OKX trading accounts to monitor portfolio exposure and track trading performance.
Instructions
Get all derivative positions
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_positions"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/get_positions.ts:21-33 (handler)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) }], }; } } - src/tools/get_positions.ts:8-8 (schema)The input schema for the 'get_positions' tool, which is empty indicating no parameters are required.
export const schema = {}; - src/tools/get_positions.ts:10-19 (registration)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, }, }; - src/services/okxApiClient.ts:97-111 (helper)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; } }