{ "cells": [ { "cell_type": "markdown", "id": "7c22c8be-f771-42f7-b550-13af6e4298de", "metadata": {}, "source": [ "# High-Frequency Grid Trading\n", "\n", "In this example, we will show you the entire process of backtesting, from data conversion using Tardis's historical data to backtesting with hftbacktest in Rust. To run this example, Python 3.10 and the latest versions of hftbacktest in Python and `gridtrading_backtest_args` in the examples of hftbacktest in Rust are required.\n", "\n", "Firstly, you need to select which pairs you will backtest. `1_ticker.py` fetches ticker information from Binance Futures. You can set the number of pairs in the script. The `tickers.json` file used in this example is included.\n", "\n", "`python 1_ticker.py`\n", "\n", "Secondly, you need to download the data. L2 market depth and trade feed data are large, so they couldn't be included with the example. For historical data, this example uses Tardis's data. You can collect the data yourself using [this repo's program](https://github.com/nkaz001/collect-binancefutures) and convert it. Please see [Data Preparation](https://hftbacktest.readthedocs.io/en/latest/tutorials/Data%20Preparation.html) for details.\n", "\n", "To run `2_download_tardis.py`, you need to set *TARDIS_KEY* and can specify the date range and path in the script.\n", "\n", "`TARDIS_KEY=your_key python 2_download.py`\n", "\n", "After downloading all necessary data, you need to convert the Tardis data into npz files that hftbacktest can consume. You can set the file paths and the number of processors for multiprocessing. Conversion requires a lot of memory, so monitor your memory usage, set the appropriate number of processors, and possibly adjust the buffer size.\n", "\n", "`python 3_convert.py`\n", "\n", "To achieve results close to actual trading, it's crucial to know your own order entry latency and response latency. If you don't have historical order latency data, as a second option, you can generate artificial order latency from the feed latency. Please see the script configuration.\n", "Also, please refer to [Order Latency](https://hftbacktest.readthedocs.io/en/latest/tutorials/Order%20Latency%20Data.html) and [Latency Models](https://hftbacktest.readthedocs.io/en/latest/latency_models.html) for further information.\n", "\n", "`python 4_latency.py`\n", "\n", "Now, all data required for backtesting is prepared. You can set the path and parameters for the backtest. This will run the pre-compiled `gridtrading_backtest_args` written in Rust, which is also provided with the example. For more detailed information, please see the Python version example of [High-Frequency Grid Trading](https://hftbacktest.readthedocs.io/en/latest/tutorials/High-Frequency%20Grid%20Trading.html).\n", "\n", "`python 5_backtest.py`" ] }, { "cell_type": "markdown", "id": "0553ac7d-8650-450c-a640-c6178f6acef2", "metadata": {}, "source": [ "