Quant Infrastructure Series #2 - Exchange Client
A comprehensive guide to building a robust exchange client.
In today’s article, we build a robust API client for a CEX/hybrid exchange with the dual purpose of downloading historical data from it and — in the long term — trading. The method shown here is applicable across exchanges. We will use Binance Futures as an example.
This topic is a natural place to begin the series. As Quants, we need historical data to research and backtest ideas and exchanges expose large amounts of it via their APIs. Third-party clients often either do not exist or are subpar in one way or another.
The article is envisioned as a template/how-to guide for building an in-house client for exchanges that expose an HTTP API. This includes all common CEX and hybrid exchanges: Binance, Bybit, OKX, Kucoin, dYdX, etc.
For practical reasons, we seek to convey the idea rather than include every single line of code of the completed client.
The reader will be happy to learn that exchange APIs are very similar to each other such that being able to integrate Binance Futures means we are also able to integrate Bybit Spot and so on.
The article demonstrates how to write a client that is simple, understandable, robust to errors, and which we are able to trust, update, and fix when necessary. We think these properties are necessary if we want to use the client to trade real money, and if we value our time and want to stay maximally headache-free as Quants — at least on the infrastructure side.
We also lay the groundwork for the next article, which will show a performant storage system, which is the natural progression after a client used to download data.
In the long term, we plan to use the client to allow us to trade.
The complete source code in Rust will be available at the end of the article for paying subscribers.
For completeness, other ways to acquire data include:
Buy it from a vendor.
Record exchange’s live feeds. This method is rarely useful outside of HFT as the data needed usually spans years and so recording it is impractical for us.
Some exchanges will also make their data available for download outside the API. For example, here’s Binance’s public data catalogue released recently.
Disclaimer: Trading is a risky endeavour and I am not responsible for any losses you may incur implementing ideas learnt through these articles.
Disclaimer: This is not financial advice.
Keep reading with a 7-day free trial
Subscribe to TaiwanQuant's Newsletter to keep reading this post and get 7 days of free access to the full post archives.