Search code examples
binance

Binance Historical Tick Data (1 second) for a specific date range and symbol


I need to some how get the tick data for BTCUSDT for specific days. This is the raw tick data, the ( Last Price ) I will attach an image of a chart from TV and the price that shows on the right that moves up and down every second, I need that price but I need it for 1 month.

I have tried the following sites to obtain it but I am probably missing something or just dont know how to get the BTCUSDT 1 second raw tick data for 1 month.

Binance Data Collection

https://github.com/binance/binance-public-data

https://pypi.org/project/binance-historical-data/

enter image description here

I just need to know how to obtain Binance BTCUSDT 1 second raw tick data (last price) for the month of July would be great.


Solution

  • 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