The bizarre math of KuCoin Grid bots

Grid Bots

I'm rather fond of the concept of Grid Trading, in particular of the idea of betting on no particular trend happening and profiting of the oscillations of the market.

The core concept is to define your grid an interval within you think a pair (say BTC/USDC) will move in the foreseeable future, slice it into bands and then for each band you maintain either a buy order on the bottom of the band or a sell order on the top of it.


Sells at the top of one band are matched with buys at the bottom of it so, that every time a sell occurs a small profit is taken. If the volatility is high enough and the trading fees are low then some nice profits can be made.

The amounts being bought and sold are sliced so, that if the grid reaches its lower bound then the bot will hold only the numerator of the pair (BTC in our example) whereas if it reaches the upper bound then will be all denominator (USDC in our example)

When you setup the Grid Strategy you (usually) create it around the current spot price and buy enough of the asset so, that all the sell orders going up to the top of the grid can be fulfilled.


As an example imagine that BTC/USDC is at 58'000 and you setup a grid with 4 orders between 56'000 and 60'000 for a total of 230 USDC, (for simplicity let's assume that we're lucky enough to not pay trading fees) you will:

  • buy 0.002 BTC for 116 USDC (and keep the other 114 USDC) 
  • create sell orders for 0.001 BTC each @59k and 60k resp.
  • create buy orders for 0.001 BTC each @57k and 58k resp.

In this case if BTC descends to under 56k and then gets back at 58k the following would occur:


  • buy 0.001 BTC @57k for 57 USDC
  • buy 0.001 BTC @56k for 56 USDC
  • sell the BTC you bought @56k for 57 USDT
  • sell the BTC you bought @57k for 58 USDT

now you would have the asset you had at the beginning +2 USDT (or a 0.8% profit). If such oscillations happen often enough then these small profits could sum up to something nice.

Enters KuCoin

KuCoin has become a rather popular playground for Grid Trading Bots, and this is (imho) for a few reasons:

  • Bots are easy to setup for they're a built in feature of KuCoin's mobile App (even though at the time of this writing they are not yet supported in the web portal)
  • The platform allows for very small transaction and, hence, you can setup a Grid Bot with just a few tens dollars, which is kind of the ideal setup for experimenting
  • KuCoin bots are free

When reporting profit and losses KuCoin splits the thing in two parts:

  • Grid Profit: aka the profit made by buying at the bottom of a band and selling at the top of it (which is always greater or equal to zero)
  • Floating PNL: the variation in value of the asset the but is currently holding


So far, so good, this breakdown of profits/losses makes per se completely sense.

Alas the way KuCoin calculates them tend to be a little confusing (and if I'd to guess I'd say that it has been done this way for the sake of keeping the implementation simpler).

Lets make an example using the hypothetical BTC-USDC bot we defined in the previous section (230 USDC, starting @58k, grid with 4 orders between 56k and 60k) and imagine a scenario where the price climbs over 60k and then re-descends to 58k:


  • sell 0.001 BTC @59k for 59 USDC
  • sell 0.001 BTC @60k for 60 USDC
  • buy 0.001 BTC @59k for 59 USDC
  • buy 0.001 BTC @58k for 58 USDC

after the swing is over you have the assets you had at the beginning (0.002 BTC + 114 USDC) plus 2 USDC.

Intuitively you would said that the Grid Profit would be 2 and and the Floating PNL would be 0 (after all you still have 0.002 BTC worth 116 USDC, just as at the very beginning), however a KuCoin bot going through that would show something different, namely:

  • Grid Profit: 3 USDT
  • Floating PNL: -1 USDT

The total is still the same (+2 USDT) but the breakdown is at least a little odd. Let's see how and why this happens:

  • in our mental accounting we would most probably match the sell with the subsequent re-buy at a lower price (which just makes sense)
  • The bot however does a different (and less intuitive) matching:
    • the first two sells are matched to the original buys of when the bot had been started
    • the two subsequent buys are unmatched

This has two consequences: the sell @60k generates an overstated grid profit of 2 USDT (60-58) and the unmatched buys move the average price of the BTC holding up to 58.5 (for 0.001 have been bought @59k and 0.001 @58k) which leads to the Floating PNL loss of 1 USDT.

If I had to guess I'd speculate that this might be due to the fact that the second approach is easier to implement than the first one (for each band you only have to keep track of the buying price).

The good news is that over time the difference between the two approaches tend to diminish: most of the discrepancy is accumulated as the sells corresponding to the initial buys occur, that is: the first time that the price of the asset crosses the upper side of the grid.

The bad news is that given that the current implementation of the KuCoin bots doesn't automatically reinvest (profits) you might end up stopping and re-creating bots quite regularly.


pax et bonum


P.S.: if you want to try KuCoin bots please feel free to use my referral code (rJAFWLS) or Link

How do you rate this article?



Elia Noris
Elia Noris

Computer scientist / mathematician, interest in math, computer science, crypto, current affairs, design. IT,DE,FR,EN,ES.

the n00b and the crypto
the n00b and the crypto

What all crypto topics have in common to me is that they all make me always feel outside my comfort zone and I'm always the less knowledgeable person in the room... pretty much the Jon Snow of crypto

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.