Skip to main content
Glama

AlgoVesta MCP Trading

close_position

DestructiveIdempotent

Closes an open position fully or partially (fraction (0,1]). Works for crypto and FOREX/MT5. This is a RISK-REDUCING operation: the policy wall NEVER blocks this tool (except the kill switch). idempotency_key is REQUIRED: even 10 calls with the same key perform ONE close. If no position exists, POSITION_NOT_FOUND is returned together with the open positions on that venue.

MT5 positions can only be closed IN FULL (no partial close) -> use fraction=1. If several
MT5 positions are open on the same symbol, `ticket` becomes REQUIRED; while it is
ambiguous, none are closed.

get_portfolio_context shows the open positions (and MT5 tickets).

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "venue": "<venue>",
      "symbol": "<symbol>",
      "side": "<side>",
      "idempotency_key": "<idempotency_key>"
    },
    "name": "close_position"
  }
}

Input Schema

NameRequiredDescriptionDefault
sideYes'buy' (long) or 'sell' (short). The side the user stated.
venueYesExchange/venue name — must be one of the user's CONNECTED accounts (e.g. binance, bybit, okx, mt5, paper). A venue that is not connected is rejected with VENUE_NOT_CONNECTED.
symbolYesTrading symbol, e.g. BTCUSDT, ETHUSDT, EURUSD.
ticketNoFOREX/MT5 only: the ticket number of the position this action targets (the 'ticket' field on forex positions in get_portfolio_context). REQUIRED when several positions are open on the same symbol — if which one is meant is not certain, nothing is done. May be left empty when there is only one position.
accountNoTARGET ACCOUNT — the account this call acts on (for place_order/simulate_order the account the order is opened in; for close/modify the account holding the position). For MT5 the login number (e.g. '12345678'), for exchanges the account label (e.g. 'Binance2'). Copy it EXACTLY from the 'account' field in the get_portfolio_context output. REQUIRED when the user has more than one account in the same market: if left empty the action is NOT performed and the user is asked which account — it is never silently applied to the default/primary account.
fractionNoClose fraction (0,1]. 1.0 = full close, 0.5 = half. MT5 positions can only be closed in full — use 1.0 there; a partial close on MT5 is refused rather than silently converted to a full close.
idempotency_keyYesClient-generated unique idempotency key (min 8 characters). Reuse the SAME key when retrying the same action — the stored response is replayed and the action is NOT performed a second time.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.7/5.0
Behavior5/5

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

Annotations already declare destructive=true, idempotent=true and openWorld=true, and the description adds context those hints cannot express: the policy wall never blocks this risk-reducing tool except the kill switch, the same idempotency key collapses repeated calls into one close, and N POSITION_NOT_FOUND returns the venue's open positions. It also discloses that an ambiguous MT5 ticket results in no action rather than a default guess, which is exactly the kind of failure-mode detail an agent needs.

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

Conciseness4/5

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

Front-loaded with the action and fraction range, then the risk/policy note, then per-venue caveats; each paragraph has a distinct job. A few clauses restate schema facts (the fraction range, ticket requirement) and could be trimmed without loss.

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

Completeness4/5

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

For a seven-parameter mutation with no output schema, the description covers the critical cases: idempotent retry behavior, the not-found path with open positions returned, and the MT5 ambiguity refusal. Only the success response shape is left implicit, which is acceptable given the idempotency-replay explanation.

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?

Schema coverage is 100%, so baseline is 3; the description goes beyond it by tying fraction to the MT5 full-close restriction (refused, not silently converted) and by stating the ticket condition for disambiguation, both of which are operational semantics rather than restatements. It does not add anything for account or side beyond what the schema already carries.

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

Purpose5/5

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

States a specific verb and resource ('Closes an open position') plus scope ('fully or partially (fraction (0,1])'), which makes it unmistakable against siblings like modify_position or cancel_order. An agent can decide between this and the modify path without opening any schema.

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

Usage Guidelines5/5

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

Gives explicit conditional routing: MT5 must use fraction=1 with no partial close, and when several MT5 positions share a symbol the ticket becomes REQUIRED with nothing closed while ambiguous. It also names get_portfolio_context as the discovery step for positions and tickets, so both the precondition and the alternative are spelled out.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.