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

# Repay Loan

> Repay debt on a loan (interest first, then principal)

Repays part or all of a loan's debt. Interest is paid first, then principal. Anyone can repay any loan. If the full debt is repaid, the loan closes automatically and collateral is returned.

## Path Parameters

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

## Body Parameters

<ParamField body="loanId" type="integer" required>On-chain loan ID.</ParamField>
<ParamField body="amount" type="string" required>USDC to repay (capped at total debt).</ParamField>

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

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