> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebelfi.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Unwind

> POST /v1/operations/unwind — Plan an unwind operation

<Note>
  **Endpoint:** `POST https://api.rebelfi.io/v1/operations/unwind`
</Note>

Plan an unwind operation to withdraw funds from a yield strategy.

### Request Body

Provide one wallet identifier:

| Field            | Type      | Required | Description                                                                                                                    |
| ---------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `walletAddress`  | `string`  | One of   | Wallet address                                                                                                                 |
| `walletId`       | `number`  | One of   | Wallet ID from registration                                                                                                    |
| `strategyId`     | `number`  | Yes      | Strategy ID to unwind from                                                                                                     |
| `amount`         | `string`  | One of   | Amount to unwind in base units. Required unless `fullWithdrawal` is `true`.                                                    |
| `fullWithdrawal` | `boolean` | One of   | If `true`, withdraws the full position using the protocol's native max-withdrawal mechanism. Cannot be combined with `amount`. |

### Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.rebelfi.io/v1/operations/unwind" \
    -H "x-api-key: your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "walletId": 42,
      "strategyId": 1,
      "amount": "500000000"
    }'
  ```

  ```bash cURL (full withdrawal) theme={null}
  curl -X POST "https://api.rebelfi.io/v1/operations/unwind" \
    -H "x-api-key: your_api_key" \
    -H "Content-Type: application/json" \
    -d '{
      "walletId": 42,
      "strategyId": 1,
      "fullWithdrawal": true
    }'
  ```

  ```typescript SDK theme={null}
  const operation = await client.operations.unwind({
    walletId: 42,
    strategyId: 1,
    amount: '500000000'
  });
  ```

  ```typescript SDK (full withdrawal) theme={null}
  const operation = await client.operations.unwind({
    walletId: 42,
    strategyId: 1,
    fullWithdrawal: true
  });
  ```
</CodeGroup>

### Example Response

```json theme={null}
{
  "operationId": 124,
  "type": "unwind",
  "status": "awaiting_signature",
  "transactions": [
    {
      "id": 457,
      "blockchain": "solana",
      "status": "unsigned",
      "unsignedTransaction": "AQAAAA...base64...",
      "description": "Unwind 500 USDC from Kamino"
    }
  ],
  "expiresAt": "2024-01-15T10:35:00Z"
}
```

### Errors

| Code                    | Description                                              |
| ----------------------- | -------------------------------------------------------- |
| `INVALID_AMOUNT`        | Amount is zero, negative, or malformed                   |
| `ALLOCATION_NOT_FOUND`  | No position exists at this strategy                      |
| `INSUFFICIENT_BALANCE`  | Amount exceeds allocation                                |
| `STRATEGY_NOT_FOUND`    | Strategy ID doesn't exist                                |
| `INSUFFICIENT_GAS`      | Not enough SOL for transaction fee                       |
| `OPERATION_IN_PROGRESS` | Another operation is currently executing for this wallet |
| `WALLET_NOT_FOUND`      | Wallet ID doesn't exist                                  |
