DOCS / 04

Orders

Limit, stop-loss with take-profit, and DCA orders: how each kind fills, where your tokens wait, what an order costs, the order book option, the keeper and its fallback, and the risks.

Updated · Markdown version

Live on BNB Chain. Orders contract 0x06360a557290f64aeC55B7a06b788eD8723e71f9, read-only views at OrdersLens 0x844ff0401646A42A868d7029eB5dC847796CA686, keeper 0xDd301C136A83Bb0d62F74272f4d3e57B278A0D13. Orders are not available on any other chain.

Besides swaps, Tirio runs standing orders that fill later, when the market reaches your terms. You place them from the Limit and DCA tabs of /swap or from the Limit, Stop and DCA tabs of the trade page. Placing an order is one transaction that moves the tokens you sell into the Tirio Orders contract. They wait there until the order fills, expires or you cancel it. A keeper run by Tirio watches every open order and fills it through the same Router and the same routing as a swap, across the pools Tirio reads.

Order types

Limit

A limit order sells an amount at a price no worse than yours: a min price when you sell, a max price when you buy. The keeper checks open orders every few seconds and fills yours as soon as the best route Tirio finds, simulated on chain, pays at least your price. When the keeper fills, everything the route pays above your price is yours.

  • Price shortcuts set the price at the market or 1 %, 5 % or 10 % better than the market.
  • Partial fills are off by default: the order fills in one go or not at all. With Allow partial fills and a smallest fill, the keeper fills the largest part the market pays at your price, never less than the smallest fill, and the whole remainder can always be filled.
  • Expires in 1 hour, 1 day, 7 days (the default), 30 days or a custom number of hours or days, at most 364.
  • List on the order book is explained below.

Stop-loss and take-profit

A stop order sells when the price falls. It is available on the trade page and always sells the pair's base token.

  • Stop price: the order triggers when the best route for the whole remaining amount pays your stop price or less. The contract also checks the trigger against an independent price reference.
  • Worst price: the lowest price the stop may sell at. Left empty, it is 98 % of the stop price. If the price gaps below the worst price, the order stays open instead of selling lower.
  • Max deviation from oracle price: every stop fill must get you within this much of the independent price reference, after fees. 5 % by default, up to 10 %.
  • Add take-profit (OCO): an optional take-profit price above the stop price. That leg sells when the best route pays at least the take-profit price. Both legs spend the same tokens, so whichever fills first closes the order.

A trigger has to hold for three checks at least a second apart before the keeper sells, and the last check simulates the full route. The keeper then sells at the best route, never below the worst price (or, for the take-profit leg, below the take-profit price).

DCA

A DCA (dollar-cost averaging) order buys or sells in equal slices on a schedule.

  • Total to spend or sell, split into a number of slices (at least two) or an amount per slice; the last slice takes whatever remains.
  • Every 1 hour, 4 hours, 1 day (the default), 1 week or a custom number of minutes, at least one.
  • First slice now or after one interval.
  • Price protection: a slice never fills at a worse price than this (a max price when you buy, a min price when you sell). Left empty, it is set from the market when you place the order so that a slice never receives less than 90 % of what the market pays at that moment: a max price about 11 % above today's price when you buy, a min price 10 % below today's price when you sell.
  • Max deviation from oracle price: every slice must get you within this much of the independent price reference, after fees. 3 % by default, up to 10 %.
  • An optional second bound (a min price when you buy, a max price when you sell). While the price is outside your range, a due slice waits and fills once the price comes back.

Stop and DCA orders need a pair with an independent price reference. For a pair without one, the app says so and only limit orders are available.

Each slice is due one interval after the previous one was due. A late slice (the price was out of range, the order was paused or the keeper was delayed) moves the next due time to one interval after it filled, so missed slices never fill back to back. You can pause and resume the order and edit the slices left, the interval, the price protection and the second bound; a shorter interval brings the next slice forward. The expiry is set for you: twice the schedule plus seven days, at most 364 days. Resuming does not move it, and whatever has not been bought or sold by then is returned.

Your tokens wait in the Orders contract

  • Placing takes the tokens you sell into the Orders contract in the same transaction. The native coin travels as the transaction's value. An ERC-20 token takes the same approval paths as a swap, with the Orders contract as the spender: a Permit2 signature by default, an EIP-2612 permit where the token supports it, or an approval.
  • While the order is open nobody can move those tokens except a fill that pays you at least your price: not Tirio, not the keeper and not the contract's owner. The owner can withdraw only the fees the contract has collected.
  • Every fill pays its output to your wallet in the same transaction.
  • Cancel at any time: what is left of the order returns to your wallet in the same transaction. Cancel all closes every open order at once.
  • Expired orders no longer fill. The keeper returns what is left of them; anyone may trigger that refund, and you can cancel an expired order yourself to get the tokens back at once. The orders table marks such an order Expired · refund pending.

