# Create an order

`POST /sigmafi/zc/orders` · Lithos client API · SigmaFi ZC Standard · requires the `api_key` header

Source: https://lithosprotocol.org/docs/api/create-zc-order

Lock collateral in an `Order` or a `PricedOrder`, depending on pricing and timing. An unguarded oracle order already under its own ratio is refused unless `allowLiquidatable`. A LithosDex provision NFT is refused as collateral: wrap it and use the receipt.

## Request body

`ZcOrderRequest`, application/json.

- `market` (string, required, one of ERG, SigUSD)
- `pricing` (string, one of fixed, yield, window): Default fixed.
- `principal` (string, required): Exact for fixed pricing; the floor for yield and window pricing.
- `repayment` (string, required)
- `timing` (object, required): `{ mode: fixed, maturity or blocks, exact }` (snapped to the 21,600-block grid unless `exact`), `{ mode: term, duration }` counted from the fill, or `{ mode: window, minDuration, maxDuration }`. 
- `yield` (object): Yield pricing. `endHeight` defaults to the expiry and `endBps` to `startBps`.
  - `startBps` (integer · int64)
  - `endBps` (integer · int64)
  - `endHeight` (integer · int64)
- `curve` (object): Window pricing. The most yield paid, then up to 20 points.
  - `capBps` (integer · int64)
  - `points` (ZcPoint[])
    - `blocks` (integer · int64, required): Blocks left to maturity.
    - `bps` (integer · int64, required): Simple yield per 262,800 blocks, in bps.
- `collateral` (object, required)
  - `nanoErg` (string)
  - `tokens` (ZcToken[]): At most 30, each token once, each amount at least 1. A liquidated bond holding more could not be pulled into a Dutch share vault within the node's 4,096-byte box limit. 
    - `tokenId` (string, required)
    - `amount` (string, required)
- `rule` (object, required): `{ kind: oracle, ratioBps, oracleAge }` or `{ kind: maturity }`.
- `fillGuard` (object): Left out, the guard is on at the rule's ratio for oracle orders. null turns it off.
  - `ratioBps` (integer · int64)
- `expiry` (integer · int64)
- `expiryFeeNanoErg` (string): Default 5000000.
- `allowLiquidatable` (boolean)
- `limits` (ZcLimits): Bounds on the rebuilt transaction. For fills, buys, repays, recollateralizations and claims, amounts are in the action's market unit (nanoERG for ERG, fee included; raw units for SigUSD; nanoERG for actions with no market). For posts (orders, offers, asks, lots, fractionalize and wraps), `maxPay` is always in nanoERG (box value plus miner fee), since any token capital or collateral is fixed directly by the request body. Outside them the send answers 409. 
  - `maxPay` (string)
  - `minReceive` (string)

## Responses

### 200: The transaction was sent; `outcome` says whether the node accepted it.

`ZcResult`

- `txId` (string): None while the write is held.
- `outcome` (string, one of accepted, rejected, uncertain, held): The node's answer. `held`: the write reads the box a pending oracle refresh creates, and a miner could reach it before that refresh, so nothing was sent yet. The client tries it again every 30 seconds for 10 minutes, rebuilt and checked against `limits` each time, and sends it once the refresh confirms.
- `reason` (string): Why a write is held.
- `retriesUntil` (integer · int64): When a held write stops being tried (ms since the epoch).
- `boxId` (string): The transaction's first output.
- `assetId` (string): The bond asset a fill minted.
- `warnings` (string[])

### 400: A malformed field, or terms the contracts refuse.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 403: Missing or wrong api_key.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 404: No such box or token, or not this wallet's.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 409: A pending transaction already spends a box this needs, or the rebuilt transaction is outside `limits`. Re-quote and resend.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 422: Valid, but not possible now; the message gives the reason the check lists in `refusals`.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

### 503: ZC tracking is off or not seeded, or the node, its index or the wallet did not answer. Nothing was sent.

`ApiError`

- `error` (integer, required): Error code
- `reason` (string, required): Error message explaining the reason of the error
- `detail` (string, required): Detailed error description

## Example request

```bash
curl -X POST "http://localhost:9000/sigmafi/zc/orders" \
  -H "api_key: $LITHOS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "market": "ERG", "pricing": "fixed", "principal": "string", "repayment": "string", "timing": {}, "yield": { "startBps": 0, "endBps": 0, "endHeight": 0 }, "curve": { "capBps": 0, "points": [ { "blocks": 0, "bps": 0 } ] }, "collateral": { "nanoErg": "string", "tokens": [ { "tokenId": "string", "amount": "string" } ] }, "rule": {}, "fillGuard": { "ratioBps": 0 }, "expiry": 0, "expiryFeeNanoErg": "string", "allowLiquidatable": true, "limits": { "maxPay": "string", "minReceive": "string" } }'
```

## Example response

```json
{
  "txId": "string",
  "outcome": "accepted",
  "reason": "string",
  "retriesUntil": 0,
  "boxId": "string",
  "assetId": "string",
  "warnings": [
    "string"
  ]
}
```
