Stellar DEX is one of the most important features of the Stellar protocol. It enables transparent asset exchange without trading fees and eliminates the ability of the exchange owners to manipulate the price without significant capital commitment. It gives all participants equal information and equal opportunities.

Why is it not among the most popular crypto exchanges? Every exchange has the chicken and egg problem, you can’t really trade by yourself. You need a number of other people trading to make it worthwhile, have good spreads and enough liquidity to complete your trade. And since almost nobody is trading — it doesn’t make much sense for a new person to join.

Current trading volumes are extremely low

How to kick-start an exchange?

The first group of participants, that is required are market-makers (MM). They place some offers on both sides of the orderbook and become a counter-party to trades made by other users. Market makers earn money on a spread. For example, if the market price for 1 BTC is 160,000 XLM, then one market-maker could sell BTC at 160,500 XLM, and buy back at 159,500 XLM. Another market-maker has more capital, so he can offer 2 BTC at 161,000 XLM each and buy back at 159,000 XLM. Even though his price is worse he can still get some trades from users who want to buy more. A third market-maker may not have that much money, so to get any trades he’s forced to set his prices lower than the first two, at 160,400 and 159,600 XLM. Competition between market-makers drives spreads down and makes it cheaper for users to exchange back-and-forth.

The second group of liquidity providers is arbitrage traders. They place their offers on multiple exchanges in such a way that allows them to buy the asset cheaper on one exchange and then sell it more expensive on another exchange. For example, the price on Kraken or Binance has moved and 1 BTC = 161,000 XLM there. An arbitrage trader can buy 1 BTC on Stellar DEX at 160,500 XLM and sell on Kraken at 161,000 XLM. But you need to act fast before someone else does. Usually, there is no time to wait for withdrawal from Stellar and deposit to another exchange, so good arbitrage traders keep a balance on multiple exchanges to be able to act immediately when they see the opportunity. By trading the difference between exchanges, arbitrage traders reduce that difference to 0 making sure that price is the same on all markets. On Stellar you can also trade arbitrage between the same asset provided by different anchors, such as BTC issued by apay.io and BTC issued by naobtc. Another way of risk-free arbitrage trading on Stellar is by sending a path-payment to yourself. You can specify that you’re sending 1 XLM and want to receive 1.001 XLM. Such payment will usually fail but sometimes may succeed.

Finally, there are other participants on the exchange:

traders, who bet on the price going up or down

merchants, buying their local currency by liquidating any currencies they’ve accepted as a payment

other businesses, who might be exposed to some currency risk and want to hedge their position against a price change

users, who just come in once a month to get rid of one currency and buy another currency

The more participants and the more money is in the exchange — the better it is for all the participants.

Evolution of liquidity providers on Stellar

Since the launch of the network anchors and developers were almost the only market-makers on the DEX, but all of them were individuals or small companies with very limited resources.

At apay.io we used SBC prize from 2017 for market-making, but it’s not a significant amount of money and eventually, that pool goes away as we need to pay salaries to our team. We also had a couple of companies hiring us for market-making their tokens.

No professional market-makers or financial institutions were looking at Stellar, because there wasn’t any money in it yet. That should change when trading volume improves.

Up until 2019, liquidity on Stellar DEX has been largely neglected by SDF. They hoped for it to form organically, but that didn’t work out. Since last year they started to attract professional firms to participate. They’ve been also developing kelp, a tool that can automatically execute your trading strategy on stellar.

kelp GUI

It’s aimed at technically-savvy users, who can understand a prebuilt strategy (or even modify it / create their own strategy), run one or more instances of the bot on an always-on computer or server and setup monitoring to react in case bot stops working or misbehaves. While it’s quite powerful it’s not really accessible for most of the users.

Mister Ticot came up with another interesting and powerful tool equilibre.io.

Portfolio overview

