About six years ago, I went out to launch with a good friend of mine to escape the awful food at our workplace. He casually mentioned he made good money buying and selling cryptocurrencies on a local exchange.
At the time, I did not know much about how markets and cryptocurrency exchanges work. Naturally, I was skeptical of the idea of making easy money. But the numbers were real, and coming from a programming background I offered to automate the trading. Since then, I’ve had a lot of experience in the field, and would like to share some lessons and common pitfalls I’ve encountered during this time.
This article is intended as an overview of the field. I will explain general concepts, strategies, pitfalls and ways of automating trading tasks.
How Markets Work — General Concepts
Order Books
On every public market, there are buyers and sellers. People write down how much they’re willing to buy and sell, and at which price. This information is saved on the Order Book, which contains all the open orders people made.
If two people agree on a price, a trade is made and the broker gets an agreed upon fee. The rest of the order book contains the open orders which did not find a match. A typical Bitcoin to USD order book will look like this:
Spread
Every listing includes the price, amount (In Bitcoin) and price per Bitcoin the person is willing to pay. As you can see, there’s a price difference between the buy and sell orders. This difference is referred to as the spread. Generally, the more volume the pair has, the smaller the spread will be.
Makers and Takers
People who buy from available offers on the order book are called takers, because they take liquidity from the order book, and increase the spread.
Conversely, a maker is someone who puts down his own offers and waits for others to take them. Makers often get much smaller fees than takers, because they reduce the spread.
If the spread is big enough to cover the fees, you could potentially make money by putting both buy and sell orders. This is called market making, and essentially it’s the technique my friend used 6 years ago.
Arbitrage
In the cryptocurrency world in particular, there are a lot of different exchanges with different order books. Right now, I can buy Bitcoin at cex.io at a rate of 6200$, and sell it on bitfinex for 6300$, making a whopping 2%! Easy money, right? This price difference is called arbitrage, and is not as easy as it seems. I will explain why in the next section.
Pairs
A pair is a pair of two coins which are traded with one another. For example, common pairs are BTC/USD, which means selling bitcoin for US Dollars, or ETH/EUR, which means selling Ethereum for euros.
Price delays
Usually, larger exchanges calibrate their price quicker, and smaller exchanges follow after them. This means, that you could predict the price on a small exchange by looking at a bigger one if you’re fast enough.
This requires a more complex platform, because you need to be aware of prices on multiple exchanges and react quickly enough, so it’s only possible with software.
Triangular Arbitrage
Sometimes there’s a price difference between pairs in the same exchange.
For example, if we can buy Bitcoin on BTC/USD for 1000$, sell on BTC/EUR for 900€, and exchange the Euros for 1020$. In reality, the difference is smaller and you have to account for the triple fee for the transaction.
Knowing this, let’s review the options for making money exploiting price arbitrage:
- Exploit arbitrage between exchanges, also called inter-exchange arbitrage.
- Using Triangular Arbitrage
- Market making on a pair with high spread.
- Exploiting price delays.
Intra-Exchange Arbitrage Pitfalls
People often see the price difference between exchanges and think they found their golden ticket. However, making money from this difference is not trivial often a reason for it. This is especially true when dealing with FIAT currencies, such as US Dollar, Russian Rubble and the like. Let’s review what we need to do to profit from this:
- Buy bitcoin on cex.io at 6200$ and pay the fee of 0.16%, which leaves us with roughly 6215$.
- Pay bitcoin withdrawal fee and transaction cost on cex.io, which is negligible.
- Move the bitcoin from cex.io to bitfinex. This requires a bitcoin transaction, which can take roughly 10 minutes.
- Sell the bitcoin on bitfinex for 6300$, which after the 0.2% fee is roughly 6290$.
Most people think the deal ends here, and we just made more than 1% in 10 minutes. However, there’s a subtle this is the ideal situation and several things could go wrong, losing you money:
- During the transaction period the price may change drastically, and when it does you can lose a lot of your money. This time can be reduced by working with faster coins like Litecoin or Dash, but then you have to make additional trades which may take time and more fees.
- When scaling this to larger sums of money, your orders will drive the buy prices higher, because demand goes up. On small exchanges, this change will be significant and you’ll find it’s not profitable to buy more than a certain amount.
- Fiat(USD, EUR, RUR etc.) currencies are valued differently across exchanges. This is caused by different fees on deposits and withdrawals, because you have to make a bank transfer to withdraw this money. If an exchange has a 5% higher withdrawal fee on USD for example, the price of all coins in USD will be 5% higher on that exchange.
This means you’ll have to pay the fee to get your money back, and is the main factor for the price difference between exchanges.
This makes arbitrage more complicated than it first seems. So before attempting to make money this way, think of the steps you’ll have to take, the risks and fees in each step, and validate the risk is worth the reward.
Avoiding transaction times
One way to avoid the transaction times, is keep a balance of both BTC and USD on two exchanges. Assuming you found a price gap after factoring in the fees, you could make two opposite trades — buy bitcoin at the cheaper exchange, and sell on the same amount on the expensive exchange. This will net you an immediate profit.
You may fail to execute the opposite trade at a good price since the market is constantly moving, but it reduces the risk significantly. If you have several coins you’re willing to hold, I recommend doing this.
Let’s Trade!
Manual trading
So you found an exploitable price gap in an exchange or between exchanges. You now need to open an account on each exchange and insert some money into it.
Sites provide a web interface to manage your orders and balance. If you’re getti with dizzy from using too many sites, consider using a platform like Coinigy, and trade on multiple exchanges from the same site.
Unfortunately, trading manually can take a lot of time and you will find you’re often overrun by bots. Due to the nature of the order book, the order with the highest buy price is executed first, so bots which can place multiple orders every seconds can always outbid you by a penny and your order will not be executed.
Additionally, when the price moves, it can move FAST. I’ve seen coins go up and down upwards of 15% of their price in 5 minutes, and unless you’re the flash you’ll struggle to keep up with the changes at the volatile times,
Automating trading
To avoid the downfalls of manual trading, we can use a bot to run our strategies. A good in depth overview of available free and paid bot options can be found here.
However, most of the available solutions work on the same exchange and ignore prices on other exchanges.
Don’t put all your eggs in one basket
One of the greatest risks when trading on multiple exchanges, is that the smaller and more questionable exchanges can make the best revenues. However, exchanges are often hacked or downright scam people, and I would advise to split your money somewhat evenly between multiple exchanges to reduce risks, and avoid keeping your money on exchanges if you don’t need to.
Writing your own platform
My approach to solve the problems with manual trading was to automate the entire process by writing my own platform in python. The bot would watch the prices on various exchanges, check for possible profits, and finally execute trades to make some money using the API provided by the exchange.
Doing this has many technical difficulties. For starters, there’re no standards for the APIs, meaning each exchange can provide an entirely different interface for automatic trading.
There’s a great open-source library which tries to solve this by providing a common RESTful interface called CCXT and I highly recommend it. However, it’s still limited because some exchanges don’t provide certain functions.
Exchanges also block you if you make too many requests. Some exchange support websockets with less limits, but many don’t. This is a problem, since we want low delays and a lot of information to scale our operation to many coins and exchanges.
To solve this, I split my architecture into microservices. One microservice, the Fetcher, was responsible for fetching public information from the exchanges, such as the public order book and transaction records. A second microservice, the Trader, was responsible for running private operations which required an API key.
All the requests the fetcher made were tunneled through proxies, allowing me to make more concurrent requests without getting blocked. Additionally, I implemented websocket clients for the larger exchanges to allow me to get live price information.
The trader, however, couldn’t use proxies because all operations were private and authenticated using the same API key. Here, the challenge was mostly about reducing the amount of API calls you make to the absolute minimum.
The final problem is one of scale. When working with a lot of exchanges, you’ll have a lot of technical difficulties. Sometimes exchanges are under a DDoS attack, under maintenance or just plain crashing.
You should ensure your program is robust enough to not lose your money in this situation, and have a good monitoring system to allow you to debug those problems.
Conclusion
Hopefully this article served it’s purpose, and you have a good idea of how cryptocurrency exchanges work, and how you could approach making money on them.
Next time you find a crazy gap in prices between cryptocurrencies, try to include the trade, deposit and withdrawal fees, as well as the time it will take to make the profit in your calculation. If you find a meaningful gap, I encourage you to try to exploit it.
Remember that the profits don’t scale linearly, and as you pour more money into the system your ROIs will diminish, since you there’s a finite amount of bargains out there.
Be advised that the profits are getting lower and lower as more players join the game, and the market is often heavily manipulated and unpredictable.