Order lifecycle
The steps
Section titled “The steps”| Step | Call | Who |
|---|---|---|
| 1. Catalog | GET /v3/catalog lists the chains and assets you can trade, with their fees. |
Your backend |
| 2. Quote | POST /v3/quote prices a trade and returns its options. |
Your backend |
| 3. Create | POST /v3/orders turns one option into an order, with the steps that fund it. |
Your backend |
| 4. Fund | The steps in summary.actionNeeded: EVM transactions from the payer, or one transfer from anyone. |
The user’s wallet |
| 5. Track | GET /v3/orders/{id} until summary.pollAfterSeconds is null, or sync every order with GET /v3/orders?sort=updatedAt. |
Your backend |
| 6. Cancel (optional) | POST /v3/orders/{id}/actions with a signed cancel, while the order trades. |
The user signs; your backend relays |
sequenceDiagram
participant B as Your backend
participant A as Khalani API
participant W as User's wallet
B->>A: POST /v3/quote
A-->>B: options
B->>A: POST /v3/orders (option, accounts)
A-->>B: order, with its funding steps
B->>W: the steps in summary.actionNeeded
W->>W: approve and deposit (EVM), or transfer
loop every summary.pollAfterSeconds
B->>A: GET /v3/orders/{id}
A-->>B: status, outcome, summary
end
Status
Section titled “Status”status is a closed list. Orders can skip statuses. An expired order can later become delivering or done when its deposit is refunded.
status |
Meaning |
|---|---|
awaiting_funding |
Created. Waiting for the deposit. |
confirming |
Khalani has seen the deposit, and the order is about to go live. |
trading |
Published: solvers can fill it, and it can be cancelled early. |
settling |
Trading ended: it filled, was cancelled, or reached fillBy. The payout and refund are being worked out. |
delivering |
Settled. The payout and the refund are on their way. |
done |
Delivered. Nothing is left to happen. |
expired |
It didn’t publish by fillBy. Trading is over; a deposit refund can still follow. |
To know whether the user has been paid, read summary, as Track orders explains.
Outcome
Section titled “Outcome”outcome says how trading ended. It is null until settling.
outcome |
Meaning | What the user gets |
|---|---|---|
full |
Filled in full. | The payout. |
partial |
Cancelled, or reached fillBy, after at least one fill. |
A payout for the filled part, and a refund of the rest less the flat fee. |
none |
Cancelled, or reached fillBy, with no fill. |
A refund of the deposit less the flat fee if it published, or the full deposit if it couldn’t publish. |
The two deadlines
Section titled “The two deadlines”Every order has two deadlines, set by your account. The quote gives them as durations, terms.fundWithinSeconds and terms.fillWithinSeconds, and the order as times counted from its creation, terms.fundBy and terms.fillBy. Ask Khalani to change them.
fundBy is when to stop asking the user to pay. Show it on your payment screen. Once it passes without a deposit:
- every step shows
closed, summary.actionNeededturns null, and- the history records a
funding_closedchange.
Hide the payment action then. If the user still wants to trade, quote again and create a new order. A deposit sent before fundBy that shows up a little later still counts.
fillBy caps how long the user waits. Solvers can fill the order until then. At fillBy, an order that hasn’t filled in full settles on its own: the user gets the filled part, and the rest of the deposit back, less the flat fee. You don’t need to do anything. So tell the user they will have their tokens, or their refund, by fillBy at the latest.
fundBy comes well before fillBy, so a deposit sent in time can still trade. A deposit that arrives after fillBy can’t fund the order: the order ends expired, shows the NOT_PUBLISHED notice, and the user waits longer to get the deposit back. Once Khalani records its full refund, the notice goes and the order moves to delivering and then done, or straight to done if delivery is already confirmed.
Settlement
Section titled “Settlement”An order settles once, when the first of these happens:
- it fills in full,
- it reaches
fillBy, or - a cancel is accepted.
Settlement pays the filled part to recipient on the destination chain, at no less than terms.minRate. It refunds the unfilled part of the deposit, less the flat fee, to refundTo on the source chain. An order can fill in parts, from more than one fill.
When to stop
Section titled “When to stop”Once summary.pollAfterSeconds is null, stop routine polling of that order: it is done or expired. Keep syncing with sort=updatedAt for later deposit and refund updates to expired orders. An order nobody funds ends expired shortly after fillBy. If a deposit for it arrives later, the order stays expired, gains the NOT_PUBLISHED notice, and sync lists it again. Sync lists it again when Khalani returns that deposit, as the order moves to delivering and then done, or straight to done if delivery is already confirmed. See Track orders.