Skip to main content
Glama

ig_close_position

Close an open trading position by specifying the deal ID. Facilitates efficient position management within the IG Trading MCP server for forex, indices, and commodities.

Instructions

Close an open position

Input Schema

NameRequiredDescriptionDefault
dealIdYesDeal ID of the position to close

Input Schema (JSON Schema)

{ "properties": { "dealId": { "description": "Deal ID of the position to close", "type": "string" } }, "required": [ "dealId" ], "type": "object" }

Implementation Reference

  • Core implementation of closing a position: fetches current positions, constructs opposite market close ticket, sends DELETE request to IG API /positions/otc, retrieves confirmation if available.
    async closePosition(dealId) { try { const positions = await this.getPositions(); const position = positions.positions.find(p => p.position.dealId === dealId); if (!position) { throw new Error(`Position ${dealId} not found`); } const closeTicket = { dealId, direction: position.position.direction === 'BUY' ? 'SELL' : 'BUY', orderType: 'MARKET', size: position.position.size }; const response = await this.apiClient.delete('/positions/otc', closeTicket, 1); if (response.data.dealReference) { const confirmation = await this.getConfirmation(response.data.dealReference); return { position: response.data, confirmation }; } return response.data; } catch (error) { logger.error(`Failed to close position ${dealId}:`, error.message); throw error; } }
  • Tool schema definition including name, description, and input validation requiring dealId.
    { name: 'ig_close_position', description: 'Close an open position', inputSchema: { type: 'object', properties: { dealId: { type: 'string', description: 'Deal ID of the position to close', }, }, required: ['dealId'], }, },
  • MCP tool dispatch/registration: handles CallToolRequest for ig_close_position by invoking igService.closePosition and formatting JSON response.
    case 'ig_close_position': const closeResult = await igService.closePosition(args.dealId); return { content: [ { type: 'text', text: JSON.stringify(closeResult, null, 2), }, ], };

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/kea0811/ig-trading-mcp'

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