# Closing a Position

When the exit condition is met (`EXIT_PRICE`), we need to close the position. More information on this can be found [here](/exchange-builder-documentation/frontend-builder-technical-guidance/instant-trading/closing-a-quote-instant-close.md).

#### Preparing the Close Request

Similar to opening a position, we need to fetch the price from Muon and apply slippage. For closing a long position, we apply negative slippage (0.99x the price):

```python
# Fetch Muon price and apply -1% slippage (for long positions)
muon_price = fetch_muon_price()
close_price = str(muon_price * Decimal("0.99"))  # 1% slippage for selling
```

#### Sending the Close Request

```python
payload = {
    "quote_id": quote_id,
    "quantity_to_close": CONFIG["QUANTITY"],
    "close_price": close_price
}

response = requests.post(f"{HEDGER_URL}/instant_close", json=payload, headers=headers)
```

#### Verifying the Close

After sending the close request, we check the response status to ensure the position was closed successfully:

```python
if response.status_code == 200:
    print("[CLOSE] Position closed successfully")
    return True
else:
    print(f"[CLOSE] Error: {response.status_code}, {response.text}")
    return False
```


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
