Skip to main content

Get Price History

Retrieves historical price data (candlestick/kline data) for a trading pair and saves it to a CSV file for technical analysis and backtesting.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.

Inputs

  • Client Id - The unique identifier from the Connect node (optional if using direct credentials).
  • Currency Pair - The trading pair symbol (e.g., BTCUSDT, ETHUSDT, BNBUSDT).
  • Limit - Maximum number of candlesticks to retrieve (optional if using date range).
  • Start Date - Start time in milliseconds timestamp (optional, requires End Date).
  • End Date - End time in milliseconds timestamp (optional, requires Start Date).
  • Save Path - File path where the CSV file will be saved (e.g., /path/to/btc_history.csv).
  • Delay Between Request - Delay in seconds between API requests when fetching large datasets (default: 0.5).
  • Custom Interval - Custom time interval (overrides the Interval option if provided).

Options

  • Api Key - (Optional) Binance API key credential. Use if not providing Client Id.
  • Secret Key - (Optional) Binance API secret key credential. Use if not providing Client Id.
  • Interval - Time interval for candlesticks. Options:
    • 1m - 1 Minute
    • 3m - 3 Minutes
    • 5m - 5 Minutes
    • 15m - 15 Minutes
    • 30m - 30 Minutes
    • 1h - 1 Hour (default)
    • 2h - 2 Hours
    • 4h - 4 Hours
    • 6h - 6 Hours
    • 8h - 8 Hours
    • 12h - 12 Hours
    • 1d - 1 Day
    • 3d - 3 Days
    • 1w - 1 Week
    • 1M - 1 Month

Output

  • CSV File - Historical candlestick data saved to the specified path.

How It Works

The Get Price History node retrieves historical candlestick data from Binance and exports it to CSV format.

When executed, the node:

  1. Validates all required inputs
  2. Retrieves the Binance client
  3. Calculates the required number of API requests (Binance returns max 1000 candles per request)
  4. Fetches candlestick data in batches with delays between requests
  5. Creates a CSV file with columns: openTime, closeTime, open, close, high, low, volume, tradeNum, quoteAssetVolume, takerBuyBaseAssetVolume, takerBuyQuoteAssetVolume
  6. Writes all candlestick data to the file

Requirements

  • Either a Client Id from Connect node OR API credentials in options
  • Valid trading pair symbol
  • Either Limit OR both Start Date and End Date must be provided
  • Write permissions for the Save Path location
  • Sufficient disk space for the CSV file

Error Handling

The node will return specific errors in the following cases:

  • ErrInternal - Failed to retrieve input values
  • ErrInvalidArg - Empty inputs, invalid interval, or missing required parameters
  • ErrGetHistory - Failed to retrieve historical data from Binance
  • ErrCreateFile - Failed to create or write to the CSV file
  • ErrStrToInt - Invalid timestamp format

Usage Notes

  • Binance returns maximum 1000 candlesticks per request
  • For larger datasets, the node automatically makes multiple requests with delays
  • Date timestamps must be in milliseconds (Unix timestamp * 1000)
  • Custom Interval overrides the Interval option if provided
  • Delay Between Request prevents API rate limiting (default 0.5 seconds recommended)
  • Data is retrieved backwards from End Date or current time

CSV Output Format

The CSV file contains the following columns:

ColumnDescription
openTimeCandlestick open time (milliseconds)
closeTimeCandlestick close time (milliseconds)
openOpening price
closeClosing price
highHighest price
lowLowest price
volumeTrading volume (base asset)
tradeNumNumber of trades
quoteAssetVolumeTrading volume (quote asset)
takerBuyBaseAssetVolumeTaker buy volume (base asset)
takerBuyQuoteAssetVolumeTaker buy volume (quote asset)

Example: Download Recent 100 Candles

Scenario: Get the last 100 hourly candles for Bitcoin

Inputs:

  • Client Id: (from Connect node)
  • Currency Pair: BTCUSDT
  • Limit: 100
  • Save Path: /data/btc_hourly.csv
  • Delay Between Request: 0.5

Options:

  • Interval: 1h

Result: CSV file with 100 hourly candlesticks saved to /data/btc_hourly.csv

Example: Download Historical Data by Date Range

Scenario: Get daily candles for January 2024

Inputs:

  • Client Id: (from Connect node)
  • Currency Pair: BTCUSDT
  • Start Date: 1704067200000 (Jan 1, 2024)
  • End Date: 1706745600000 (Feb 1, 2024)
  • Save Path: /data/btc_jan2024.csv
  • Delay Between Request: 0.5

