# Close position

## Complete closing position process

When closing a position, if the position is not empty and still contains liquidity, fees, or rewards, an error code 0 will be thrown by the position module. To successfully close the position, follow these steps:

1. [Remove liquidity.](/cetus-developer-docs/developer/via-sdk/features-available/remove-liquidity.md)
2. [Collect fees.](/cetus-developer-docs/developer/via-sdk/features-available/collect-fees.md)
3. [Collect rewards](/cetus-developer-docs/developer/via-sdk/features-available/collect-rewards.md) (if applicable).
4. Close the position.

## Function

clmmpool/sources/pool.move

```rust
/// Close a position by burning the corresponding NFT.
///
/// # Arguments
///
/// _ config - A reference to the GlobalConfig object.
/// _ pool - A mutable reference to the Pool object.
/// _ position_nft - The Position NFT to burn and close the corresponding position.
///
/// # Generic Type Parameters
///
/// _ CoinTypeA - The type of the first coin in the pool.
/// \* CoinTypeB - The type of the second coin in the pool.
///
/// # Returns
///
/// This function does not return a value.

public fun close_position<CoinTypeA, CoinTypeB>(
    config: &GlobalConfig,
    pool: &mut Pool<CoinTypeA, CoinTypeB>,
    position_nft: Position,
) {}
```

## Example

```rust
public entry fun close_position<CoinTypeA, CoinTypeB>(
    config: &GlobalConfig,
    pool: &mut Pool<CoinTypeA, CoinTypeB>,
    position_nft: Position,
    min_amount_a: u64,
    min_amount_b: u64,
    clock: &Clock,
    ctx: &mut TxContext
) {
    let all_liquidity = position::liquidity(&mut position_nft);
    if (all_liquidity > 0) {
        remove_liquidity(
            config,
            pool,
            &mut position_nft,
            all_liquidity,
            min_amount_a,
            min_amount_b,
            clock,
            ctx
        );
    };
    pool::close_position<CoinTypeA, CoinTypeB>(config, pool, position_nft);
}
```


---

# 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://cetus-1.gitbook.io/cetus-developer-docs/developer/via-clmm-contract/features-available/close-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.
