# Remove Liquidity Overview

Understand how to withdraw liquidity from DLMM positions, collect accumulated fees, and manage partial or complete exits from pools.

### What is Removing Liquidity?

In DLMM, removing liquidity means:

* Withdrawing tokens from specific bins
* Collecting accumulated trading fees
* Reducing or closing your position
* Receiving tokens based on current bin reserves

### Core Concepts

#### Partial vs Complete Removal

* **Partial**: Remove from selected bins only
* **Complete**: Withdraw all liquidity and fees
* **Close Position**: Complete removal + burn NFT

#### Token Returns

You receive tokens based on:

* Your share of each bin's reserves
* Accumulated fees in those bins
* Current price (may differ from entry)

#### Fee Collection

* Fees are automatically included in removal
* No separate claim transaction needed
* Proportional to your liquidity share

### The Workflow

#### 1. Check Position Status

```typescript
const bins = await sdk.Position.getPositionBins(pair, positionId);
const amounts = await sdk.Position.getPositionBinsAmount(pair, positionId);
```

#### 2. Calculate Expected Output

Preview what you'll receive:

```typescript
// Check each bin's value
amounts.forEach(bin => {
  console.log(`Bin ${bin.id}: ${bin.amountX} X, ${bin.amountY} Y`);
});
```

#### 3. Execute Removal

Two main options:

* Remove from specific bins
* Remove all and close position

### Removal Strategies

#### Range Exit

Remove liquidity outside active range:

```
Before: ████ ████ ████ ████ ████
After:  ████ ████ [active] 
        (removed)         (removed)
```

#### Profit Taking

Remove from bins with accumulated fees:

```
Fees:   Low  Low  HIGH  Low  Low
Action: Keep Keep REMOVE Keep Keep
```

#### Rebalancing

Remove and re-add with new distribution:

1. Remove from current bins
2. Calculate new optimal range
3. Add with updated strategy

### What You Receive

For each bin removed:

```
Your tokens = (Your liquidity / Total liquidity) × (Reserves + Fees)
```

Example:

* Your liquidity: 1000
* Total in bin: 10000
* Bin reserves: 50000 X, 100000 Y
* Your share: 10% of everything

### Important Considerations

#### Price Impact

* Current price may differ from entry
* Can result in more of one token
* This is impermanent loss realized

#### Gas Optimization

* Removing many bins costs more gas
* Consider batching operations
* Complete removal is gas-efficient

#### Timing

* No lock periods in DLMM
* Remove anytime markets are open
* Consider fee accumulation rates

### Common Patterns

#### Emergency Exit

```typescript
// Quick complete withdrawal
await sdk.Pair.removeAndClosePosition(pair, positionId);
```

#### Selective Removal

```typescript
// Remove only profitable bins
const profitableBins = bins.filter(b => b.fees > threshold);
await sdk.Pair.removeLiquidity(pair, {
  positionId,
  binIds: profitableBins.map(b => b.id)
});
```

#### Fee Harvesting

```typescript
// Remove and re-add to collect fees
// 1. Remove all
// 2. Add back immediately
```

### Next Steps

Choose your removal approach:

1. **Partial Removal**: [Remove from Specific Bins](https://docs.ferra.ag/integration/dlmm/typescript-sdk/remove-liquidity/remove-from-specific-bins)
2. **Complete Exit**: [Remove All Liquidity](https://docs.ferra.ag/integration/dlmm/typescript-sdk/remove-liquidity/remove-all-liquidity)
3. **Preview First**: [Calculate Output Amounts](https://docs.ferra.ag/integration/dlmm/typescript-sdk/remove-liquidity/calculate-output-amounts)

### Related Topics

* [Position Management](https://docs.ferra.ag/integration/dlmm/typescript-sdk/position-management) - Check bins
* [Close Position](https://docs.ferra.ag/integration/dlmm/typescript-sdk/position-management/close-position) - Remove and burn
* [Calculate Position Fees](https://docs.ferra.ag/integration/dlmm/typescript-sdk/fees-and-analytics/calculate-position-fees) - Track earnings
