Skip to content
Guides

Track orders

GET /v3/orders/{id} takes the order’s ord_ id and needs your key. Track orders from your backend.

Terminal window
curl -sS "https://api.hyperstream.dev/v3/orders/$ORDER_ID" -H "X-API-Key: $KHALANI_API_KEY"

Poll it after summary.pollAfterSeconds, until that is null. Null means routine polling can stop because the order is done or expired. Keep syncing with sort=updatedAt to receive later deposit and refund updates for expired orders. There are no webhooks. With more than a few dozen open orders, sync.

Every change to an order raises its version. Reads can arrive out of order, for example a sync page and a read by id. Keep the one with the higher version. Two reads with the same version show the same order.

Read status, outcome and summary. The lifecycle lists every status and outcome.

Before settlement, show what the order commits to:

  • terms.receive: the amount the quote showed.
  • terms.receiveMin: the least a full fill pays.
  • terms.flatFee: the quote’s display.flatFee. A published order that doesn’t fill, cancelled or not, refunds send less it. Recovery of a deposit that never published refunds the full deposit.

After settlement, show the two legs, summary.payout and summary.refund:

"payout": { "amount": { "asset": { "id": "eip155:8453/erc20:0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "chain": "eip155:8453", "symbol": "USDC", "decimals": 6 }, "amount": "99620254" },
"status": "completed", "tx": { "chain": "eip155:8453", "hash": "0x…" }, "withoutTx": null }
Field Meaning
amount What this leg pays. Null until the order settles, and briefly after.
status pending until it settles, in_flight on its way, completed once it lands.
tx The delivery transaction, once seen.
withoutTx Why a completed leg has no tx, else null. An open list: sub_unit_amount or tx_unknown.

Both legs are always present. A leg with nothing to deliver completes with amount 0, so show a leg once its amount is above zero: a full fill has a payout, an order with no fill a refund, and a partial fill both.

A leg is complete once its status is completed, even while the order still shows delivering. A completed leg can have tx: null and empty obligation evidence; its withoutTx says why:

  • sub_unit_amount: the amount was smaller than the smallest unit on the chain the leg pays out on, so nothing was transferred. For example, a partial fill can leave a ZEC refund below one zatoshi. Its refund leg completes with amount "0", tx: null and withoutTx: "sub_unit_amount".
  • tx_unknown: the leg was delivered, but its transaction is unknown, and may never become available.

summary.notices lists what Khalani is handling, each a code with params. The user has nothing to do. Tell them what is delayed.

code Meaning
NOT_PUBLISHED A deposit arrived that couldn’t fund the order, such as one that arrived too late. Khalani returns it to the sender. For an order that never published, the notice goes once the refund is recorded in summary.refund. If another deposit published the order, the notice remains for the separate stranded deposit.
SETTLEMENT_STUCK Settlement is delayed. Khalani keeps retrying it.
DELIVERY_STUCK A payout or refund is delayed. Khalani is recovering it.

Notice codes are an open list. Show an unknown one as is.

The rest of the order is the record behind summary:

Field What it holds
accounts The payer, recipient and refundTo the order was created with.
steps The funding steps. See Fund orders.
liveAt When the order went live for solvers.
receipts The deposit’s transaction, once seen.
fills Each fill, with send, what it used of the deposit (its share of the percentage fees included), and receive, what it pays. The fills’ receive add up to the payout. For a published order, their send, terms.flatFee and the refund add up to terms.send, give or take a base unit of rounding.
obligations The payout to recipient and the refund to refundTo: the legs summary shows, with each delivery’s transaction, and when it was seen, in evidence.
requirements What holds the order up, and who acts. Those Khalani acts on are also in summary.notices.
invocations The cancel request, if any. See Cancel and refunds.
actions.cancel Whether a cancel is possible now, and what to sign.
charges.protocolFee The protocol fee taken at settlement, rounded up like terms.flatFee.

GET /v3/orders returns your orders in pages of up to 50, limited to your key.

Query Meaning
status Repeat it for several. Not with sort=updatedAt.
account A CAIP-10 id, such as eip155:42161:0x5B38Da6a701c568545dCfcB03FcB875f56beddC4. Matches the payer, the recipient or refundTo.
sendAsset, receiveAsset An asset id.
sort createdAt (the default) or updatedAt.
cursor The cursor from the previous page. Leave it out on the first page.

Keep the sort and filters unchanged while paging. A cursor in the wrong format, cursor=null included, is a 400 VALIDATION_FAILED.

sort=createdAt lists newest first. cursor is null after the last page. Stop only then: a page before it can come back empty when it skipped orders v3 doesn’t show.

sort=updatedAt syncs. Each page holds the orders that changed after the cursor you send, each once and in its current state, oldest change first. Keep the last cursor you got, and ask again every 10 to 30 seconds:

  • A page that comes back empty with the cursor you sent means you are caught up. Keep the cursor and ask again later.
  • A page that comes back empty with a new cursor skipped changes that aren’t listed. Ask again now, with the new cursor.
  • 410 CURSOR_EXPIRED means the API can no longer use your cursor. Sync again with no cursor, which returns every order in its current state, and continue from the cursor it gives. A cursor doesn’t expire with time.
Terminal window
curl -sS "https://api.hyperstream.dev/v3/orders?sort=updatedAt&cursor=$CURSOR" -H "X-API-Key: $KHALANI_API_KEY"

Past a few dozen open orders, sync instead of reading each one: see Rate limits.

A recovered order can move straight from expired to done if its refund is already delivered. Its history then records delivered with the refund record, without an intermediate settled change. An in-flight refund records settled, then delivered when delivery completes. A refund already known to have failed records delivery_stuck directly; show its DELIVERY_STUCK notice.

GET /v3/orders/{id}/changes lists the changes to one of your orders, oldest first. It records what happened to the order, while the order itself shows its current state. Each change has the order’s version after it, its time, a kind, and records, the ids of the steps and records it set.

kind When
created The order was created.
deposit_seen The deposit showed.
funding_closed fundBy passed with no deposit.
expired The order didn’t publish by fillBy.
not_published A deposit arrived that couldn’t publish the order.
published The order went live.
cancel_requested A cancel was accepted for relay.
filled A fill landed.
trading_ended Trading stopped.
settlement_stuck Settlement is delayed.
settled The order settled.
payout_delivered, refund_delivered One leg landed before the other.
delivery_stuck A payout or refund is delayed.
delivered Every leg landed.
updated Anything else, before settled.

Change kinds are an open list, and changes can arrive in a different order from the one above. Versions in the history can skip numbers: not every change to the order is listed.