Post and cancel an offer
Make a bid or an ask. What it promises is locked when you post it, and released when you cancel.
Posting an offer sets your own price. What it promises is locked when you post it, the units of an ask or the cash of a bid, and any other member can take it in part or in full until you cancel.
Before you start
- You are admitted.
- For an ask: the units, free in your position. Units locked in another offer or pledged in a repo don't count.
- For a bid: units times price, free in your ledger cash.
Post
Open the instrument
In Markets, open the instrument. Post an offer is beside its Offer board.
Side, units, price
Choose Buy or Sell and enter the Units and the Price per unit in USD. Locks now shows exactly what posting locks: the units for a sell, the cash for a buy.
Sign and post
Press Review buy offer or Review sell offer, then Sign and post. The offer appears on the Offer board and under My open offers, and the lock shows in your position's locked lane.
// An ask: 200 units of CALDER at 25.50 USD. Locks 200 units.
await send(await api.buildPostOffer({ wallet, code: 'CALDER', side: 'sell', units: '200', price: '25500000' }), sign)
// A bid: 100 units at 25.10 USD. Locks 2,510.00 USD.
await send(await api.buildPostOffer({ wallet, code: 'CALDER', side: 'buy', units: '100', price: '25100000' }), sign)curl -X POST "$AGORA_API/v1/build/post-offer" -H 'content-type: application/json' \
-d '{"wallet":"<wallet>","code":"CALDER","side":"sell","units":"200","price":"25500000"}'The price is cash atoms per unit. send is the helper from A first settlement.
Cancel
Choose Cancel beside the offer under My open offers on the instrument's page, or under Open offers on your account. Review cancel shows what returns, then Sign and send. Whatever is still locked returns to your free lane and the offer closes, returning its rent to you.
const { offers } = await api.account(wallet)
const mine = offers.find((o) => o.code === 'CALDER' && o.side === 'sell')
if (mine) await send(await api.buildCancelOffer({ wallet, offerId: mine.id }), sign)curl -X POST "$AGORA_API/v1/build/cancel-offer" -H 'content-type: application/json' \
-d '{"wallet":"<wallet>","offerId":"<offer id>"}'What it ends in
| Post an ask | Post a bid | Cancel | |
|---|---|---|---|
| Your units | free → locked | locked → free (an ask) | |
| Your cash | free → locked | locked → free (a bid) | |
| The offer | open, with its full size | open, with its full size | closed |
While it is open, each fill takes from the lock: see Atomic settlement. Units in an open ask keep earning income for you. The settlements are the kinds post-offer and cancel-offer.
If it fails
InsufficientFreeUnits,InsufficientFreeCash: the free lane is short of what the offer locks.ZeroAmount: units or price is zero.InvalidId, or "already in use" from the System program: another offer of yours landed first. Build again.WrongAccount: cancelling an offer you didn't post.