Extracting Historical Ethereum Data from Binance API
As an Ethereum developer, you are probably familiar with the importance of historical data for analysis and trading strategies. However, extracting accurate historical data from external APIs like Binance can be challenging due to several limitations.
Problem: Limited time frame
You are encountering an issue where your code is only getting 3 items, while expecting around 700 entries from [current_time – 2 years] to [current_time]. This discrepancy is due to the fact that Binance historical data typically has a much longer time frame than what you are requesting.
Why this happens
There are several reasons why this might happen:
- API limitations: The Binance API has rate limits that can prevent excessive requests to avoid overloading their servers.
- Data Caching

: External APIs often cache historical data for performance and reliability reasons, which can result in older records being returned before the required time frame.
- Data Format Mismatches: Historical data can be stored in different formats or structures, making it difficult to retrieve specific records.
Solutions
To overcome these challenges, consider the following solutions:
1. Check API Rate Limits
Make sure you are not exceeding the Binance API rate limits. You can do this by checking the documentation and monitoring the number of requests using tools such as [Rate Limit Checker](
import requests
max_requests = 1000
current_time = datatime.now()
while true:
try:
response = requests.get(' params={'symbol': 'ETH', 'interval': '1D', 'start': int(current_time.timestamp()) - 86400, 'count': 70})
if response.status_code == 200:
break
except exception like e:
print(f"Error: {e}")
2. Use Binance Historical Data Feature
Binance offers a historical data feature that allows you to retrieve data from any time period, including long-term intervals such as [current_time – 2 years]. However, this feature may not be available or may require additional authentication.
import requests
Set your API credentials and other parametersapi_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_KEY'
symbol = 'ETH'
interval = '1D'
start_date = (datetime.now() - datetime.timedelta(days=730)).strftime('%Y-%m-%d')
end_date = (datetime.now() - datetime.timedelta(days=365)).strftime('%Y-%m-%d')
response = requests.get(f' interval, start, end)',
auth=(api_key, api_secret), headers={'limit': 100})
if response.status_code == 200:
print(response.json())
3. Use a library or framework
Consider using libraries such as [pandas-datareader]( (for Python 3.x) or [yfinance]( (for Python 2.x), which provide more comprehensive and flexible data extraction capabilities.
import pandas as pd
pd.set_option('display.max_columns', None)
symbol = 'ETH'
start_date = datatime.now() - timedelta(days=730).strftime('%Y-%m-%d')
end_date = (datatime.now() - datetime.timedelta(days=365)).strftime('%Y-%m-%d')
df = pd.read_csv(f'
print(df.head(70))
Print the first 70 records
After implementing these solutions, you should get historical data from Binance that meets your requirements.