How To Create Liquidity With Kelp On The Stellar Dex

Bouwe Ceunen
Sep 2, 2020 · 10 min read

What is Kelp, what is market-making, what is market liquidity and how can you use Kelp to create it? I’ll walk you through the most important things you need to know in order to get started. Note that this post does not facilitate trading advice nor does it encourage you to be reckless. Always do your due diligence before you start trading and/or use trading bots.

Kelp Market Making Bot

There are a few key things you have to understand before we can dive into the usage of the market-making bot Kelp. The absolute entry point for understanding is something called the order book. This will also help understanding why prices differ from exchange to exchange.

The Order Book

Alright, first things first. What does it mean when you hear the word exchange? We’re going to look at StellarTerm, it’s a popular interface for the Stellar Dex. The Stellar Dex is the decentralized exchange where you can trade your Stellar (XLM) for other assets on the Stellar network. It’s also called the Stellar Universal Marketplace.

The screenshot below is the order book for Stellar/Bitcoin XLM/BTC. Everything comes in pairs, in order for you to trade good A, someone is willing to give something in return, good B. This can range from money to houses, where for example a market can be USD/house or USD/EUR or EUR/gold, it doesn’t really matter. The thing that matters is the liquidity, meaning how easy/hard it is to trade one thing for another. We’ll talk about this in the next section. Back to the order book.

On the left, you can see the Buy (Bid) offers, and on the right the Sell (Ask) offers. People are buying XLM and selling BTC, XLM/BTC. Of course, it’s the same as buying BTC and selling XLM, BTC/XLM. The first line in the left column is willing to buy 788.4878049 XLM at a price of 0.0000082 BTC. For 1 Stellar, that totals to 0.0064656 BTC. The total market depth is the sum of all orders in each column, that is what the green and red bars represent. You can see that the market is in somewhat of a balance, a lot of people buying and selling. This is a more liquid market. This is the order book, people/bots buying selling an asset pair XLM/BTC.

The so-called spread is the gap between the buying and selling side. In this case, it’s really small, with on one side 0.0000082 XLM and the other 0.0000083 XLM. The spread, in this case, is 0.0000001 XLM. We’ll get to why the spread is important in regards to market-making bots in a later section.

XLM/BTC on StellarTerm

You can imagine that every exchange has its own order book, that’s why the price of each asset differs from exchange to exchange. The price of an asset is mostly defined where the bid and ask orders meet. In low liquidity markets or on low liquidity exchanges the stability of the price is thus not guaranteed and isn’t safe to trade on. Price jumps can occur very rapidly if the bid and ask prices are far from each other. Users that don’t understand the market or don’t understand market/limit orders will mostly pick market orders, which is the lowest ask price, but in reality, can differ a lot from the real price you think the asset is listed at.

The Liquidity Problem

I’m not going into this matter too deeply because Nikhil Saraf already did a good explanation in another Medium post on the creation of Kelp. The ability to trade one good for another is the main thing that describes market liquidity. There’s a market for everything and with ‘market’ we mean a place to trade good A for good B. Not every market is liquid, meaning that sometimes it’s not so easy to find people who want to trade goods with you. Take for example the market USD/bread, you can trade your dollars for bread in almost every shop you come across. This is a very liquid market because there are a lot of people selling bread and a lot of people buying bread. An illiquid market is let’s say gold/bread, I’m not sure if there are even places you can sell your gold for bread, there are no sellers that sell bread and want gold. It’s hard to trade assets in illiquid markets.

Let’s look at another example of a market on the Stellar Dex, Citron/Stellar XCT/XLM. This represents people buying XCT and selling XLM. You can see that this market is not balanced and illiquid. The total amount that people/bots want to buy is 355 XLM against the total that people/bots want to sell is 2094610 XLM. The spread is also really big, meaning there’s little chance of buyers and sellers meeting each other to do an actual transaction. This is why a liquid market is important. Illiquid markets are rather stale, no one is meeting each other in terms of selling and buying and the price is not stable. Keep in mind that the bid (buy) price is always lower than the ask (sell) price, if they cross each other, a transaction will take place. There’s always a gap between the buying side and selling side, the spread.

If no one is selling on the Stellar Dex, no one can buy and vice versa. This is the liquidity problem and Kelp is going to help to solve this.

XCT/XLM on StellarTerm

What can we do about the liquidity problem on the Stellar Dex you say? We can create liquidity. We can make automated buy and sell offers so that people are willing and able to trade on it. What’s in it for me you ask? We’ll get to that with potential arbitrage opportunities!


Let’s get to the spread of the order book and what market-making is all about. In order to create liquidity, you can run a market-making bot, such as Kelp. It will automatically place bid (buy) and ask (sell) orders on each side of the order book to create liquidity. The more orders there are, the more stable the price. Market-making theoretically results in profits being taken from the bid-ask spread of different assets. Let’s say you have 3 markets, ETH/BTC, USD/BTC and USD/ETH. They have the following prices for each pair.

  • 1 BTC / 10000 USD
  • 1 ETH / 0.02 BTC
  • 202 USD / 1 ETH

You can buy 1 BTC for 10000 dollars, sell that 1 BTC for 50 ETH and sell that 50 ETH again to get 10100 dollars. This is possible due to the spread being different in every market. This is why market-making bots create liquidity and are incentivized to do that by taking small profits from the orders they make on the same exchange. Running market-making bots also ensure that you are following the spread on each side of the order book if the price increases or decreases. So you are buying more when the price increases and sell immediately if the price decreases. This is an intra-exchange arbitrage opportunity.

