close_position
Closes an open trading position by symbol and side, returning confirmation when the position is closed.
Instructions
Close one open position, identified by symbol and side.
Maps to POST /api/positions?action=close_position -- action is a
query parameter, not a JSON body field (same pattern as cancel_order
above). A genuine spec correction: the spec names this tool's
parameter position_id, but OctoBot positions have no id concept at
all -- confirmed against source (Services/Interfaces/web_interface/ models/trading.py::_dump_position, the exact function behind
get_positions()'s response, builds each position dict with
symbol/side/contract/... keys but no id key, unlike
_dump_order's sibling function which does include "id": order.order_id). The real route calls interfaces_util.close_positions( [{"symbol": ..., "side": ...}]) -- packages/services/ octobot_services/interfaces/util/position.py -- which reads exactly
positions_desc["symbol"]/positions_desc["side"]. side is submitted
as OctoBot's own PositionSide enum's literal value ("long"/
"short"/"both"/"unknown", confirmed against
octobot_trading.enums.PositionSide) -- the exact same string
get_positions()'s own side field already uses, so a value read from
that response can be passed straight through as both symbol and
side here.
Success: OctoBot returns HTTP 200 with the literal JSON string
"Position closed", returned unchanged (NFR-8). Failure -- no matching
open position on any connected exchange -- raises
PositionCloseRejectedError with OctoBot's own extracted error text
(always, in practice, the literal "Impossible to close position: position already closed.").
Not confirm-gated: the user was explicitly asked about the spec's own
footnote flagging this tool as "revisitable" given its irreversible
effect, and chose to keep it ungated (milestone 13.6), per ADR-0003's
original reasoning that this is routine, expected trading-bot activity.
No confirm parameter exists on this tool at all.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| side | Yes | ||
| symbol | Yes |