# Closing a Position On-Chain

## How to Request to Close a Position on SYMM if the Frontend Application is Unavailable

If you need to close your position or cancel a quote to unlock collateral but the frontend is unavailable, you can follow these steps to execute the operation manually using on-chain methods.

### Solution 1: Use the IPFS FE

Use the IPFS frontend to close the position (Website TBA)

### Solution 2: Manually Close with a Block Explorer

#### Step 1: Locate the Transaction When You Opened the Position

You need to find the `SendQuote` event log that was emitted when you initially opened your position. This log contains essential information such as the `partyA` address and the `quoteId`. You can obtain this information from a block explorer (like Etherscan) by searching for your account and looking for `_call()` transactions .

Here’s an example of what the `SendQuote` emitted event might look like:

<figure><img src="https://1257875949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYQhBmTCs9MwhhuPQrV5v%2Fuploads%2FSCCJ80GCpPPUnh2TXdSv%2Fimage.png?alt=media&#x26;token=9c82fb38-5642-4319-99dc-96885bfa95c8" alt=""><figcaption><p>sendQuote event</p></figcaption></figure>

#### Step 2: Find the `calldatas[]` for Closing the Position

You need the `calldata[]` to send to the diamond contract (in this case, the SYMMIO Clearing Engine) to request to close your position. Here's how you can do that:

1. **Find the Diamond Address**: From the `SendQuote` log (from Step 1), identify the address of the SYMMIO Clearing Engine It will look something like this:

   ```plaintext
   Address: 
   0x976c87cd3eb2de462db249cca711e4c89154537b
   (SYMMIO: Clearing Engine)
   ```
2. **Access Louper.dev**:
   * Go to [louper.dev](https://louper.dev).
   * Paste the diamond address and select the correct chain (e.g., Ethereum, BSC, etc.).
   * Connect the wallet you originally used to open the position.
3. **Request to Close the Position**:

   * Navigate to the **Write** tab in louper.dev.
   * Look for the function `requestToClosePosition` (or `requestToCancelQuote` if the quote was never responded to). Populate the fields using the data you extracted from the `SendQuote` log:

   <figure><img src="https://1257875949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYQhBmTCs9MwhhuPQrV5v%2Fuploads%2FjU7v3mN1dmYcdwgztcaD%2Fimage.png?alt=media&#x26;token=8eb1b597-7603-4345-ace7-ad43c3bea300" alt=""><figcaption><p>requestToClosePosition example</p></figcaption></figure>

<figure><img src="https://1257875949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYQhBmTCs9MwhhuPQrV5v%2Fuploads%2FRBXTiFUTFLYUUtqoLLub%2Fimage.png?alt=media&#x26;token=b4108118-46c3-4540-bff7-05d253108ef7" alt=""><figcaption><p>requestToCancelQuote() example</p></figcaption></figure>

Make sure you adjust the closing price to ensure it reflects current market price with some added slippage to ensure that the closing operation goes through. For longs the `closePrice` should be slightly less than the `marketPrice` and for shorts the `closePrice` should be slightly more than the `marketPrice`

Once you’ve populated the fields, click **Write** and wait for a wallet popup. Click the **View Raw** button to see the raw transaction data. This is where you’ll see the `calldata[]` generated. Copy this as a HEX string.

<figure><img src="https://1257875949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYQhBmTCs9MwhhuPQrV5v%2Fuploads%2F6NQjTMdqAdff6Kj7IhwA%2Fimage.png?alt=media&#x26;token=a421d621-ecd3-4470-b048-8d234c0feca1" alt=""><figcaption></figcaption></figure>

#### Step 3: Execute the `_call()` on the MultiAccount Contract

Now that you have the `calldata[]`, you can manually execute the closing request:

1. **Find the MultiAccount Contract**: This is the contract you used to open the position, the same one you checked the logs for to find the SendQuote event.
2. **Perform the `_call()`**:
   * Connect your trading wallet to the appropriate block explorer depending on the chain the trade was opened on (e.g., Etherscan or another compatible tool).
   * Perform a `_call()` by pasting the `calldata[]` and `partyA` address into the appropriate fields.

{% hint style="info" %}
The `partyA` is not the wallet you use but the sub-account address. You can find the `partyA` address in the details of the sendQuote event.
{% endhint %}

<figure><img src="https://1257875949-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYQhBmTCs9MwhhuPQrV5v%2Fuploads%2F17yTowK5TY0RJ2JSezD1%2Fimage.png?alt=media&#x26;token=69dbfbc5-0bb3-4c95-ace0-725beeca9855" alt=""><figcaption><p>Writing with a Block Explorer</p></figcaption></figure>

Submit the transaction on-chain to close the position by clicking **Write**. If everything was set up correctly, the position should be closed successfully.

{% hint style="info" %}
If you encounter an "is not a valid array" error, you must send the calldata as a hex string, enclosed in brackets and quotes e.g.

`["0xa63b936300000000000000000000000000000000000000000000000000000000000002ba"]`
{% endhint %}
