This project provides a Python script to download historical kline (candle) data from Binance for various symbols and timeframes. It is designed for use in backtesting strategies.
- Incremental Fetching: Only downloads new data points since the last run.
- 4-Year History: Automatically retrieves the last 4 years of data on the first run.
- JSON Output: Saves data in a structured JSON format, perfect for JavaScript/React backtesting modules.
- Multiple Timeframes: Supports 5m, 15m, 1h, 4h, and 1d timeframes (configurable).
- Multiple Symbols: Supports a configurable list of USDT pairs.
- Clone or navigate to the project directory.
- Create a virtual environment:
python3 -m venv venv
- Activate the virtual environment:
- On macOS/Linux:
source venv/bin/activate - On Windows:
venv\Scripts\activate
- On macOS/Linux:
- Install dependencies:
pip install -r requirements.txt
You can customize the symbols, timeframes, and historical depth in config.py:
SYMBOLS = ['BNBUSDT', 'BTCUSDT', 'ETHUSDT', 'XRPUSDT', 'LINKUSDT', 'ADAUSDT']
TIMEFRAMES = ['5m', '15m', '1h', '4h', '1d']
HISTORICAL_YEARS = 4(Optional) If you hit rate limits, you can add your API_KEY and API_SECRET to config.py.
Run the main script to start syncing data:
python3 get_binance_data.pyThe data will be saved in data/json/{SYMBOL}/{SYMBOL}_{TIMEFRAME}.json.
The output JSON follows this structure:
[
{
"date": "2021-01-28T14:00:00+00:00",
"timestamp": 1611842400000,
"open": 32145.5,
"high": 32500.0,
"low": 32000.0,
"close": 32300.2,
"volume": 120.5
},
...
]