Apay MM bot for Stellar DEX is ready!

umbrel
Apay.io
Published in
6 min readMay 13, 2020

Hey Everyone,

I’ve integrated the ability to commit funds to our market-maker bots in the new interface at beta.apay.io and it’s time I explain what it does in more detail.

Why is it important?

I made an introduction to the problem in my previous article

Today markets on Stellar DEX are illiquid, you can’t exchange 1000 USD to BTC without significantly moving the market, some pairs have spread (the difference between buy and sell offers) 20% or more. These factors prevent people and companies from using the DEX, as it just doesn’t provide a good price or can’t handle the volume of the exchange.

In its current state Stellar can’t fulfill the primary use case of small Nigerian business sending naira to a Chinese supplier, who’s going to receive yuan at their end, because the exchange will cost them too much to be able to forget about it. At the same time, You (users) have funds lying around in wallets, that can be used to offer liquidity to the market and earn you some trading fees.

I think at this stage attracting liquidity to Stellar is the most important step in the ecosystem development, that’s why I’ve made this bot inspired by uniswap protocol and running it free of charge for everyone to participate.

Check out price comparison between Changelly and beta.apay.io

XLM to BTC using beta.apay.io
XLM to BTC using changelly

It is competitive on XLM / BTC pair, price is just a little bit worse and sometimes even better using Stellar DEX.

This is because there is at least $10k in BTC market-maker.

Try the same with a larger amount and you will see how quickly Stellar starts losing. However, if we succeed in attracting x10 or x100 liquidity, you can forget about using anything else.

Check out another example XLM / BAT.

XLM to BAT using beta.apay.io
XLM to BAT using Changelly

This pair doesn’t come close even on small amounts, that’s because there is only $2k in BAT market-maker and I don’t have more money to put into it.

That’s exactly why we need your help! If you are holding some of the supported tokens — consider using it to make markets.

How it works

The bot operates multiple Stellar accounts, each account is used for 1 trading pair. Here’s the list of currently active accounts:

Update from 24.05.20: we’ve also created a market-maker bot for Ternio community

The choice of currency pairs is quite important, as it provides a minimal level of diversification. You won’t lose all your funds whether crypto markets go up or down. This wouldn’t be the case if you had to hold let’s say XLM and BTC, as they both go up and down simultaneously.

The bot operates with two balances. It calculates the price as a ratio between balances and sets offers on both sides of the orderbook with increasing spread.

Let’s take for example XLM / USDT. Balances are 160,000 XLM and 8000 USDT. Median price will be 8000/160000 = 0.05 USDT for XLM. It will set up offers to sell 100 XLM at 0.0501, 200 XLM at 0.0502, 300 XLM at 0.0503, 400 XLM at 0.0504, … and offers to buy XLM at 0.0499, 0.0498, 0.0497, 0.0496…

The amount used for these offers has to be small (1–2% of the total balance of the bot), let’s say $160 total in our case. This is important to make sure that balances don’t change too much when a trade occurs.

Now XLM price on other exchanges goes up to 0.0502 USDT / XLM and a trader thinks that buying at 0.0501 from the bot is a good deal as he can sell it more expensive somewhere else.

Trade has been executed and the bot now has 159900 XLM and 8005.01 USDT. New median price recalculated as 8005.01/159900 = 0.0500626 and offers set up to sell XLM at 0.05016, … and to buy XLM at 0.04996, …

Now external price goes down to 0.499 and trade happens in another direction, bot balances become 160000.2 XLM and 8000.01 USDT, the median price comes back to the previous level 0.05.

As you can see with every pair of trades up and down bot earns 0.000125% of its balance. if it happens 50–100 times a day for a year it compounds to 3–4% annually. And in general, this strategy makes sense, as you sell an asset when it becomes more expensive and buy it when the price falls.

I’ll repeat once again here, returns are not guaranteed and you should assess the risk yourself and bear full responsibility for your decision to participate.

How to commit funds

The new section is located inside “My account” on beta.apay.io, sign in with your public key or federated address and scroll below the list of balances.

Market-making section of “My account”

For each trading account, we also have a “manager” account, that accepts payments from users and issues special tokens for accounting.

Let’s say the bot already has 160,200 XLM and 8005 USDT and previously issued 8000 APAYXLM to users.

The current unit price of APAYXLM is 20.025 XLM + 1.000625 USDT.

Screenshot from beta.apay.io shows how to commit funds
beta.apay.io helps to create the required transaction

A user has to transfer funds in the same proportion, for example, 40.05 XLM + 2.00125 USDT, to get 2 APAYXLM tokens. Our new interface on https://beta.apay.io can help with that, it generates a transaction for you to sign, which adds a trustline and sends both assets to the manager account using memo unique to your account.

Once we spot payments to the manager account that haven’t been processed yet — we will show you the following action, where you have to accept Terms and Conditions to proceed.

Refunds are manual for now, contact support@apay.io to get your funds back if you’ve sent something to manager account, but don’t want to proceed.

When funds have been sent you need to agree to terms and confirm the deposit

Then you will receive some tokens and will be able to monitor the changes in unit price.

monitoring USD value of your funds put into MM bot

Don’t worry if you send more of one asset or rate changes while you’re signing the transaction. When the manager account issues tokens, it will maximize the amount you can get by fully using one asset and a proportional amount of another asset according to the current rate, the rest will be refunded back to you.

How to redeem funds

The redemption process is similar, you need to send tokens back to the manager account and press a button to get your funds transferred back to you.

Feedback

Let me know if you spot any gap in my reasoning, bug in the code, or just want to suggest an improvement.

If you’re an asset issuer consider running my code to make your markets liquid or talk to me about running it for you.

--

--