Fees

  • 10 bps (0.10 %) of what each fill receives, 3 bps (0.03 %) between stablecoins (USDT, USDC, USD1 and FDUSD on BNB Chain).
  • Charged only when an order fills, from the output of that fill. Placing, cancelling and expiring cost nothing but the gas of your own transactions, and the keeper pays the gas of every fill. A fill pays no swap fee on top: the Router's protocol fee is 0 and the Router exempts the Orders contract anyway, and the app's 3 bps Tirio fee applies to swaps only.
  • Your price is net of fees. The contract checks what reaches you after the order fee (and a partner fee, if any) against your price, so the price you enter is the price you get.
  • Everything above your price is yours when the keeper fills: there is no cut of the price improvement, and the positive-slippage cap of swaps does not apply to fills.
  • A white-label link's partner fee applies to orders too, on the output of every fill, paid to the partner minus Tirio's 10 % share.
  • The contract caps the order fee at 1 % (100 bps). The fee is read when an order fills, but because your price is net of fees, a fee change can never pay you less than your price.

You also pay the fees of the pools on the route, as with any swap.

List on the order book

Limit orders have a List on the order book switch. It is on by default in the app.

  • On: the order is listed in Tirio's order book, and any Tirio swap can take it at exactly your limit price the moment it is listed. The swap's route treats your order like a pool that sells at your price. Your order tends to fill sooner, you always receive exactly your price, and any price improvement goes to the swap that took it.
  • Off: the order is not listed and no swap can take it. Only the keeper fills it, at the best route, and anything the route pays above your price goes to you.

Listed orders appear in the order book panel of the trade page. Stop and DCA orders are never listed.

The keeper and its fallback

The keeper is a Tirio service with its own key, 0xDd301C136A83Bb0d62F74272f4d3e57B278A0D13. That key can only fill orders and tell the contract the keeper is alive (a ping every five minutes); it can move no funds in any other way. While orders are open, it reads them from the chain every few seconds, simulates each fill on chain before sending it, and sends fills through private transaction endpoints first. It skips fills worth less than $1.

If the keeper stops, stop and DCA orders wait until it is back. Once it has not pinged for longer than the contract's grace period (15 minutes), anyone may fill limit orders (listed on the book or not) and take-profit legs, so a keeper outage does not hold those orders hostage. The contract still pays you at least your net price, but the price improvement above it may go to whoever fills.

Stop legs and DCA slices only ever fill through the keeper, and every one of their fills is checked against the independent price reference.

Floors

Every order carries a floor that the contract enforces on every fill, in proportion to the amount filled and after fees:

OrderFloorDefault in the app
Limityour limit pricenone: you enter it
Stop legyour worst price98 % of the stop price
Take-profit legyour take-profit pricenone: you enter it
DCA sliceyour price protection90 % of what the market pays when you place the order

Stop legs and DCA slices have a second floor: what you receive after fees must be within your max deviation of the independent price reference. The higher of the two floors applies. A fill that would pay you less reverts. The floor is also the worst case if something goes wrong (see Risks and limits below), so set it to a price you would accept.

Amounts and durations

  • Minimum per token: each token has a minimum order size, about $5, that applies to the whole order or to each DCA slice. The app shows it under the amount and the contract refuses smaller orders. A token without a minimum cannot be listed on the order book.
  • Durations: limit and stop orders run from one hour up to 364 days; a DCA order's expiry follows its schedule. The contract refuses anything longer than 365 days.
  • Gas: placing an order is one transaction of about 390 000 to 510 000 gas on BNB Chain, depending on the token and the approval path; cancelling takes about 65 000 to 80 000.

Tokens with transfer taxes

Tokens that take a tax on transfer cannot be traded through orders. The API refuses a token with a known transfer tax, a blocked token and one whose tax cannot be measured, and the contract refuses an input that delivers less than the amount you place and any fill whose output would leave it short of what it holds for others.

Claiming a payout that could not be sent

A payment that fails never blocks a fill, a cancel or an expiry. If the Orders contract cannot send you a fill's output or a refund (for example a contract wallet that rejects the native coin or needs more than 50 000 gas to receive it, or a token that blocks your address), the amount is recorded as claimable for your address. The orders table then shows Waiting for you to claim with a Claim button for each token, which sends you the balance. The same applies to partners.

Risks and limits

  • Price reference. Stop triggers and every stop and DCA fill are checked on chain against an independent price reference, and each fill must stay within your max deviation of it. A sustained move in the market still triggers a stop, so choose the worst price with that in mind.
  • Timing. Fills are sent seconds after the market reaches your price. When many orders trigger at once or the network is congested they can lag; stops are handled first. In a fast fall a stop may sell well below its stop price (never below the worst price), or not at all if the price gaps below the worst price.
  • Keeper key. If the keeper's key were stolen, the worst it could do is fill your orders at their floors: a limit at your limit price, a stop or a DCA slice at the higher of its own floor and your max deviation below the price reference. It cannot move tokens in any other way, and the owner can replace it.
  • Keeper outage. If the keeper stops, limit and take-profit orders can be filled by anyone after the 15-minute grace period; stops and DCA slices wait for the keeper, so a stop may not sell while the market falls. You can cancel at any time.
  • Order book. A listed order fills at exactly your price, never better.
  • Tokens that can be frozen, burned or rebased. Some tokens let their issuer freeze or burn balances (USD1, for example), and some rebase. If that happens to tokens the Orders contract holds, open orders in that token can be affected. The order forms note such tokens.
  • Owner. The contract's owner can change fees, the keeper and the grace period, but it cannot touch escrowed tokens, and your floor is net of fees.
  • Testing. The Orders contract is covered by fuzz, invariant and mainnet-fork tests. See Contracts, Security and the Risk Disclosure.