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

# Borrow & lend

> Borrow and lend USDC for a fixed term on OCX's yield-quoted books: tenors, rates, interest, settlement, limits, and the endpoints

OCX runs order books for **USDC loans**. A bid is an offer to **borrow**, an ask is an offer to **lend**, and a fill opens a fixed-term loan between the two accounts. Rates are quoted as an annual yield; the loan settles at its maturity, when the borrower pays back principal plus interest.

Every endpoint is served through the gateway at `https://api.ocx.global`. `GET /funding/book` is **Public**; every other endpoint here needs a signed-in session (cookie or `Authorization: Bearer`) — see [Authentication](https://docs.ocx.global/get-started/authentication.md). The API paths use the name *funding*; this has nothing to do with futures funding payments, which OCX does not have.

> [!NOTE]
>
> Enums: `side` = `borrow | lend`; `timeInForce` = `gtc | ioc` (default `gtc`; `fok` is accepted and treated as `ioc`). Rates are `rateBps`: annual yield in basis points, 0 to 100,000, to 0.1 bp — `1625` is 16.25% a year. Sizes are USDC decimal strings, rounded to the cent.

## Books and tenors

There is one book per tenor. A loan matures at the daily settlement time on the first day that is at least its term away from the fill.

| Tenor | Term | Who quotes |
| - | - | - |
| `23h` | At least 1 hour: the next daily settlement more than an hour away | **OCX only.** You can borrow from OCX's offers or lend back into OCX's bids, `ioc` only; client orders cannot rest here (`BOOK_TAKE_ONLY`). |
| `1w` | 7 days | Clients, and OCX when it posts |
| `2w` | 14 days | Clients, and OCX when it posts |
| `1m` | 30 days | Clients, and OCX when it posts |
| `3m` | 90 days | Clients, and OCX when it posts |
| `6m` | 180 days | Clients, and OCX when it posts |
| `1y` | 365 days | Clients, and OCX when it posts |

For every tenor except `23h` the term is counted less one hour before the next settlement is taken, so a `1w` loan filled at 21:00 UTC matures at the settlement seven days later, not eight. Each fill reports its exact `maturesAt`. OCX's own levels carry `venue: true` in the book. Where OCX has lent on a book, it also bids for that money back, below the rate it lent at, so a borrower can close early by lending into those bids.

## Matching

* A borrow takes offers at or below its `rateBps`; a lend hits bids at or above its `rateBps`. Best rate first, then time.
* A fill is priced at the **resting** order's rate.
* Your own orders never match each other. A `gtc` order that would cross your own resting order on the same book is refused (`SELF_CROSS`); an `ioc` order is not.
* `gtc` rests whatever does not fill; `ioc` cancels it.

## Interest and fees

Interest is simple, on the principal, at the loan's rate, for the loan's exact term in seconds over a 365-day year, rounded to the cent. The borrower pays the **full term's** interest, including when it repays early through `POST /funding/repay`. The one exception is a loan recalled because its lender was liquidated: the borrower then pays interest to the recall.

```text theme={null}
interest = principal × rateBps / 10,000 × termSeconds / 31,536,000
100,000 at 1,625 bps for 6 h 15 min = 11.59
```

Three fees apply. `GET /funding/book` returns the live values.

| Field | Paid by | Charged |
| - | - | - |
| `fillFeeBps` | Borrower | At the fill, on the principal, out of the cash you receive. |
| `unwindFeeBps` | A borrower lending back | At the fill, on the part of a lend that offsets your own borrowing on the same book. |
| `feeBps` | Lender | At settlement, as a share of the interest. |

## How the cash moves

All funding cash moves through your `options` bucket. See [Balances & transfers](https://docs.ocx.global/concepts/balances.md).

**1. Post a lend**

The full size leaves `options` when you post (`lend_reserve`), so a resting offer is cash you really have. If `options` is short, the gateway tops it up from your other buckets and retries once, as it does for orders. Cancelling, or an `ioc` remainder, returns it (`lend_release`).

**2. Fill**

The borrower receives the principal in `options` (`lend_borrow`), less the fill fee (`lend_fee`).

**3. Warning**

At `warnUtc` each day, a borrower whose loans mature at the next settlement and who would then be short of margin has those loans flagged: `warning` in `GET /funding/me`.

**4. Settlement**

At `settleUtc` (currently 20:15 UTC) every matured loan settles. The borrower's `options` bucket pays principal (`lend_repay`) and interest (`lend_interest`), even if that takes it below zero; the borrower's resting lend offers are cancelled first if needed to cover it. The lender receives principal (`lend_return`) and interest less `feeBps` (`lend_yield`).

These entries appear in `GET /wallet/history`, with the order or loan id in `txHash`. A `lend_lend` entry records a lend filling; its cash already left at `lend_reserve`.

> [!NOTE]
>
> `blackout` in the book describes an optional daily window around settlement in which new `23h` orders are refused (`BOOK_CLOSED`). It is currently disabled; `closed` is `true` while a book is inside it.

## Limits

> **Borrow capacity**
>
> A multiple (`maxLeverage`) of your own NLV, less what you already owe net on each book, less your resting borrow bids. `GET /funding/me` returns it as `capacity`. A resting bid is checked again when it fills: it is cut back to your capacity at that moment, or cancelled.

> **Lend limit**
>
> You can lend only free equity: NLV not already lent or offered, less the initial margin your positions and working orders need. Borrowed cash and sold premium cannot be lent. Lending back what you owe on the same book is exempt.

While you owe on the books, a withdrawal must leave at least the principal you owe × (1 + 1/`maxLeverage`) across your buckets; the rejection states the most you can withdraw. See [Withdraw](https://docs.ocx.global/concepts/balances.md#withdraw).

## Borrowing, margin, and liquidation

* **Borrowed cash is collateral.** It sits in `options`, so during the day your requirement is measured against NLV plus what you borrowed. NLV itself does not rise: the loan is netted.
* **Overnight, only longer loans count.** At the daily cutoff, borrowing that runs past the next settlement still carries your positions; borrowing due at the next settlement does not. Money you have lent that is not back by the next settlement does not count either.
* **Loan floor.** While you owe on the books, your account is liquidated if its NLV falls to `liquidationFloorPct` of the equity it had when your oldest open loan was taken. `GET /funding/me` shows the level as `liquidation.floorEquity`.
* **Liquidation settles your loans.** Your resting funding orders are cancelled, and once your positions are closed every loan you borrowed is settled with its full-term interest. Loans you made to other clients are recalled: the borrower repays now, with interest to date.

If you borrowed from a client who is liquidated, your loan can therefore be recalled before maturity. See [Margin & liquidations](https://docs.ocx.global/concepts/margin.md#borrowing-and-margin).

## Endpoints

### Book

`GET /funding/book?tenor=23h` — **Public.** One book, aggregated by rate. `tenor` defaults to `23h`.

**tenor** `string`

**asks / bids** `array`

Offers to lend (lowest rate first) and bids to borrow (highest first).

**level**

**rateBps** `number`

Annual yield, bps.

**size** `string`

USDC resting at that rate.

**orders** `number`

Orders at that rate.

**venue** `boolean`

`true` when the level includes OCX's own quotes.

**enabled / closed** `boolean`

Whether the books are open, and whether this book is inside its blackout window now.

**fillFeeBps / unwindFeeBps / feeBps** `number`

The fees described in [Interest and fees](#interest-and-fees).

**minSize** `string`

Smallest order the books accept, USDC.

**settleUtc / warnUtc / nextSettleAt** `string`

Daily settlement and warning times (UTC), and the next settlement.

**liquidationFloorPct** `string`

The loan floor, as a share of equity at your first open loan.

**venueBidSpreadBps** `number`

How OCX's exit bids step: each further clip bids this many bps lower, starting below the rate OCX lent at.

**exitClip** `string`

Size of each clip of OCX's exit bids, USDC.

**blackout** `object`

`{ enabled, fromUtc, toUtc }`.

```bash cURL theme={null}
curl -s "https://api.ocx.global/funding/book?tenor=23h"
```

```js JavaScript theme={null}
const book = await fetch("https://api.ocx.global/funding/book?tenor=23h").then(r => r.json());
```

```json Response theme={null}
{
  "tenor": "23h",
  "asks": [
    { "rateBps": 1625, "size": "1000000", "orders": 1, "venue": true },
    { "rateBps": 1684, "size": "1000000", "orders": 1, "venue": true },
    { "rateBps": 1743, "size": "1000000", "orders": 1, "venue": true }
  ],
  "bids": [],
  "enabled": true,
  "closed": false,
  "feeBps": 0,
  "fillFeeBps": 1,
  "unwindFeeBps": 0.5,
  "minSize": "100",
  "liquidationFloorPct": "0.3",
  "venueBidSpreadBps": 10,
  "exitClip": "100000",
  "settleUtc": "20:15",
  "warnUtc": "19:45",
  "nextSettleAt": "2026-10-28T20:15:00Z",
  "blackout": { "enabled": false, "fromUtc": "09:00", "toUtc": "09:35" },
  "asOf": "2026-10-28T17:46:21Z"
}
```

### Your account

`GET /funding/me` — **Session.** Your open orders, open loans in both directions, interest to date, and limits.

**capacity / maxLeverage / ownCash** `string`

What you can still borrow now, the leverage behind it, and your own NLV (net of loans) it is measured on.

**cash** `string`

What your buckets hold, borrowed cash included.

**borrowed / lent** `string`

Open principal, gross.

**netBorrowed / netLent / closedByLending** `string`

The same netted per book: lending back on a book offsets borrowing on that book.

**interestPayable / interestReceivable** `string`

Interest accrued to now; the receivable is net of `feeBps`.

**reservedInOrders / heldForOrders** `string`

Cash in your resting lend offers, and cash your working option orders hold.

**liquidation** `object | null`

`{ floorPct, equityAtGrant, floorEquity }` while you owe; `null` otherwise.

**orders** `array`

Open orders: `{ id, tenor, side, rateBps, size, remaining, status, createdAt }`.

**loans** `array`

Open loans, soonest maturity first: `{ id, tenor, role, principal, rateBps, feeBps, accruedInterest, openedAt, maturesAt, warnedAt }`. `role` is `borrower` or `lender`.

**warning** `object | null`

`{ maturesAt, warnedAt }` when loans you borrowed are flagged ahead of settlement.

```json Response theme={null}
{
  "enabled": true,
  "capacity": "149950",
  "maxLeverage": "5",
  "ownCash": "49990",
  "cash": "149990",
  "borrowed": "100000",
  "lent": "0",
  "netBorrowed": "100000",
  "netLent": "0",
  "closedByLending": "0",
  "interestPayable": "3.71",
  "interestReceivable": "0",
  "reservedInOrders": "0",
  "heldForOrders": "0",
  "liquidation": { "floorPct": "0.3", "equityAtGrant": "50000", "floorEquity": "15000" },
  "liquidationFloorPct": "0.3",
  "orders": [],
  "loans": [
    { "id": "…", "tenor": "23h", "role": "borrower", "principal": "100000", "rateBps": 1625,
      "feeBps": 0, "accruedInterest": "3.71", "openedAt": "2026-10-28T14:00:00Z",
      "maturesAt": "2026-10-28T20:15:00Z", "warnedAt": null }
  ],
  "warning": null,
  "nextSettleAt": "2026-10-28T20:15:00Z",
  "asOf": "2026-10-28T16:00:00Z"
}
```

### Place an order

`POST /funding/orders` — **Session.**

**tenor** `string` *required*

`23h | 1w | 2w | 1m | 3m | 6m | 1y`

**side** `string` *required*

`borrow` (bid) | `lend` (ask)

**rateBps** `number | string` *required*

Annual yield in bps, to 0.1. For a borrow, the most you will pay; for a lend, the least you will accept.

**size** `string` *required*

USDC, at least `minSize`.

**timeInForce** `string`

`gtc` (default) | `ioc`. Must be `ioc` on `23h`.

Returns `{ orderId, tenor, side, rateBps, size, remaining, status, fills }`. `status` is `filled`, `open` (resting), or `cancelled` (an `ioc` remainder). Each fill is `{ loanId, rateBps, size, maturesAt, counterpartyOrderId }`.

```bash cURL theme={null}
curl -s -X POST "https://api.ocx.global/funding/orders" \
  -H "Authorization: Bearer $OCX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "tenor": "23h", "side": "borrow", "rateBps": 1625, "size": "100000", "timeInForce": "ioc" }'
```

```js JavaScript theme={null}
await fetch("https://api.ocx.global/funding/orders", {
  method: "POST",
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
  body: JSON.stringify({ tenor: "1w", side: "lend", rateBps: 950.5, size: "25000" }),
});
```

```json Response theme={null}
{
  "orderId": "…", "tenor": "23h", "side": "borrow", "rateBps": 1625,
  "size": "100000", "remaining": "0", "status": "filled",
  "fills": [
    { "loanId": "…", "rateBps": 1625, "size": "100000",
      "maturesAt": "2026-10-28T20:15:00Z", "counterpartyOrderId": "…" }
  ]
}
```

### Amend, cancel, and repay

| Endpoint | Description |
| - | - |
| `POST /funding/orders/{id}/amend` | **Session.** Body `{ rateBps?, size? }`, at least one. Cancels and re-places the resting order in one step under a new `orderId` (returned with `replacedOrderId`), so it loses time priority. A new rate that crosses the book fills at once. If the new order is refused, the old one stays. |
| `POST /funding/orders/{id}/cancel` | **Session.** Returns `{ orderId, status: "cancelled", released }`; `released` is the lend cash returned. `404` if no open order has that id. |
| `POST /funding/repay` | **Session.** Settles everything you borrowed **from OCX** now, exactly as at maturity: full-term interest, same fees. What you lent OCX on the same book settles with it, as far as it offsets that borrowing. Loans with another client on the other side run to maturity. |

`POST /funding/repay` takes no body and returns `{ settled, netPaid, keptOpen }`. `settled` lists each loan settled (`loanId`, `principal`, `interest`, `fee`, and both account ids); `netPaid` is what left your account (negative when you received); `keptOpen` lists lends to OCX left to run, as `{ loanId, principal }`. Repayment is paid from your `options` bucket only — move cash there first if it is short — and is refused if what remains would not cover your margin.

## Borrow and place

An opening single-leg option order can borrow what it is short in the same request. Add `borrow` to `POST /orders`:

**borrow** `object`

**properties**

**tenor** `string` *required*

The book to borrow on.

**maxRateBps** `number | string` *required*

The most you will pay.

**maxSize** `string` *required*

The most you will borrow for this order, in total.

If the order is short of premium cash or margin, OCX borrows the shortfall `ioc` on that book (at least `minSize`, sized so the cash after the fill fee covers it), then checks the order again. The loan and the order commit together or not at all: if the borrow is refused, the order is still short, or an `ioc`/market order fills nothing (`ORDER_DID_NOT_FILL`), nothing is borrowed and the order is not sent. The response adds `borrowed: { size, fee, cash, fills }`, or `null` when nothing was borrowed.

```json POST /orders theme={null}
{ "marketId": "SPX-2026-11-04-7350-P", "side": "sell", "type": "limit",
  "price": "3.1", "quantity": "10", "timeInForce": "gtc",
  "borrow": { "tenor": "1w", "maxRateBps": 1700, "maxSize": "50000" } }
```

> [!NOTE]
>
> The automatic top-up from your other buckets acts only on a rejected order. With `borrow`, the order is not rejected for a shortfall; it borrows instead. Move cash into `options` first if you would rather use your own.

## Errors

Refusals return `400` with `{ code, message, details }` unless noted.

| Code | Meaning |
| - | - |
| `INVALID_TENOR`, `INVALID_SIDE`, `INVALID_RATE`, `INVALID_SIZE` | Malformed field. |
| `SIZE_TOO_SMALL` | Below `minSize`. |
| `FUNDING_DISABLED` | The books are closed. |
| `BOOK_TAKE_ONLY` | A resting (`gtc`) order on `23h`. |
| `BOOK_CLOSED` | Inside the `23h` blackout window. |
| `SELF_CROSS` | Would cross your own resting order on the book. |
| `BORROW_CAP` | Over your borrow capacity; `details.capacity` says how much is left. |
| `LEND_LIMIT` | Over your free equity; `details.lendable` says how much you can lend. |
| `INSUFFICIENT_CASH` | Not enough cash in `options` to post a lend or to repay. |
| `MARGIN_UNAVAILABLE` | Margin could not be checked; retry. `503` on repay. |
| `NOTHING_TO_AMEND`, `ORDER_NOT_OPEN` | Amend with no change, or of an order no longer resting. |
| `NOTHING_TO_REPAY` | No borrowing from OCX to repay. |
| `REPAY_NEEDS_MARGIN` | Repaying now would leave your positions under-margined. |
| `INVALID_BORROW`, `BORROW_LIMIT`, `NOT_ENOUGH_ON_OFFER` | Borrow and place: malformed `borrow`, more needed than `maxSize`, or not enough offered at or below `maxRateBps`. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.