If you're into crypto trading, you probably know that server location can be a game-changer in trading speed and efficiency. Some years ago, I tried to find more about this topic, but there wasn't much out there. So, I did a little research on my own. As time went on, the need for a deeper analysis became apparent, and I believe it's essential to share these insights.
I started with Binance, but I have plans to study other platforms soon.
Methodology
I used Hummingbot to run the tests. As an all-encompassing open-source solution, it's equipped with multiple exchange connectors. It's also user-friendly for creating crypto trading bots, achievable with just a single Python script.
The primary goal wasn't to find exact latencies, but rather to determine the best AWS region. To achieve this, I devised a straightforward hummingbot script to compare the time durations for order creation, cancellation, and execution.
Here's how it works:
Timestamps: For every order – whether created, cancelled, or executed – the script records two timestamps along with the order ID in a CSV file.
Pre-transmission Timestamp: This marks the time just before the API request is sent to the exchange.
Post-transmission Timestamp: This is the time when a successful confirmation is received from the exchange.
By analyzing the difference between the pre-transmission and post-transmission timestamps, one can determine the round-trip time for each order activity.
Order Types and Frequencies:
Limit Orders: I tested creation and cancellation by generating limit orders every 30 seconds.
Market Orders: Execution was assessed using market orders created every 5 minutes.
Websocket and REST API: While actions like order creation, cancellation, and execution are transmitted using the API request, confirmations are retrieved via Hummingbot events, which are dependent on a Websocket connection.
AWS Setup
I set up identical t3.small instances across various regions, all using the same image for consistency. The only distinction between them was the connection to individual Binance subaccounts. This was done to ensure that there were no mix-ups or overlaps in API requests.
Results
My testing consisted of two stages: I started with a quick high-level test across continents and then went deeper into the best-performing area.
The first test took place across 8 regions within a 4-hour window:
Asia-Pacific: Tokyo, Singapore
Europe: London, Frankfurt
North America: Canada
South America: São Paulo
Middle East: UAE
Africa: Cape Town
Below are the box plot results specific to order creation:
From the results, it's evident that the Asia region outperforms the rest.
Building on that, I decided to delve deeper into Asia, launching servers in seven distinct regions:
Tokyo, Osaka, Seoul, Hong Kong, Singapore, Mumbai, Sydney
This time, the bots operated for a full 24 hours. Each bot processed about 4000 limit orders—both creating and canceling—and successfully executed around 200 market orders.
Below are the box plots illustrating order creation, cancellation, and execution:
Accompanying that is the statistical tables:
Order creation round-trip latencies statistics for Asia region:
Order cancellation round-trip latencies statistics for Asia region:
Order execution round-trip latencies statistics for Asia region:
To my surprise, the winner was not Tokyo but Osaka. In general, Seoul sometimes showed better results than Tokyo as well. I decided to run another test, focusing solely on these three regions for an additional 24 hours. The results were consistent: Osaka performed better, while Seoul and Tokyo competed closely for second place.
Conclusion
In conclusion, this analysis elucidates the significant impact of server location on trading bot latency on Binance across various AWS regions. The findings notably highlight the superior performance of servers in the Asia region, particularly in Osaka, Tokyo and Seoul, in terms of order creation, execution and cancellation latencies. This insight is crucial for crypto traders looking to optimize their trading bots for faster and more efficient order processing. As the crypto trading landscape evolves, understanding such nuances in server latency across different regions remains imperative for gaining a competitive edge in the market.
What's Next?
Next, I plan to conduct similar tests for other exchanges. I'd love to know which ones you'd like me to explore – drop your suggestions in the comments! Additionally, any insights to enhance the methodology would be greatly appreciated. I'm always open to feedback, constructive criticism, and advice. If you fancy a chat or even a quick call, don't hesitate to reach out to me on Discord
Resources
Hummingbot - The open source OS for crypto algo traders
Crypto Exchanges Latencies Test Repository - contains the script and all data discussed in this post.
Which Availability Zones in Osaka please?
To find a consistent identifier for an Availability Zone across different AWS accounts, you can use the AZ ID, which is a unique and consistent identifier for an AZ. The AZ ID remains constant across different AWS accounts and can be used to accurately identify the physical location of resources.
The list displayed will include both the AZ name (like eu-west-1a) and the AZ ID (like euw1-az1).