#App

By Jason Ridgway-Taylor

As part of the road to mainnet changes that Marigold is working on for Batcher, the first is moving the order execution from FIFO (first in, first out) to Pro-Rata.  This post describes the reasoning and benefits of such a change.

What is FIFO order execution?

FIFO is a type of order execution where the priority of execution is given to those orders that were placed earlier in a given set of orders. This means that the chance of being filled is better if the order was placed earlier. For Batcher, this meant that the order most likely to be filled (price level selection not withstanding) would be the order that opened the batch or those that were placed closer to the batch opening.

What is Pro-Rata order execution?

Instead of matching orders, one-by-one, we can consider all of the orders on a particular side for a given price and treat them all fairly at the same time rather than give time preference to any one. In practice this means understanding the percentage each order contributes to the volume and then fill them accordingly. For example, if a single order is 10% of the buy side volume then he would receive 10% of any matched sell volume in exchange, with any remaining part of the order returned; i.e. a partial fill. The advantages of pro-rata execution are that all matching orders achieve a fairer fill regardless of when the order was placed in the batch.  

An illustrative example

The following example, whilst contrived, will hopefully give an intuitive feel for the difference between FIFO and Pro-Rata.

The Order Book

For both illustrations, we will use the same initial order book.

Number / Wallet Side Sell Buy Amount Price
1 BUY tzBTC USDT 0.1 B Price / W Fill
2 SELL USDT tzBTC 2000 W Price / B Fill
3 BUY tzBTC USDT 0.1 W Price / B Fill
4 BUY tzBTC USDT 0.2 Oracle
5 SELL USDT tzBTC 10000 B Price / W Fill
6 SELL USDT tzBTC 2000 Oracle
7 BUY tzBTC USDT 0.1 W Price / B Fill

Additionally in both cases the clearing price (i.e. the price level at which the most orders can be cleared) will be the same; the Oracle price.

Wallet states after FIFO execution

Number / Wallet IB (tzBTC) IB (USDT) FB (tzBTC) FB (USDT) Fill % Fill
1 0.1 0 0 1642.7 100.0% Total
2 0 2000 0.1217 0 100.0% Total
3 0.1 0 0.1 0 0.0% No Fill
4 0.2 0 0.0564 2357.2942 71.76% Partial
5 0 10000 0 10000 0.0% No Fill
6 0 2000 0.1217 0.0058 99.99% Partial
7 0.1 0 0.1 0 0.0% No Fill
  • IB: Initial balance
  • FB: Final balance

After FIFO execution we have two orders that were totally filled and those were the ones that were first in the order book. The other orders that were included in the clearing level were only partially matched.

Wallet states after Pro-Rata execution

Number / Wallet IB (tzBTC) FB (USDT) tzBTC USDT Fill % Fill
1 0.1 0 0.0188 1333.33 81.2% Partial
2 0 2000 0.1217 0.0028 99.99% Partial
3 0.1 0 0.1 0 0.0% No Fill
4 0.2 0 0.0376 2666.6628 81.2% Partial
5 0 10000 0 10000 0.0% No Fill
6 0 2000 0.1217 0.0028 99.99% Partial
7 0.1 0 0.1 0 0.0% No Fill
  • IB: Initial balance
  • FB: Final balance

In contrast to the FIFO execution, no single order was totally filled (albeit very close to total) but the distribution of partial fills is a much fairer distribution when considering all the orders that were included in the clearing price.

Wen Pro-Rata?

The pro-rata version will be deployed to Ghostnet towards the end of the year after being tested on Kathmandunet. The change to pro-rata is one of the upcoming changes to Batcher as we progress to mainnet.

Steps to mainnet

In addition to the pro-rata execution change there will be a number of features being added to Batcher as we get it ready for mainnet.

- A more robust oracle solution.
- Continuous batches (sliding batch window). At the moment, a user cannot add orders to a closed batch until the oracle price has been received and the clearing has been done. We will be opening this up so that an order placed after the previous has closed will open the next batch.
- Multiple token pools. We will be adding support for token pools other than the tzBTC/USDT pool that is currently available.

A blog post will accompany each update along with an announcement of mainnet launch when ready.

DISCLAIMER:  The numbers in the examples are meant as illustration ONLY and as such the numbers have been rounded for display purposes.

If you want to know more about Marigold, please follow us on social media (Twitter, Reddit, Linkedin)!

Scroll to top