Blog Article

Kelp: Why We Built It — The Liquidity Problem


Nikhil Saraf

Publishing date




Stellar has a near-zero-fee Decentralized Exchange built into the protocol, which allows you to trade any token pair and list your tokens without any listing fees or restrictions.

Like all exchanges, the Stellar Decentralized Exchange is faced with the liquidity problem: there have to be enough people putting out “maker” offers or it will be hard to buy or sell a token. This problem can be solved with the help of market makers who are willing to place bids and asks for the possibility of a profit from the bid-ask spread.

To help market makers automate bids and manage spreads, we developed Kelp, a 100% open-source market-making and trading bot, built for the Stellar Decentralized Exchange and written in Golang. With Kelp you can get up and running with a functional trading bot and trading strategy on the Stellar Decentralized Exchange or on centralized exchanges in a matter of minutes. You can also write your own trading strategies and custom exchange plugins. See walkthroughs for Kelp’s trading strategies to help you get started. You can download the latest binary release of Kelp (v1.7.1) here.

The Liquidity Problem

Any exchange is a marketplace for buyers and sellers. If everybody wanted to buy and nobody wanted to sell, there would be no trades. Conversely, if everybody wanted to sell and nobody wanted to buy, then again, there would be no trades.

The issue faced by all exchanges is one of Liquidity. When you want to sell your token, there needs to be somebody else who is willing to buy your token at a price that is acceptable to both of you. It is not always the case that two traders want to take an opposing view of a given asset (buy vs. sell) at exactly the same price and exactly the same time. Without this, we just have emptiness. To be clear, on an illiquid exchange you will likely find worse prices as a result of the sparsity of offers and wider spreads.

An exchange without liquidity is like a barren land

Investopedia describes the general problem of liquidity very well.

Exchanges need somebody who is willing to be the first person to name a price to buy or sell an asset. This brave soul could be very wrong on how they have priced their offer and could end up selling their asset for much less than what it is worth — or buying it for much more than it is worth. Moreover, this daredevil could end up waiting for hours without anybody coming along to trade with them. As risky as this sounds, there are some that choose to do this — and find a way to make money while doing it!

Enter the Market Maker

The market maker is an entity that is consistently one of the first to name a price to buy or sell an asset (using a “maker” offer) in the hopes of making a profit on the spread or when reversing the position they hold.

Wikipedia defines a market maker as such:

A market maker or liquidity provider is a company or an individual that quotes both a buy and a sell price in a financial instrument or commodity held in inventory, hoping to make a profit on the bid-offer spread, or turn.

When you name a price on a market that is empty you are posting an offer to the order book, i.e. you are placing a “maker” offer. In doing so, you are allowing someone to trade with you at a price of your choosing. However, if someone trades with you by placing a “taker” offer, they will have made that decision to trade with you after knowing that you are willing to trade with them.

In other words, when placing a “maker” offer you are revealing to the broader market your intentions of demand (or supply). Others could factor this in when thinking about the price of the underlying asset and could possibly exploit your offers for their own profit (and your loss). Thus, by placing a “maker” offer you are always incurring what is known as adverse selection — when others with more material information trade with you to exploit your trading strategy.

Why then, would someone take on the role of the market maker?

Armed with the ability to set the prices on the market, the market maker would typically quote a higher ask price than their bid price (as opposed to using the same price). That is, they would maintain a spread so that if both their bid and ask offers are executed then they would be left with a profit equaling the spread, assuming the same order size for both offers. There are many considerations to take into account when setting this spread, such as the fee on the exchange, existing trading volume, cost of capital, assets being traded, asset inventory risk, counterparty risk, current market volatility, etc.

A seasoned market maker would be able to evaluate the above risks and come up with a price at which to buy and sell the asset pair, and therefore the spread they can afford to offer on the given market. Thus, market makers are compensated for the liquidity they provide on the market in the form of profits from the spread or from reselling the assets they acquire as part of their market-making activities.

The Market Maker

Why We Built the Kelp Automated Trading Bot

When trading manually, or “click trading”, you may find that you are not fast enough to execute your trading strategy, or that you let emotions come in the way of your strategy, or just simply that you cannot do this 24/7 — you have a life! This is where automated trading bots can be very useful. They help you automate the execution of a trading strategy. This may not always be a good thing because if your trading strategy loses money then by automating it you will only lose money faster. It’s important to pick a good trading strategy, one that works for you, and monitor it to see whether you are getting the results you expect.

There are many market-making and trading bots out in the wild. However, when we started thinking about liquidity on the Stellar Decentralized Exchange, most of the market-making and trading bots we came across were either proprietary, were not super-reliable, or were not built for market-making. We had a specific set of requirements when we were thinking about trading bots on Stellar:

  • The bot should be 100% open source.
  • The bot should be written in a language that is easy to learn, reliable, and fairly performant — this cut out C/C++, Rust, Nodejs, and Python and we eventually landed on Golang.
  • The bot should be designed in a manner that makes it easy for others to build on top of and to create their own trading strategies.
  • The bot should be robust enough so it can monitor your offers and keep them in check, running uninterrupted 24/7.

With these requirements in mind, we built Kelp and open-sourced it in the summer of 2018. Kelp is a free and open-source trading bot for the Stellar Decentralized Exchange and for centralized exchanges that includes several configurable trading strategies and exchange integrations. You can define your own parameters or use the sample configurations to quickly get up and running with a trading bot in a matter of minutes. The modular design allows you to easily create new trading strategies, exchange integrations, and token markets to give you full control. So far we have seen over 1,600 downloads across the many releases of Kelp over the past year.

While you are solely responsible for determining and executing your own trading strategy, there are three market-making strategies that could be launched with the Kelp trading bot out of the box:

  • buysell strategy — creates buy and sell offers based on a specific reference price and a pre-specified liquidity depth while maintaining a spread.
  • balanced strategy — dynamically prices two tokens based on their relative demand. For example, if more traders buy token A from the bot (the traders are therefore selling token B), the bot will automatically raise the price for token A and drop the price for token B.
  • mirror strategy — mirrors an order book from another exchange by placing the same orders on Stellar after including a spread.

See the full list of strategies available on Kelp. You can also see walkthroughs for each of these strategies to help you get started. We strongly urge you to thoroughly research and analyze the guides, strategies, and markets to understand and manage the risk of using Kelp.

You can download the latest binary release of Kelp (v1.7.1) here. We have a UI for Kelp that will be coming out soon, which will make it much easier to use Kelp, so look out for that!

Disclaimers: Kelp is not for beginners. You may lose large amounts of money using Kelp, and you are solely responsible for the legality and consequences of your trades, strategies, and activities. SDF does not and cannot provide any guarantees or assurances regarding Kelp, including without limitation any guarantees or assurances that Kelp will function reliably, securely, safely, or for any intended purpose.