Kelp: Setup your first trading bot on the Stellar Network

Automated trading systems and trading bots like Kelp, are a quite an important concept in the financial markets, specially in the Cryptocurrency space. When you are trading any type of assets on a decentralized or centralized exchange, there is a chance that a trading bot is the one dealing with your offer. Strategies can be used across different exchanges (inter-exchange) or within one exchange (intra-exchange). Trading bots are becoming very popular specially for companies that are looking into having a better control over the liquidity of their order books by automatically generating orders based on predefined set of rules using a particular trading strategy. Currently Kelp supports only the Buysell Strategy, but you are free to setup your strategies using your own code.

The main goal of setting up a trading bot is to possibility a more liquid order book. In this blog I will explain what Kelp is and will provide a high end tutorial about setting up a Kelp bot using Ubuntu Windows Subsystem for Linux V2, so you can start testing your own trading strategies.

What is Kelp?

Kelp is a free, customizable, open-source trading bot for the Stellar universal marketplace. It also has a command line which allows you to create new trading strategies using you own code. Kelp also has support for more 100+ centralized exchanges.

The importance of Liquidity

Liquidity is a key concept in the stock and cryptocurrency markets and usually refers to how easy it is for an asset or token to be turned into cash without affecting in a significant way the price of the asset. Its availability represents huge repercussions for token holders, traders and other interested parties. For this reason, it is of high importance for asset issuers to promote a heathy market that protect token holders, traders and exchanges from market disruption and manipulation.

Market makers and their role in providing Liquidity

A market maker is an organization or an individual who actively quotes two-sided markets in a security, providing bids and asks along with the market size of each. Market makers provide liquidity and depth to markets and profit from the difference in the bid-ask spread.

A market maker bot creates offers to buy and sell token on certain market and keeps a spread for a potential profit.




Order book depth chart on a currency exchange. The x-axis is the unit price, the y-axis is cumulative order depth. Bids (buyers) on the left, asks (sellers) on the right. (Wikipedia)

How to setup your first trading bot on the Stellar Network

Kelp offers an user friendly GUI (graphical user interface) which can be compiled on Linux, Windows and iOS. For this tutorial we are compiling Kelp on Ubuntu 18.04/Windows 10.

Before installing Kelp, it is necessary to install Windows Subsystem for Linux (WSL), which allows you run a Linux environment directly on your Windows 10 without the need for a virtual machine.

You do this by running the following command (as admin) on the Windows PowerShell:


Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Then by going to Windows Store and Installing Ubuntu 18.04 LTS.




After done, click on Launch, which will start the Ubuntu client. Then, add an username and password for Linux in the Ubuntu terminal. Once the user config is done, make sure to install Golang on your Ubuntu since is the language in which the bot was built.

You can get the latest version of Golang here: https://golang.org/dl/

We have downloaded Golang to our Ubuntu using the following command:

wget https://golang.org/dl/go1.15.1.linux-amd64.tar.gz

Once you have succesfully downloaded Golang, make sure to download the link of the Kelp binaries to run it on your OS. You can find the list here: https://github.com/stellar/kelp




In our case we will use the binary “kelp-v1.9.0-linux-amd64.tar” and we will use the following command to download the binaties (by copying the URL of the Binary) into our directory:

wget https://github.com/stellar/kelp/releases/download/v1.9.0/kelp-v1.9.0-linux-amd64.tar

Then you will see a file named “kelp-v1.9.0-linux-amd64.tar” on your directory. To extract the file to the current directory type on the terminal:

tar -xvf kelp-v1.9.0-linux-amd64.tar

Then you can proceed to enter to the folder kelp-v1.9.0 with the following command:

cd kelp-v1.9.0

And proceed to execute the binary with:

./kelp

During the installation you will need to grant Kelp access your firewall so that the application can talk to the ccxt server.




Kelp uses CCXT to enable access to more than 100 centralized exchanges. To make sure that CCXT was properly installed in your system, you can run

If the response returned is an array of the different exchange names available on CCXT, then the CCXT server was installed correctly.

If you are experiencing an creating window failed: canceller.cancelled error, try the following command on the terminal:

./kelp server --no-electron

The terminal will proceed to load the application and will display a live feed of the current operations happening on the sever.




CCXT will take port 3000 and Kelp should open on http://localhost:8000/




If you manage to reach this screen, congrats, you have succesfully compiled Kelp on your machine.

Managing your Bots

By clicking on “Autogenerate your first test bot” the bot will be created. It will automatically generate a new secret key and execute the relevant trustlines.




As we can observe, the autogenerated bot with a "BuySell" strategy will start to initialize on the Stellar testnet. The bot will display the markets and the balances for this parcular bot for those tokens.

If you would like to see the issuer of the base asset, you can do it by hovering on the "i" icon.



The first option called "Show Offers" will redirect you to the status of the offers on Stellar Expert



The second option called "Show Market" will allow you to see the current BuySell spread on Interstellar.exchange



The third option called "Edit" will allow you to see and edit the details of the autogenerated bot, incluidng the Public Key, the base asset and the quote asset code.



Kelp allows the creation of Bids and Asks at different prices and levels. A Bid allows us to buy the base asset and sell the quote asset. An Ask is an offer to sell the market pair or selling the base asset and buying the quote asset. Quote assets are basically any token available on the market.

Bellow, at the "Strategy Settings", we will be able to setup the details of our BuySell strategy.



The Bot takes the Numerator price of the base asset (in this case XLM) and divides that by the Denominator to calculate the final price. This will allow us to price both assets differently but in the same units. We also have the possibility to refresh the prices to see current price which will be used by the bot.

On "Current Price" you will be able to see the explaination of how the pricing of the asset works.

Below, we can see the 4 different levels that the bot uses.



The levels represents the change in percentange that a price must variate form the center price to perform the operation related to the amount added to the field.

Finally, we are able to start the bot by clicking on the button "Start". Please keep in mind that as long as the bot stays running and the program open, the offers will be active and they will consume as soon as the price changes according to the details of the strategy in the bot configuration. So if you would like to stop your current offers, make sure to cancel the current offers by clicking on "Stop" or simply by quitting the application.



Risks

I hope that this article was useful, but remember that this article is for educational purposes only and is intended to be a guide to be used on the Stellar Tesnet. Any attempt of trying Kelp on live environments might be contraproductive and might generate capital losses, so please be careful and make sure you know what you are doing when using automatized trading systems.

Conclusion

Kelp is the most innovative automated trading systems in the cryptocurrency space and its main goal is to solve the issue of liquidity which most of the projects in the industry face. The beauty of Kelp is that it is not only available on the Stellar Network but also allows to any developer to start developing their own trading strategies which they could potentially apply in any of the more than 100 centralized exchanges which Kelp provides access to.


This article was created as part of the Kelp Overview Battle organized by StellarBattle

Resources

[1] Github repository: https://github.com/stellar/kelp

[2] Kelp GUI: Your First Automated Trading Bot: https://www.youtube.com/watch?v=_UDZfcQWOYg&feature=youtu.be

[3] Engineering Talks - Kelp GUI: https://www.youtube.com/watch?v=zxBoERxZcQs

[4] Understanding Liquidity Risk: https://www.investopedia.com/articles/trading/11/understanding-liquidity-risk.asp

[5] Market Makers: https://www.investopedia.com/terms/m/marketmaker.asp