updated over 2 years ago
Orderbook works with markets where you can create orders for a specific trade pair you want to exchange. Each market has its own rate and its own trade history.
An exchange between users happens through Sell and Buy orders. Sell and Buy orders are matched when the Taker proposes a bid that is bigger or equal to Maker’s ask.
Placing an order to be matched in the future by someone makes you the Maker. Matching someone's order makes you the Taker in that exchange. It is worth mentioning because order matching fees are covered by Takers.
Taker fee is a maximum between the fixed fee and percentage fee (0.2%) from amount traded. But if the traded amount is less than the fixed fee then percentage fee is taken.
Take a look at the casual situation on TKN-ETH market:
Let’s say that Bob wants to buy 50 TKN for his 0.5 ETH and there are no Sell Orders to match it at the moment. Alice is interested in selling her 100 TKN for 1 ETH or greater.
From Bob’s buyer side:
- Bob places a Buy Order of 50 TKN with the rate of 0.01 ETH for 1 token.
- Orderbook publishes the Buy Order, taking Bob's 0.5 ETH from his contract. Bob can cancel his order any time later, receiving his ETH back.
Note: If there are no Sell Orders on the stack Bob is an order Maker.
From Alice’s seller side:
- Alice finds the Bob’s Buy Order and places a Sell Order of 100 TKN with same rate of 0.01 ETH for 1 token.
- Alice's 100 TKN tokens are sent to Matching Engine contract.
- Orderbook searches for Buy Orders to match Alice's Sell Order, finds Bob's order, transfers 0.5 ETH from Matching Engine's address to Alice's address, then transfers 50 TKN to Bob's address.
- Note: Alice is an order Taker, and as a Taker she pays trading fee that covers trading transactions. Bob does not pay trading fee because he is Maker.
- Orderbook updates Alice's order, subtracting sold tokens from total amount to sell.
- Since Bob’s Buy order is matched, Orderbook closes it.
- Note: now Alice becomes an order Maker, and will not pay trading fee for further manipulations with the rest of her Sell Order.
In the end, Bob has 50 TKN on his address on TKN token contract.
As for Alice, she has 0.5 ETH. Alice also holds a Buy Order of 50 TKN that weren’t covered by Bob’s Buy order. Orderbook holds Alice`s 50 TKN. It can be returned to Alice at any time if she cancels a Sell order.
Same order of actions is relevant for the opposite case.