Skip to main content
Glama

Close a position (reduce-only)

close_position
Destructive

Close all or part of a perpetual futures position with a reduce-only market order, so it can never open or flip a position. Use to take profit, cut a loss or reduce exposure; it is also the only way to undo a filled order. Third-party apps can close only positions they opened. Not for cancelling resting orders (use cancel_order). Inputs: symbol, venue, and close_fraction (1 = all) or size_base. Works while trading is halted. Next: get_my_positions.

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": {
      "symbol": "<symbol>"
    },
    "name": "close_position"
  }
}

Input Schema

NameRequiredDescriptionDefault
venueNoVenue: sandbox, hyperliquid, okx, bybit or binance. Omitted: the agent's only venue, else hyperliquid if connected, else your only connected exchange, else the sandbox
symbolYesBase coin, e.g. BTC
size_baseNoOr how much to close in the base coin, e.g. 0.01 BTC (at most what is held)
close_fractionNoShare of the position to close, a fraction: 0.5 = half, 1 = all of it

Output Schema

NameRequiredDescriptionDefault
okYesFalse when rejected or failed
feeNoOnce executed: the trading fee, estimated at once and replaced by the amount the exchange charged once its fill records show it
legsNoA ladder entry: per leg {price, size_base, order_id, sl_oid, status}; status resting, or after a refused leg withdrawn, filled or partly_filled
errorNoWhy it was rejected or failed
venueNoVenue name
checksNoChecks run at execution
sl_oidNoVenue order id of the protective stop
statusYespending_approval, armed (a trigger entry waiting for its price), executed, rejected, failed, expired, declined, cancelled, or executing (TradeHub has not confirmed the outcome yet: check get_order_status)
receiptNoSigned receipt (compact JWS, EdDSA) once executed: request, checks, preview price, fill, slippage, order ids, delegation. Verify with /.well-known/tradehub-receipts.jwks
order_idNoVenue order id of the fill
cancelledNocancel_order with all_waiting_entries: the order ids withdrawn (venue ids and req_… trigger entries); [] when nothing was waiting
fill_priceNoAverage fill, USD per coin
request_idYesOrder request id; get_order_status(request_id) follows it
deprecationNoPresent only while this tool is deprecated: replacement, removal_date, changelog
filled_sizeNoFilled size, in the base coin (e.g. BTC), not USD
take_profitsNoset_take_profits: the take-profits now on the exchange
trigger_priceNostatus armed: opens at market when the mark reaches this, USD per coin
trigger_expires_atNostatus armed: when it lapses unless reached, ISO 8601 UTC
approval_expires_atNoWhile pending: when the approval request lapses, ISO 8601 UTC

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changed
    • removedInput schema / properties / venue / default
      Removed value: -"hyperliquid"
  2. Added

TDQS

A4.6/5.0
Behavior4/5

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

Annotations already flag destructive=true, readOnly=false and non-idempotent, so the safety profile is largely covered. The description still adds real behavior beyond them: the reduce-only guarantee that prevents opening or flipping, the third-party restriction that apps can only close positions they opened, and availability during halts. Minor gaps remain on market-order slippage/price impact and partial-fill behavior.

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?

Content is front-loaded with purpose first, then use cases, exclusions, inputs and next step—every clause carries information. The prose is fairly dense and reads as a long run-on in places, which slightly hurts scanability but not correctness.

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

Completeness5/5

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

For a destructive, open-world trading mutation the description covers what it does, when to use it, the key safety invariant, permission scoping, availability during halts, input aliasing and a follow-up tool; venue defaults are fully documented in the schema and an output schema exists, so no return-value explanation is needed.

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 the baseline is 3, but the description adds the important alternative-or semantics ('close_fraction (1 = all) or size_base') that the schema does not state, since both properties are merely listed as optional. It also reiterates that fraction 1 closes everything, reinforcing the maximum constraint.

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 (close), resource (perpetual futures position) and mechanism (reduce-only market order), and immediately explains the scope limitation 'can never open or flip a position'. It also explicitly disambiguates from the nearest sibling: 'Not for cancelling resting orders (use cancel_order).' An agent can distinguish it from cancel_order and close_net_exposure 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 concrete positive triggers (take profit, cut a loss, reduce exposure, undo a filled order) and an explicit exclusion with a named alternative (cancel_order for resting orders). It even adds an applicability rule ('Works while trading is halted') and points to the next tool (get_my_positions), leaving little to inference.

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.

Resources