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

# Liquidate Loan

> Execute a liquidation on an undercollateralized loan

Triggers liquidation of an unhealthy loan. The oracle is updated automatically if stale. Depending on market configuration, this creates either an instant liquidation (collateral sent to the router) or a Dutch auction.

When `autoSell` is `true` (default), the orchestrator attempts to sell the seized collateral through the configured order book and settle proceeds back to the lending pool.

<Warning>
  This is a write operation. Requires `LIQUIDATOR_ROLE` granted to the registered wallet on the market contract.
</Warning>

## Path Parameters

<ParamField path="marketId" type="string" required>Market ID.</ParamField>
<ParamField path="loanId" type="integer" required>On-chain loan ID.</ParamField>

## Body Parameters

<ParamField body="autoSell" type="boolean" default="true">
  Whether to automatically route seized collateral through the order book.
</ParamField>

<ParamField body="txHash" type="string">
  Hash of the transaction you broadcast for this operation. Send it to confirm the transaction and record the result. Omit it to receive the calldata.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.trusset.org/lending-stocks/api/liquidations/{marketId}/liquidate/7" \
    -H "X-API-Key: trusset_your_key_here" \
    -H "Content-Type: application/json" \
    -d '{"autoSell": true}'
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "data": {
      "loanId": 7,
      "liquidationId": "4",
      "auctionId": null,
      "txHash": "0xabc...def",
      "collateralSeized": "50.000000000000000000",
      "debtRepaid": "4272.500000",
      "orchestratorResult": {
        "success": true,
        "status": "FULLY_SOLD",
        "tradesExecuted": 2
      },
      "orchestratorError": null
    }
  }
  ```

  ```json Error - Loan Still Healthy theme={null}
  {
    "success": false,
    "error": {
      "code": "LIQUIDATION_FAILED",
      "message": "execution reverted: LoanStillHealthy"
    }
  }
  ```
</ResponseExample>
