# 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.](https://cetus-1.gitbook.io/cetus-developer-docs/developer/via-sdk/features-available/remove-liquidity)
2. [Collect fees.](https://cetus-1.gitbook.io/cetus-developer-docs/developer/via-sdk/features-available/collect-fees)
3. [Collect rewards](https://cetus-1.gitbook.io/cetus-developer-docs/developer/via-sdk/features-available/collect-rewards) (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);
}
```