Options:

  • Interval: 1d

Example: Automated Daily Data Collection

[Timer: Daily at midnight]
|
v
[Connect]
|
v
[Calculate Dates]
| start = yesterday_start (milliseconds)
| end = today_start (milliseconds)
v
[Get Price History]
| Currency Pair: BTCUSDT
| Interval: 1h
| Start Date: start
| End Date: end
| Save Path: /data/btc_ + date + .csv
v
[Log: "Downloaded data for " + date]
|
v
[Disconnect]

Example: Multi-Timeframe Download

[Connect]
|
v
[For Each: interval in ["5m", "15m", "1h", "1d"]]
|
v
[Get Price History]
| Currency Pair: BTCUSDT
| Custom Interval: interval
| Limit: 1000
| Save Path: /data/btc_ + interval + .csv
| Delay Between Request: 0.5
v
[Wait: 2 seconds]
|
v
[Next Interval]
|
v
[Disconnect]

Converting Timestamps

JavaScript:

// Convert Date to milliseconds timestamp
const startDate = new Date("2024-01-01").getTime();
const endDate = new Date("2024-02-01").getTime();

// Convert milliseconds to human-readable date
const date = new Date(1704067200000);
console.log(date.toISOString()); // "2024-01-01T00:00:00.000Z"

Python:

import datetime

# Convert to milliseconds
start_date = int(datetime.datetime(2024, 1, 1).timestamp() * 1000)
end_date = int(datetime.datetime(2024, 2, 1).timestamp() * 1000)

# Convert from milliseconds
date = datetime.datetime.fromtimestamp(1704067200000 / 1000)

Interval Calculations

Maximum data per interval with 1000 candle limit:

IntervalMax Time Range
1m~16.7 hours
5m~3.5 days
15m~10.4 days
1h~41.7 days
4h~166.7 days
1d~2.7 years
1w~19.2 years

Use Cases

Technical Analysis:

  • Calculate moving averages, RSI, MACD
  • Identify support and resistance levels
  • Detect chart patterns

Backtesting:

  • Test trading strategies on historical data
  • Validate indicators and signals
  • Calculate strategy performance

Machine Learning:

  • Train predictive models
  • Feature engineering from candlestick data
  • Time series analysis

Reporting:

  • Generate price charts
  • Calculate historical returns
  • Analyze volatility patterns

Processing CSV Data

Python Example:

import pandas as pd

# Read CSV
df = pd.read_csv('btc_history.csv')

# Convert timestamps
df['openTime'] = pd.to_datetime(df['openTime'], unit='ms')
df['closeTime'] = pd.to_datetime(df['closeTime'], unit='ms')

# Calculate returns
df['returns'] = df['close'].pct_change()

# Calculate SMA
df['SMA_20'] = df['close'].rolling(window=20).mean()

Excel:

  • Open CSV in Excel or Google Sheets
  • Use built-in charting tools
  • Apply formulas for technical indicators

Best Practices

  • Use appropriate intervals based on your analysis needs (shorter for day trading, longer for investing)
  • Set Delay Between Request to 0.5-1 second to avoid rate limiting
  • For large datasets, split requests into smaller date ranges
  • Verify the CSV file was created successfully before processing
  • Store historical data locally to avoid repeated API calls
  • Use Custom Interval input for programmatic interval selection
  • Clean up old CSV files periodically to save disk space
  • Validate timestamps are correct before making requests

Rate Limiting Considerations

  • Binance has weight-based rate limits
  • Each kline request has a weight of 1
  • Downloading 5000 candles requires 5 requests (weight: 5)
  • Add appropriate delays to avoid hitting limits
  • Default 0.5 second delay is recommended
  • Increase delay if you encounter rate limit errors

Data Quality

  • Binance provides high-quality historical data
  • Data includes all executed trades
  • Gaps may exist during exchange maintenance
  • Very old data may have limited availability for some pairs
  • Verify data completeness after download

Common Errors

  • Invalid interval - Use only supported interval values
  • Date range mismatch - Ensure Start Date < End Date
  • File permission error - Check write access to Save Path
  • Rate limit exceeded - Increase Delay Between Request
  • Invalid date format - Use milliseconds timestamps
  • Pair not found - Verify trading pair exists on Binance

Tips for Large Downloads

  • For years of data, split into monthly chunks
  • Use daily or higher intervals for long time periods
  • Monitor API weight and rate limits
  • Save to dedicated data directory
  • Compress old CSV files to save space
  • Use database instead of CSV for very large datasets