|
| 1 | +# Downloading Market Data |
| 2 | + |
| 3 | +Reliable backtesting starts with high-quality historical data. Stochastix provides a built-in command-line tool to fetch OHLCV (Open, High, Low, Close, Volume) data from major cryptocurrency exchanges and save it in a highly efficient binary format. |
| 4 | + |
| 5 | +Under the hood, this downloader uses the powerful CCXT library, giving you access to dozens of exchanges. |
| 6 | + |
| 7 | +## The Download Command |
| 8 | + |
| 9 | +The primary tool for fetching data is the `stochastix:data:download` command (alias: `stx:data:dl`). |
| 10 | + |
| 11 | +### Command Signature |
| 12 | + |
| 13 | +```bash |
| 14 | +make sf c="stochastix:data:download <exchange> <symbol> <timeframe> [options]" |
| 15 | +``` |
| 16 | + |
| 17 | +### Arguments |
| 18 | + |
| 19 | +* **`exchange`**: The exchange ID as recognized by CCXT (e.g., `binance`, `okx`, `kraken`). |
| 20 | +* **`symbol`**: The trading pair you want to download (e.g., `BTC/USDT`, `SOL/USDT`). |
| 21 | +* **`timeframe`**: The candle size. This must be a timeframe supported by the specific exchange (e.g., `1m`, `5m`, `1h`, `1d`, `1w`). |
| 22 | + |
| 23 | +### Options |
| 24 | + |
| 25 | +* **`--start-date` or `-S`**: (Required) The date from which to start downloading data, in `YYYY-MM-DD` format. |
| 26 | +* **`--end-date` or `-E`**: (Optional) The date at which to stop downloading data. If omitted, it will download data up to the current day. |
| 27 | + |
| 28 | +## Step-by-Step Example |
| 29 | + |
| 30 | +Let's download 1-day data for `ETH/USDT` from `Binance` for the entire year of 2023. |
| 31 | + |
| 32 | +1. Open your terminal in the root of your Stochastix project. |
| 33 | +2. Run the following command: |
| 34 | + |
| 35 | + ```bash |
| 36 | + make sf c="stochastix:data:download binance ETH/USDT 1d --start-date=2023-01-01 --end-date=2023-12-31" |
| 37 | + ``` |
| 38 | + |
| 39 | +3. You will see a progress bar as the downloader fetches data in batches from the exchange. |
| 40 | + |
| 41 | + ```bash |
| 42 | + 🚀 Stochastix OHLCV Data Downloader 🚀 |
| 43 | + ====================================== |
| 44 | +
|
| 45 | + Download Progress |
| 46 | + ----------------- |
| 47 | +
|
| 48 | + 287/364 [======================>-----] 78% | Fetched until: 2023-10-15 00:00:00 (1 recs) |
| 49 | + ``` |
| 50 | + |
| 51 | +4. Once complete, you will see a success message indicating where the file has been saved. |
| 52 | + |
| 53 | +## Data Storage Location |
| 54 | + |
| 55 | +Downloaded data is stored in the `data/market/` directory of your project. The files are organized in a clear hierarchy: |
| 56 | + |
| 57 | +`data/market/{exchange_id}/{symbol}/{timeframe}.stchx` |
| 58 | + |
| 59 | +For the example above, the data would be saved to: |
| 60 | + |
| 61 | +`data/market/binance/ETH_USDT/1d.stchx` |
| 62 | + |
| 63 | +::: info |
| 64 | +Note that the `/` in a trading symbol is automatically converted to an `_` for filesystem compatibility. The framework handles this conversion automatically when reading the data. |
| 65 | +::: |
| 66 | + |
| 67 | +The `.stchx` files are stored in a custom binary format designed for maximum read performance during backtesting. The next pages in this section will explain how to inspect these files and will provide their full technical specification. |
| 68 | + |
| 69 | +## Asynchronous Downloading via the UI |
| 70 | + |
| 71 | +While the CLI command is great for single downloads, the web UI provides an asynchronous way to manage multiple downloads. When you initiate a download from the UI, it sends a request to the API (`POST /api/data/download`), which queues the job for a background worker. This allows you to start several large downloads and monitor their progress in real-time without tying up your terminal. |
0 commit comments