An on-chain book is slower than a centralized one, and every requote is a transaction. Expiry, epochs and the atomic batch bound what a stale quote can lose.

Latency on NEAR

  • Blocks are about 0.6–1.2 s apart. A signed intent reaches hexbook.near 2–4 blocks after submission, final a few later.
  • A taker can hit your order in the next block. Your requote is always a few seconds behind the reference. Size the spread for the move the reference can make in that time.
  • Two batches in flight can land in either order: send one at a time and wait for its outcome.

Why TTL and epoch

Set the TTL to a few tick intervals (e.g. 2 minutes with a 30 s loop, 3–5 minutes with a 1-minute cron): a missed tick only lets orders expire. Expiry is checked against the block timestamp (ns). Keep your clock synchronized (NTP): an expires_at that is not in the future when the batch executes makes it panic.

Kill switch

Send cancel_all and stop quoting when:
  • your reference price is stale (the source failed and the last good price is older than you accept);
  • the reference price jumps more than you accept between two ticks;
  • an inventory limit or your loss limit trips;
  • your process is shutting down.
Resume by hand, so a flapping source does not re-post the ladder in a loop. cancel_all costs the same with 3 or 200 orders.
Dead orders (killed by cancel_all / bump_epoch, or expired) still count toward the 200-per-owner and 500-per-level limits and the 128-order live-price scan. When you resume, list them in the cancel of your first batch (cancel accepts dead orders); find them with get_orders_by_owner + get_order_meta. prune is a fallback. The full sequence is the lifecycle.
Do not cancel with close_order: it pays out your whole internal balance. Use batch cancels or cancel_all.

Inventory limits

  • Cap what you may hold per asset (internal balance + resting orders). Past a limit, stop quoting the side that grows it.
  • Skew both sides against your inventory before the limit, so fills tend to bring it back.
  • With payout mode intents, fills land in intents.near and must be deposited again; internal avoids that.

Hedging

hexbook does not hedge for you. If you hedge elsewhere, hedge when the net delta since the last hedge passes a threshold, not on every fill.
  • A hedge has its own latency and fees; include them in your spread.
  • Do not stack hedges: wait for one to settle (or fail) before sending the next.
  • If you cannot hedge, manage risk with skew, inventory limits and a wider spread.

Operational checklist

  1. Dry run against mainnet data; check prices, tick rounding and sizes.
  2. Start with small sizes and tight inventory limits; raise them after a day of clean fills.
  3. Watch place_skipped (cross often means the spread is too tight or the fair is stale).
  4. Cancel your dead orders in your batches (see the lifecycle); otherwise they fill your 200-order cap and placements are skipped with owner_cap.
  5. Keep keys out of config files and repositories; use a dedicated account.