> ## 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.

# Withdraw Collateral

> Release excess collateral from an open loan

Removes collateral from a loan while leaving it open. The contract reverts if the withdrawal would push the health factor below `1.0`, so a loan can only shed collateral it does not need.

Single transaction in both modes.

## Path Parameters

<ParamField path="marketId" type="string" required>Market ID.</ParamField>

## Body Parameters

<ParamField body="loanId" type="integer" required>
  On-chain loan ID. Must be a positive integer sent as a JSON number.
</ParamField>

<ParamField body="amount" type="string" required>
  Security tokens to release, as a decimal string. Parsed at the collateral token's decimals.
</ParamField>

<ParamField body="signedPrice" type="object">
  EIP-712 signed price from [Sign Price](/endpoints/external-securities-lending/sign-price). Omit to price against the stored oracle value.

  <Expandable>
    <ParamField body="price" type="string">Price in base units.</ParamField>
    <ParamField body="timestamp" type="integer">Signing timestamp.</ParamField>
    <ParamField body="validUntil" type="integer">Signature expiry.</ParamField>
    <ParamField body="signature" type="string">EIP-712 signature.</ParamField>
  </Expandable>
</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>

## Response Fields

<ResponseField name="data" type="object">
  <Expandable>
    <ResponseField name="txHash" type="string">Transaction hash. Returned when confirming with `txHash`.</ResponseField>
    <ResponseField name="loanId" type="integer">Loan ID, echoed back. Returned when confirming with `txHash`.</ResponseField>
    <ResponseField name="amount" type="string">Collateral released, echoed back. Returned when confirming with `txHash`.</ResponseField>
    <ResponseField name="action" type="string">`SIGN_TRANSACTION` when `txHash` is omitted.</ResponseField>
    <ResponseField name="transaction" type="object">`{ to, data }` for the `withdrawCollateral` call. Returned when `txHash` is omitted.</ResponseField>
  </Expandable>
</ResponseField>

<Warning>
  This endpoint performs no preflight check. A withdrawal that would breach the health factor, exceed the posted collateral, or target an inactive loan reverts on-chain. Compute the safe amount from the loan's current state before submitting.
</Warning>

<Note>
  Where the released tokens end up depends on the market mode. `FREEZE` markets unfreeze them in place, so the borrower's balance does not change but the tokens become transferable again. `CUSTODY` markets transfer them out of the adapter back to the borrower.
</Note>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.trusset.org/lending-external-securities/api/positions/{marketId}/withdraw-collateral" \
    -H "X-API-Key: trusset_your_key_here" \
    -H "Content-Type: application/json" \
    -d '{"loanId": 5, "amount": "100"}'
  ```
</RequestExample>

<ResponseExample>
  ```json Calldata Response theme={null}
  {
    "success": true,
    "data": {
      "action": "SIGN_TRANSACTION",
      "transaction": { "to": "0x70A0...", "data": "0x..." },
      "functionName": "withdrawCollateral"
    }
  }
  ```

  ```json Confirmed Response theme={null}
  {
    "success": true,
    "data": {
      "txHash": "0xabc...def",
      "loanId": 5,
      "amount": "100"
    }
  }
  ```
</ResponseExample>
