Skip to main content
Glama
kea0811
by kea0811

ig_close_all_positions

Close all open trading positions in IG Trading accounts using the IG Trading MCP server, automating position management for forex, indices, and commodities.

Instructions

Close all open positions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main implementation of ig_close_all_positions: fetches all positions and closes them concurrently, returning successful and failed closures.
    async closeAllPositions() {
      try {
        const positions = await this.getPositions();
        
        if (positions.positions.length === 0) {
          logger.info('No positions to close');
          return [];
        }
    
        const closePromises = positions.positions.map(p => 
          this.closePosition(p.position.dealId)
        );
    
        const results = await Promise.allSettled(closePromises);
        
        const successful = results.filter(r => r.status === 'fulfilled').map(r => r.value);
        const failed = results.filter(r => r.status === 'rejected').map(r => r.reason);
        
        if (failed.length > 0) {
          logger.warn(`Failed to close ${failed.length} positions`);
        }
        
        return { successful, failed };
      } catch (error) {
        logger.error('Failed to close all positions:', error.message);
        throw error;
      }
    }
  • Input schema definition for the tool (no parameters required).
    {
      name: 'ig_close_all_positions',
      description: 'Close all open positions',
      inputSchema: {
        type: 'object',
        properties: {},
      },
    },
  • MCP server tool execution handler that dispatches to IGService.closeAllPositions() and formats the response.
    case 'ig_close_all_positions':
      const closeAllResult = await igService.closeAllPositions();
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(closeAllResult, null, 2),
          },
        ],
      };
  • Helper method to close a single position, used by closeAllPositions.
    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;
      }
    }
  • Helper method to fetch current open positions.
    async getPositions() {
      try {
        const response = await this.apiClient.get('/positions', 2);
        return response.data;
      } catch (error) {
        logger.error('Failed to get positions:', error.message);
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. 'Close all open positions' implies a destructive, irreversible action affecting multiple resources, but it doesn't specify whether this requires confirmation, what happens to pending orders, or if there are rate limits or authentication requirements. The description is minimal and misses critical behavioral details for a high-stakes operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words—'Close all open positions' directly conveys the core action. It is front-loaded and appropriately sized for a tool with no parameters, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a tool that performs a batch destructive operation with no annotations or output schema, the description is inadequate. It lacks details on return values, error conditions, side effects, or confirmation requirements. For a high-risk action like closing all positions, more context is needed to ensure safe and correct usage by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description correctly implies no required inputs, as closing all positions typically doesn't need parameters. This aligns well with the schema, earning a baseline score of 4 for parameter semantics in this context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Close') and target resource ('all open positions'), which is specific and unambiguous. It distinguishes from the sibling 'ig_close_position' by specifying 'all' positions rather than a single one. However, it doesn't explicitly mention the financial trading context implied by the 'ig_' prefix and sibling tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'ig_close_position' for individual positions or 'ig_update_position' for partial adjustments. It lacks context about prerequisites (e.g., needing open positions) or consequences, leaving the agent to infer usage from the name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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