> For the complete documentation index, see [llms.txt](https://docs.symm.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.symm.io/trader-documentation/building-a-trading-bot/part-2-trading/closing-a-position.md).

# Closing a position

Closing is one EIP-712 op. The trick is `signerAccount.addr`: for closes it's the **virtual account**, not the sub-account.

Why? Because as far as the Symmio core is concerned, it's that virtual address that holds the quote. The core looks up `quotes[quoteId].partyA` and checks that the caller (after the AccountLayer's signer-context forwarding) matches. That `partyA` is the VA. Sign as the sub-account and the core rejects the call with an authorization error that doesn't exactly say "wrong account"; it just fails.

### Compute close price

Slippage runs in the *opposite direction* to opens: when you close a long, you're selling, so you accept a *lower* price; when you close a short, you're buying back, so you accept a *higher* price.

| Side closing | Worst-acceptable close price          |
| ------------ | ------------------------------------- |
| CLOSE LONG   | `price = mark × (1 − slippage / 100)` |
| CLOSE SHORT  | `price = mark × (1 + slippage / 100)` |

Quantize to `price_precision` and convert to wei.

### Sign one `SignedOperation`

The envelope is the same `SignedOperation` struct as for opens, the domain is the same `SymmioInstantLayer`, and the signer is the same session key. The fields that differ:

* `target`: Symmio Core (same as `sendQuote`)
* `signerAccount.addr`: **virtual account**
* `callData`: selector `0x501e891f` followed by ABI-encoded `(quoteId: uint256, closePrice: uint256, quantityToClose: uint256, orderType: uint8, deadline: uint256)`. `orderType = 1` for MARKET.

### POST as a JSON array

```
POST <instant-close endpoint>
Content-Type: application/json

[
  {
    "signedOperation": { ... },
    "signature": "0x..."
  }
]
```

Note the array. **Open is a JSON object, close is a JSON array**. Mixing them up may cause failures on the server side.

The solver responds with `200 null` when the close is queued. The notifications WS will show `FillCloseRequest` once it fills on-chain.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.symm.io/trader-documentation/building-a-trading-bot/part-2-trading/closing-a-position.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
