> 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/exchange-builder-documentation/frontend-builder-technical-guidance/closing-a-quote.md).

# Closing a Quote

Closing a quote is how PartyA exits an open position. You send a close request specifying which portion of the position to close, at what price, and by when. As with sending a quote, you encode the `requestToClosePosition` call with the Symmio Core ABI and forward it through the AccountLayer's `_call`. For a wallet-free close signed by a session key, use the Instant Layer flow instead.

#### Function signature

```solidity
function requestToClosePosition(
    uint256 quoteId,
    uint256 closePrice,
    uint256 quantityToClose,
    OrderType orderType,
    uint256 deadline
) external;
```

### Parameter breakdown

#### `quoteId`

The unique identifier of the quote you want to close.

#### `closePrice`

For a **LIMIT** order, this is the exact price (in 18 decimals) at which you want to close the position.

For a **MARKET** order, the executed price includes the spread the solver charges, so you send a price adjusted from the current market price by a slippage buffer (e.g. 5%) to make sure the close is accepted. Adjust in the direction that guarantees the fill:

* Closing a LONG (a sell): decrease the market price by your slippage percentage.
* Closing a SHORT (a buy): increase the market price by your slippage percentage.

The adjustment accounts for the hedger's spread and helps ensure your close request is accepted.

#### `quantityToClose`

The amount of the position (in 18-decimal format) you want to close.

#### `orderType`

An enum value for the closing order type:

* `0` for LIMIT orders
* `1` for MARKET orders

#### `deadline`

A Unix timestamp by which the close request must be executed. If no action is taken by then, the request expires.

#### Parameter encoding

Encode the parameters for `requestToClosePosition()` with the Symmio Core ABI, then pass the calldata to the AccountLayer's `_call()` for the SubAccount that owns the position. On a non-CUSTOM SubAccount the AccountLayer routes the close to the VirtualAccount holding that `quoteId`; on a CUSTOM SubAccount it executes directly.

```javascript
// Prepare close position parameters
const nowInSeconds = Math.floor(Date.now() / 1000);
const deadlineInSeconds = nowInSeconds + deadline; // 'deadline' is a duration in seconds

const closePositionParameters = [
  quoteId.toString(), 
  closePrice.toString(), 
  quantityToClose.toString(), 
  orderType, 
  deadlineInSeconds.toString()
];

// Encode the function call using the Symmio Core ABI
const encodedClosePositionData = web3.eth.abi.encodeFunctionCall(
  requestToClosePositionFunctionAbi, // ABI definition for requestToClosePosition
  closePositionParameters
);

// Prepare call data for the AccountLayer's _call: [subAccount, [calldata]]
const _callData = [subAccountAddress, [encodedClosePositionData]];

// Estimate gas and send the transaction through the AccountLayer
const gasPrice = await web3.eth.getGasPrice();
const gasEstimate = await accountLayerContract.methods._call(..._callData).estimateGas({ from: process.env.WALLET_ADDRESS });
const gasEstimateBigInt = BigInt(gasEstimate);
const adjustedGasLimit = gasEstimateBigInt + (gasEstimateBigInt * BigInt(20) / BigInt(100)); // 20% buffer

const transactionReceipt = await accountLayerContract.methods._call(..._callData).send({
  from: process.env.WALLET_ADDRESS,
  gas: adjustedGasLimit.toString(),
  gasPrice: gasPrice.toString()
});

console.log("Transaction Receipt:", transactionReceipt);
```


---

# 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/exchange-builder-documentation/frontend-builder-technical-guidance/closing-a-quote.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.
