Binance provides some of its historical trading data on the binance.vision
domain. Specifically, the 1 second klines for BTCUSDT pair can be found here: https://data.binance.vision/?prefix=data/spot/daily/klines/BTCUSDT/1s/
Here's a sample bash script that downloads and unpacks the raw data for the whole month:
#!/bin/bash
for i in $(seq -f "%02g" 1 31) # zero-padded days 01, 02, 03, ... 31
do
# month of july 2023, day number is the `i` variable
archiveName="BTCUSDT-1s-2023-07-${i}.zip"
# download the .zip, extract it (saves .csv), and remove the .zip
wget "https://data.binance.vision/data/spot/daily/klines/BTCUSDT/1s/${archiveName}" && unzip "./${archiveName}" && rm "./${archiveName}"
done
As mentioned in their GitHub readme, each of the the .csv
lines contains the following field values:
Open time |
Open |
High |
Low |
Close |
Volume |
Close time |
Quote asset volume |
Number of trades |
Taker buy base asset volume |
Taker buy quote asset volume |
Ignore |
So for example, the file BTCUSDT-1s-2023-07-01.csv
containing this first line
1688169600000,30471.99000000,30472.00000000,30471.99000000,30472.00000000,0.54114000,1688169600999,16489.61790060,31,0.52320000,15942.95040000,0
enables you to calculate this:
- From millisecond timestamp
1688169600000
(July 1st, 2023 0:00:00 UTC)
- To millisecond timestamp
1688169600999
(July 1st, 2023 0:00:00.999 UTC)
- Full candle
- Open price
30471.99
USDT for 1 BTC
- Close price
30472.00
USDT for 1 BTC
- Close is higher than open => candle is green
- Knots
- Lowest price
30471.99
USDT for 1 BTC
- Same as open price of green candle => no knot below
- Highest price
30472.00
USDT for 1 BTC
- Same as close price of green candle => no knot above