An inter-exchange arbitrage opportunity can be obtained by doing trades between exchanges based on the price difference on those exchanges. These are caused by different order books as explained earlier. It follows the same principle, it’s possible to buy at a lower price on one exchange and sell it again at a higher price on another exchange. There’s no 1 absolute price for an asset, everything depends on the exchange it is traded on and the order book that decides on what the actual price of that asset is on that exchange.

Kelp Trading Bot

There are a few ways to run Kelp. It’s possible to run it with the provided binaries on GitHub. It’s your choice how to run it, whether it’s in Docker, on Kubernetes, or on your own computer with the binaries.

I’ve run Kelp for a few months on Kubernetes. I was not able to build the Dockerfile included in the Kelp repository, so a made a Dockerfile myself.

Dockerfile Kelp

In order for this container to run on Kubernetes, a deployment.yml is needed as well as a configmap.yml for the configuration. If you are not familiar with Kubernetes, you can just focus on the 2 files trader.cfg at line 9 and balance.cfg at line 70. There are different strategies that are explained in-depth on the GitHub page of Kelp, we’ll focus on the balanced strategy. The trader.cfg file contains the information Kelp needs to know, what to trade, and where to trade. The balance.cfg file contains a particular strategy and thus explains to Kelp how to trade. In this example, Kelp will start trading on the market XLM/USD. The ISSUER_B is the public id of the provider of that asset, in this case, AnchorUSD. I’m not going into too much detail, the documentation of Kelp covers each setting in detail as well as other trading strategies that can be used.

Kelp configmap.yml

If you don’t plan to run Kelp on Kubernetes, you can skip the following file. In order for Kelp to run it needs a Deployment. This starts up kelp from the previously created Docker container of the Dockerfile. Feel free to use your own image if you have created it. This Deployment will deploy 1 pod in the kelp namespace that is going to run Kelp with a balanced strategy.

Kelp deployment.yml

Running Kelp is not without risks of course. You’re dealing with a piece of software that is executing real trades on your behalf. Any software glitch may cause potential losses. Price fluctuations of certain assets are also something to keep in mind. You could have a profit from each trade but if the valuation of the token you are trading plummets, it does not really profit you in any way. Market-making is also one of the more difficult ways to trade in my opinion. Everything depends on the order book and how fast you can react on bid or ask orders being created. Some people out there are willing to throw in a lot of money to be as close as possible to the servers of the exchange and want to have the best internet speeds to execute orders at blazing speeds. Be careful out there, always educate yourself first, read the documentation, and start out with a minimal amount of money. Never invest money you can’t afford to lose.

If you start Kelp on for example StellarTerm and you log in, you can see the buy and sell orders Kelp has created. It always tries to maintain a spread percentage (that can be defined in the balance.cfg file shown before), by calculating the distance from the middle of the order book where bid and ask orders and thus buyers and sellers meet.

StellarTerm buy and sell offers done by Kelp

In order for you to easily keep track of what Kelp is doing, you can download Solar Wallet on your computer and see your balance, buy and sell orders in real-time. You just have to add XLM on there and exchange half of it for USD (or EUR, whatever you prefer) in order for the balanced strategy to do its job. The balanced strategy is one of the strategies you can use as explained before. There are also other available strategies. Carefully read the documentation before running a different strategy.

Solar Wallet

The Stellar ecosystem needs liquidity to guarantee a stable price. Bringing liquidity to the Stellar Ecosystem ensures that it’s mature enough to be used by everyone. Stellar has amazing potential, besides a currency, the Stellar Dex can be used already to trade a lot of different assets.

Kelp can also be used outside of the Stellar Dex, it can trade on Binance for example by integrating with CCXT, a cryptocurrency trading library. If you’re interested in also running CCXT as a Docker container besides Kelp, the following Dockerfile can help you. You can also run CCXT on Kubernetes the same way as you would run Kelp with the Docker images.

Dockerfile CCXT
CCXT and Kelp docker-compose.yml

The above docker-compose.yml file runs Kelp alongside CCXT, this is needed if you decide to not run Kelp on the Stellar Dex, but on, for example, Binance.

Anyone who likes algorithmic trading, setting up applications, and playing around with cryptocurrency can set up Kelp. You’ll learn a lot about market-making, liquidity, and trading bots.


Kelp is a market-making bot that can provide liquidity in certain markets by placing bids and asks on either side of the order book on supported exchanges. This solves the liquidity problem because it’s hard to trade your assets in illiquid markets. Liquidity provides a stable price but also minimizes your intra- and inter-exchange arbitrage opportunities because of the price difference on each exchange. The price of each asset differs from exchange to exchange due to buyers and sellers not meeting each other in the middle of the order book. At some exchanges, buyers are a little less picky and the price may be higher and vice versa. Intra- and inter-exchange arbitrage opportunities can arise by trading on the spread of the order book on the same exchange or trading the same assets across different exchanges. Kelp provides liquidity and potential profits, but beware, always do your due diligence and don’t spend what you can’t afford to lose.

This content was created as part of a Stellar Battle.

Conveying information about high-end technology and science.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store