It’s aimed at non-technical users, who only need to set up their portfolio once, for example, 50% USD, 30% BTC, 10% ETH, 10% XLM. After that, you need to regularly visit the website (once a day or once a week). The tool does all the job for you by monitoring balances, prices of all portfolio components and prepares transactions for you to sign. For example, USD went down in price, compared to other currencies you have, so your proportions are no longer 50, 30, 10, 10, but 40% USD, 35% BTC, 12.5% ETH and 12.5% XLM instead. Equilibre is going to offer you a transaction to sign, which sells some calculated amount of BTC, ETH and XLM, and buys USD. You can verify that everything is correct, and once you execute that transaction — your portfolio will get back to defined proportions. It uses just one defensive balanced strategy, which is not meant to make you a lot of money, but rather protect you from price fluctuations, especially when your portfolio consists of different asset classes, that won’t go down together.

Apay MM bot

At apay.io we’ve been looking for ways to simplify it even further for our users. We’re actively building an open-source trading bot now, that uses the same balanced strategy, doesn’t require manual involvement and eliminates most of the choices. We’re going to host it ourselves, take care of monitoring and maintenance.

From the user perspective it becomes extremely easy:

you deposit funds to a special account and get a token in return (it’s needed to keep track of your share in the total balance of the bot)

you hodl, any time you can check bot’s performance and calculate how much funds can you get back.

bring back the special token and get your share of bot’s balances.

How it works?

It’s inspired by the uniswap protocol, bot uses multiple accounts, each account for 1 currency pair. It calculates the price of the pair as ratio between its balances. For example, it has 1 BTC and 7000 USDT. Its median price will be 7000/1 and offers set with the spread on both sides from the median. Offer amounts must be low, to make sure that after the trade newly calculated median price falls within the spread of previous trade.

blue triangles indicate offers created by Apay MM bot

Following this simple algorithm bot slowly accumulates both balances. From my tests and previous experience it adds up to as much as 3–5% per year. (It’s is of course in no way guaranteed, past performance is not indicative of future results). At the same time while it’s a custodial solution — it does not increase your trust requirements compared to using kelp or equilibre, because even if you use those tools — you still need to trust an anchor for assets you hold in your portfolio. If you already trust apay.io your only new risk is the algorithm, which is open-source and ready for critics.

Example with numbers

Let’s say bot is already running on BTC / USDT pair.

It’s balance 1 BTC and 7000 USDT. 100 APAYBTC tokens issued to users who already deposited some funds. It trades around 7000/1 median price.

Alice comes along and makes a deposit of 0.1 BTC and 700 USDT. It does not affect the price, it is still 7000/1. APAYBTC value before the deposit is 0.01 BTC + 70 USD, so 10 new APAYBTC tokens are issued to Alice.

Now bot balance is 1.1 BTC and 7700 USDT, 110 APAYBTC tokens issued, each token value 0.01 BTC + 70 USDT.

Now let’s say BTC price slowly rises to 14000/1. After trading back and forth bot’s balance becomes 0.76 BTC and 11715 USDT.

Alice comes back to redeem 10 APAYBTC tokens, she receives 0.069 BTC + 1065 USDT (her share is 10 out of 110 tokens, which is around 9% of total bot balance). As we can see Alice got 0.031 BTC less than was deposited, but 365 USDT more and at current rate 365 USDT is more than 0.031 BTC * 14000 = 336 USDT by 29 USDT or around 2% more than original deposit.

The best thing of all — you get similar result in case if BTC price drops to 3500/1. You will get more BTC, less USDT, but total output value should exceed the value of your deposit.

Conclusion

Stellar DEX desperately needs liquidity to achieve its mission and as a community we can help with that. Previously it wasn’t easy to participate in market-making, but with the service we propose everyone can take a part. Look how Uniswap does it for Ethereum, liquidity has grown from 300k to 44 mln in just 15 months.

uniswap total liquidity taken from uniswap.info

In addition to market-making this bot attracts arbitrage traders, because it creates a lot of opportunities for them to profit.

While helping broader ecosystem to grow and achieve its goals users can also earn some 3–5% a year on their deposits regardless if market goes up or down.

Let’s pool our resources together!