Passive Income from Algotrading

March 08, 2023 All posts


If we look at the candlestick plot of DAI/USD on Kraken, we can see large (2-4%) deviations from the $1 peg that DAI maintains. These deviations are due to liquidity shocks – order books are just not “deep” enough to momentarily execute big orders.

We can write a simple strategy that places limit orders at certain price levels (e.g. buy @ \$.99). Once the order executes we can sell that DAI for $1. We can find a starting price level by backtesting our strategy on historic data:

We can see in the above plot, that there are multiple “profit” zones. It looks like the most profitable thing to do is to sell at \$1, whilst buying at ~\$.983. However, this backtest wasn’t very sophisticated. Namely, we did not account for liquidity. In practice, even if the level around ~\$.983 will get reached by an order, by the time it gets there it might be for a small amount of money. Here is an example with an actual order (placed by me) at \$.99 for \$30,000:

Whilst the \$.99 target was hit, only ~\$8,937 worth of DAI got filled. Thus if we had a 10 trades in a year that hit $.99 mark, our naive backtest would have estimated returns close to \((\left [ \frac{1}{0.99}\right ]^{10} - 1)*100\% = 10.5\%\). However, if out of \$30,000 only \$9,000 gets filled every time, the returns drop to \((\left [ \frac{21000 + 9000*(1/0.99)}{30000}\right ]^{10}-1)*100\% = 3.07\%\). At the same time, if we had \$.995 target, and our orders were to be filled 100%, the returns would had been around 5%. Thus with lower margins we could have generated higher returns. That being said, we can’t raise our bid price too high, since fees will eat our returns.

Returning back to our partially filled order, we can dive deaper and see all the trades that took place (with my trade highlighted):

There is a couple of interesting things to observe:

  1. There was another trade “in front” of me with the same price (\$.99) but much bigger volume (\$50,000) that got filled.
  2. There was an order in front of both of us with slightly higher price \$.99001.

Due to FIFO nature of the orderbooks, how much of our order is going to be filled not only depends on the size of the order, but also on our position in the queue. When I placed my order at \$.99 there was already another order for \$50,000 there, so mine was executed after his. The order at \$.99001 gives us a hint on how to go around that – by adding a smallest amount possible to our price, we might keep our returns, but at the same time make sure our order is first to be executed.

Now things might not be as trivial as just using \$.99001 price instead of \$.99. Everyone is smart, so chances are once we place an order at the new price, another order will appear above us at \$.99002, like so:

An interesting thing to note in the above snapshot of the DAI/USD order book, is that there is a large order at \$.99265, worth around \$700,000. Playing the bid-war with other small players might be an interesting exercise, but biggest bang for the buck at this point is beating these “walls”. The strategy that could be tried at this point could be:

  1. Find a minimum and maximum desired profit range.
  2. Find maximum volume order in that range.
  3. Outbid that order.
  4. Go to step 2.


An important factor to strategy returns are fees. Most of the crypto exchanges use fee schedules, i.e.: your maker and taker fees depend on the 30-day USD volume. To give an example, my current fee is 0.16%, if I could get my 30-day USD volume to \$100,000, that fee would drop to 0.12%. My current returns (assuming buy price at \$.99266) is 6.54%. With 0.12% fees it would be 7.84%.

The fee schedule for a maker is as follows:

The question at this point is – is there a point to try and level up our fees as much as possible? Lower fees would mean more trades for same returns, thus lower fees, thus more trades – a positive feedback loop.

  1. How high could we get in terms of fees starting with \$100k?
  2. How profitable we could be whilst still being able to maintain the volume requirement?