A story of failure and success: From real trades to simulation. My crypto arbitrage adventure.
Join me on a personal journey through the world of crypto arbitrage, from real trades to educational simulation, and discover key and insights.
Six months ago, I discovered arbitrage and became curious. To gain a deeper understanding, I decided to put it into practice. It started as an intellectual adventure driven by the desire for knowledge, with profit as a bonus.
Exploring the concept
"Life is a market! It’s all about buying things you can sell with an extra zero. Everyone in the world understands that but you!" Kalle from the film "Songs from the Second Floor" (2000) by Roy Andersson.
What is arbitrage?
Arbitrage might sound like a complex term, but it's actually a straightforward concept. It's all about buying something for a lower price in one place and selling it for a higher price somewhere else. The profit comes from this price difference, which usually happens because of short-term changes in how much things cost.
Now, you might have heard that arbitrage is a way to make money without any risk. Well, it's not that simple. While it's true that you buy and sell the same or similar things at the same time in different markets, calling this completely risk-free isn't accurate. Why? Because there are several things you can't always be sure about:
Completion Guarantee: Can you be absolutely sure that you'll be able to finish the transaction without any problem?
Timing Precision: Is it possible to time your transaction perfectly to make the most out of the price difference?
Market Thing: What if you buy something in one market but then can't sell it in another because something unexpected comes up?
Price Fluctuations: What if the price changes in a way that's not in your favor while you're in the middle of the arbitrage?
These questions show that arbitrage, like any other investment strategy, comes with its own set of risks. It's based on predictions and changes over time. We often talk about managing risks without fully understanding the concept of time itself. So, while arbitrage can be a smart way to make money, it's important to remember that it's not immune to the uncertainties of the real world.
Choosing the right arbitrage
When it comes to arbitrage, you need a market where you can buy things cheaply and sell them at a higher price. But what kind of market should you choose? Let me share how I made this decision.
Sports? Stocks? Cryptocurrency?
I weighed different options. Should I go for sports betting, stock trading, or cryptocurrency? Here's what I found. Cryptocurrency arbitrage is the best fit for me because it doesn't require a lot of money to start, unlike stock trading (may be I wrong). And compared to sports betting, there's a lower chance of getting banned. Also you can find crypto exchange with minimal KYC procedure or without it at all.
Approach
After thinking about different ways to do arbitrage, I decided to keep things simple and effective. I avoided methods that were too complicated or had too many restrictions. Here's what I chose:
Simple: Involves trading on the same asset.
Inter-exchange: Involves trading on different exchanges.
Automated: Utilizes bots to to identify and execute arbitrage opportunities.
Real trades
My journey into actual arbitrage trading began with a search for the right tools. I started by exploring GitHub, hoping to find some free and open-source software that could meet my needs. Unfortunately, it was challenging to find something that was both suitable and well-maintained.
Discovering ccxt and Barbotine Arbitrage Bot
My search led me to the ccxt library, a versatile tool that provides quick access to market data for a range of activities like analysis, trading, and even bot programming. Its ongoing maintenance and development were impressive.
Yet, ccxt wasn’t quite the perfect fit for me. I needed something ready-to-use and fully functional. That’s when I stumbled upon the Barbotine Arbitrage Bot (BAB), which seemed like a promising solution.
BAB stood out with features like:
Zero-risk (no speculation)
Permanent live rate display in the terminal
Full live tracking on Telegram and Discord webhooks
Compatible with almost any exchange (all ccxt exchanges).
Pre-calculates all future transactions fees to know the exact possible profit before all transactions
The best part? BAB had a free demo version that worked as a scanner for spotting arbitrage opportunities. This allowed me to test the waters without any real financial commitment. After trying out the demo, I was convinced of its capabilities and decided to invest in the full version.
Testing the bot
I set up BAB to run on my local machine, but also considered hosting it on a server for continuous operation. Having prior experience with Google Cloud Platform (GCP), I chose it as my hosting service. For tech enthusiasts, I’ve even shared a GitHub Action script for deploying code to GCP.
My trading experiments were a mixed bag. There were moments of achieving 1% profit, but also instances of facing similar percentages in losses. I tried various trading pairs like BTC/USDT, ETH/USDT, and SOL/USDT. However, the market's low volatility during that time made it tough to find consistently profitable trades.
Navigating challenges
My journey into the world of real arbitrage trading presented difficulties. Let me share them:
Limited Crypto Market Knowledge: I quickly realized how important it is to understand the crypto market. It was difficult for me to find the pair to trade and make the consistent profit.
Bot Instability: The bot's performance was erratic, which posed a significant challenge.
Technical Difficulties: I had to implement a graceful shutdown logic to handle persistent errors, and I faced various issues with error signals in Google Cloud Platform (GCP) Virtual Machines (VMs).
As my trial period with GCP neared its end, it dawned on me that I had invested a lot of time in exploring arbitrage without fully overcoming these challenges. While the bot was useful, it did not yield stable results nor a consistent income.
Key insights from my experience
Despite the challenges, this journey was rich with learning opportunities. Here are some valuable insights for anyone interested in venturing into real arbitrage:
Market Volatility: Arbitrage chances are more frequent in highly volatile markets, so understanding the current market state is crucial.
Choosing the Right Trading Pair: Knowing which pair to trade is key, and remember that profitable pairs change rapidly.
Server Location Matters: Placing servers close to exchange data centers can decrease latency and speed up order execution.
Beyond Strategy: Having an arbitration strategy is essential, but it’s not enough. Implementing advanced risk management techniques is vital to navigate market volatility and other trading risks.
Personal reflection
Through this journey, I've learned that deep understanding comes from personal exploration. While there's no such thing as a risk-free venture, risks can be managed. Also, I realized that developing my own solutions might not be the most efficient path to earning money.
My initial goal was to expand my knowledge, and interacting with the bot was just the beginning. The next step in my learning process was creating something on my own. This step was about consolidating my knowledge and applying it in a more practical, hands-on manner.
Shift to Educational Simulation
By then, I understood arbitrage in theory and practice better than ever. My knowledge expanded. Interest faded a bit. And it was time to apply my knowledge in a new way by developing a simple program.
I constantly exploring various programming languages and concepts. At that moment my interest was particularly piqued by the Go language, especially channels. These channels, with their simplicity and clarity, seemed ideal for the project I had in mind. This article captures my fascination with Go's approach to handling functions and concurrency.
Building a simple arbitrage simulator
My goal was to create something straightforward yet informative. I began crafting a program that simulates an arbitrage bot. My focus was on the basic principles of arbitrage, avoiding the complexities of real-time market data.
I’m excited to share some parts of the DeltaWhisper program with you. If you're not familiar with coding, don't worry – I've tried to keep it simple. Here's a bit of what I put together, along with explanations to make it clear.
Laying the foundation: Order book data
First, I defined the basic types of data my program would use:
type OrderBookData struct {
ExchangeID string
Price float64
}
type OrderBookEvent struct {
MaxBid OrderBookData
MinAsk OrderBookData
}
This code is like the building blocks for the program. It tells DeltaWhisper what kind of information to look at when it's making decisions.
Simulating the market: Generating order book data
Next, I added a way for the program to create pretend market data:
const FakeCryptoRate = 55.0 // Imagine 1 SOL is equal to 55 USD
func generateOrderBookData() OrderBookEvent {
maxBidPrice := FakeCryptoRate + rand.Float64()
minAskPrice := maxBidPrice + rand.Float64()
// Pretending there's a chance to make money.
// coef should be equal 1 when deal with real data
coef := generateRandomFloat64InRange(1, 1.015)
return OrderBookEvent{
MaxBid: OrderBookData{
ExchangeID: exchanges[rand.Intn(len(exchanges))],
Price: maxBidPrice * coef,
},
MinAsk: OrderBookData{
ExchangeID: exchanges[rand.Intn(len(exchanges))],
Price: minAskPrice,
},
}
}
This piece lets DeltaWhisper play around with fake prices to see where there might be a good chance to buy low and sell high.
Keeping an eye on the market: Using Go channels
To monitor the market, I used a special feature in Go called channels:
const CryptoSymbol = "SOL"
const EventIntervalMs = 100
func watchOrderBook(channel chan OrderBookEvent) {
defer close(channel)
for {
orderBookData := generateOrderBookData()
halfInterval := EventIntervalMs / 2
select {
case channel <- orderBookData:
case <-time.After(EventIntervalMs * time.Millisecond):
// return
}
sleepTime := time.Duration(rand.Intn(halfInterval)+halfInterval) * time.Millisecond
time.Sleep(sleepTime)
}
}
This part is like having a lookout, constantly checking the market to see what's happening and if there are opportunities to make a trade.
Finding the right moment: Identifying opportunities
The heart of DeltaWhisper is about deciding when to make a move:
// ... [initial setup code] ...
// Watches order book data and looks for potential arbitrage opportunities.
for data := range orderBookData {
// ... [] ...
isDifferentExchange := data.MinAsk.ExchangeID != data.MaxBid.ExchangeID
isDifferentAskPrice := prevMinAskPrice != data.MinAsk.Price
isDifferentBidPrice := prevMaxBidPrice != data.MaxBid.Price
isProfitUsdCriteriaMet := changeUsd > MinimumUsdGain
isProfitUsdPctCriteriaMet := changeUsdPct > MinimumProfitPercentage
isSufficientUsdBalance := usdBalances[data.MinAsk.ExchangeID] >= usdSpent
isSufficientCryptoBalance := cryptoBalances[data.MaxBid.ExchangeID] >= cryptoPerOperation
meetsCriteria :=
isDifferentExchange &&
isProfitUsdCriteriaMet &&
isProfitUsdPctCriteriaMet &&
isDifferentAskPrice &&
isDifferentBidPrice &&
isSufficientUsdBalance &&
isSufficientCryptoBalance
if meetsCriteria {
// 1. Execute arbitrage (limit orders or market orders)
// 2. Recalculate balances
// 3. Log the results
// ... [] ...
}
}
// ... [additional utility functions and logic] ...
In this part, the program checks different things like prices, balances, and if it's a good time to buy or sell. It's like a puzzle – the program puts together all these pieces of information to decide the best move.
Wrapping Up
I've tried to put helpful comments in the code to make it easier to understand. If you want to see more about how DeltaWhisper works, you can check out the project here. This was not just about making a program but about learning and sharing that learning in a way that’s easy and fun to understand.
Conclusion
So, we've come to the end of this story about my journey with crypto arbitrage. Yes, the idea of making money was exciting, but what I really wanted was to learn something new. And learn I did! I gained a lot of practical knowledge, which was the best part for me.
This article is all about sharing what it's like to start out in the world of arbitrage. I hope it shows you that it's okay to try new things and learn as you go, without feeling too much pressure.
For anyone just starting out, remember that trying things out for yourself is really important. I might not have explored complex market strategies, but the experiences I had were key in helping me understand how arbitrage in crypto works.
If my story has gotten you interested and you want to hear more about what I learn and try out in the future, you can sign up for my newsletter. I share all sorts of cool discoveries and tips there. It's all about learning together and supporting each other on this journey. Let's keep growing and discovering new things!