Skip to content
All library documents

Fetching and Reusing Historical Exchange Data for Backtests

Article OctoBot

Summary

This guide explains how to obtain exchange history for OctoBot Script backtests and how to reuse previously downloaded data. The fetch request is configured with a trading pair and candle interval, with optional settings for the starting timestamp, exchange, and market type. The exchange defaults to Binance and the market type defaults to spot; supported futures markets can also be selected.

Downloaded history is saved locally in a backtesting data folder. The returned data object exposes the saved file’s name, which can then be supplied in a later request to load the same history instead of fetching it again. Reuse can shorten repeat runs and allows a script to work offline once the data is available. The page focuses on access and storage mechanics rather than data validation, coverage, or backtest design, and it does not provide evidence about data quality or trading performance.

Key ideas

  • Backtests require historical market data, including candle history.
  • Requests can specify symbols, time intervals, a start time, an exchange, and a market type.
  • Fetched data is stored locally and can be loaded again by referencing its saved file.
  • Using cached history supports repeat runs and offline execution.

Tags

Full text
# Télécharger les données historiques de trading


---
title: "Télécharger les données historiques"
description: "Apprenez comment récupérer et réutiliser des données historiques de marché d'échange en utilisant Python à l'aide d'OctoBot Script."
sidebar_position: 14
---



# Télécharger les données historiques de trading

:::info
  La traduction française de cette page est en cours.
:::

In order to run a backtest, OctoBot script requires historical
trading data, which is at least candles history.

## Télécharger de nouvelles données

When using OctoBot script, historical data can be fetched using:
`await obs.get_data(symbol, time frame)`

Where:

- symbol: the trading symbol to fetch data from. It can also be a list of symbols
- time frame: the time frame to fetch (1h, 4h, 1d, etc). It can also be a list of time frames

Optional arguments:

- start_timestamp: the unix timestamp to start fetching data from. Use <a href="https://www.epochconverter.com/" rel="nofollow">this converter</a> if you are unsure what you should use.
- exchange: the exchange to fetch data from. Default is "binance"
- exchange_type: the exchange trading type to fetch data from. Default is "spot", "future" is also possible on supported exchanges

```python
data = await obs.get_data("BTC/USDT", "1d", start_timestamp=1505606400)
```

## Réutiliser les données précédemment téléchargées

Calling `data = await obs.get_data` will save the downloaded data into the `backtesting/data` local folder.
If you want to speedup subsequent calls, you can provide the `data_file` optional argument to read
data from this file instead of downloading historical data. This also makes it possible to run a
script while being offline.

You can get the name of the downloaded backtesting file by accessing
`data.data_files[0]`

```python
data = await obs.get_data("BTC/USDT", "1d", start_timestamp=1505606400)
# print the name of the downloaded data file
print(data.data_files[0])
```

```python
datafile = "ExchangeHistoryDataCollector_1671754854.5234916.data"
# will not download historical data as a local data_file is provided
data = await obs.get_data("BTC/USDT", "1d", start_timestamp=1505606400, data_file=datafile)
```

Shown in full with attribution under the source's licence. Licence: GPL-3.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.