For data scientists, quant researchers, and algorithmic traders, historical data is the bedrock of any successful market strategy. Whether you are backtesting a moving average crossover system, training a machine learning model to predict volatility, or simply conducting seasonality analysis, the quality and depth of your data determine the reliability of your results.
While many data providers restrict access to recent intraday activity or the last 52 weeks of pricing, deep analysis requires a much broader horizon. To truly understand how an asset behaves through different market cycles, you often need a decade or more of price history.
In this tutorial, we will demonstrate how to programmatically retrieve 10 years of historical stock market data (Open, High, Low, Close, Volume) using the Mboum Finance API and Python.
👉 Get your free API key here:
https://mboum.com/pages/api
The Mboum Endpoint for Historical Data
To retrieve candle data (OHLCV), we will use the following endpoint:
GET /v1/markets/stock/history
This endpoint is designed to return time-series data formatted specifically for charting and backtesting.
Documentation:
https://docs.mboum.com/#stocks-options-GETapi-v1-markets-stock-history
The API dynamically adjusts the historical range returned based on the interval parameter you choose. According to the documentation, selecting a monthly interval allows you to retrieve data spanning back 10 years, making it ideal for long-term trend analysis.
Critical Parameters
When constructing your request, you will primarily work with the following parameters:
-
ticker – The symbol of the asset you want to query (e.g.,
AAPL,SPY,BTC-USD) -
interval – The time duration between two data points
To achieve a 10-year lookback period, use1moOther options include:
-
1d(5 years range) -
1wk(5 years range) -
5m(1 month range)
-
-
diffandsplits – A boolean string (
trueorfalse) to determine if you want split data included
Python Example: Fetching 10 Years of Data
Below is a complete, runnable Python script that fetches 10 years of historical monthly candles for the SPDR S&P 500 ETF Trust (SPY). We will use the standard requests library to handle the API call.
import requests
import json
# Configuration
api_key = "YOUR_AUTH_KEY" # Replace with your actual Mboum API Key
symbol = "SPY"
base_url = "https://api.mboum.com/v1/markets/stock/history"
# Set parameters
# We use '1mo' (1 month candles) to trigger the 10-year range
# as specified in the documentation.
params = {
'ticker': symbol,
'interval': '1mo',
'diffandsplits': 'true'
}
headers = {
'Authorization': f'Bearer {api_key}'
}
try:
# Make the GET request
response = requests.get(base_url, headers=headers, params=params)
# Check if the request was successful
if response.status_code == 200:
data = response.json()
# Output the metadata and the first entry as a sample
print("Status:", data['meta']['status'])
print("Symbol:", data['meta']['symbol'])
print("Data Granularity:", data['meta']['dataGranularity'])
# Accessing the body which contains the candles
history_data = data['body']
# Example: Print the first 3 months of data retrieved
print(f"\n--- First 3 Data Points for {symbol} ---")
count = 0
for timestamp, candle in history_data.items():
if count < 3:
print(f"Date: {candle['date']} | Close: {candle['close']} | Volume: {candle['volume']}")
count += 1
else:
break
else:
print(f"Error: {response.status_code} - {response.text}")
except Exception as e:
print(f"An error occurred: {e}")
Understanding the API Response
When you successfully make a request, the API returns a JSON object containing:
-
A meta object (request details)
-
A body object (the actual price data)
The body dictionary uses Unix timestamps as keys, ensuring that every data point is uniquely indexed by time.
Candle Fields
Each candle includes the following fields:
-
date – The human-readable date of the candle (e.g.,
"01-09-2023") -
date_utc – The Unix timestamp representation of the date
-
open – Price at the beginning of the interval
-
high – Highest price during the interval
-
low – Lowest price during the interval
-
close – Price at the end of the interval
-
volume – Total shares traded during the interval
Sample JSON Output
{
"meta": {
"symbol": "SPY",
"dataGranularity": "1mo",
"version": "v1.0",
"status": 200,
"copywrite": "https://mboum.com"
},
"body": {
"1693526400": {
"date": "01-09-2023",
"date_utc": 1693526400,
"open": 450.72,
"high": 451.08,
"low": 423.56,
"close": 427.48,
"volume": 1466632200
}
}
}
Practical Use Cases for 10-Year History
1. Macro Trend Backtesting
Strategies that rely on Golden Crosses (e.g., 50-day SMA crossing 200-day SMA) or long-term momentum require datasets that span multiple years. Ten years of data usually encompasses at least one full bull and bear market cycle, providing a stress test for your algorithms.
2. Seasonality Analysis
To determine if patterns like “Sell in May and Go Away” or the “Santa Claus Rally” are statistically significant, you need a large sample size of years. Monthly data over a decade allows you to average performance by month reliably.
3. Investment Portfolio Modeling
For developers building robo-advisor dashboards, plotting a 10-year growth chart is standard practice. This endpoint provides the exact data points needed for long-term line or candlestick charts using libraries like Chart.js or D3.js.
Final Thoughts
Retrieving historical financial data doesn't need to be complicated or fragmented. By leveraging the Mboum API history endpoint, you can pull standardized OHLCV candles spanning a full decade with a single HTTP request. This allows you to spend less time data wrangling and more time analyzing market behavior.
Ready to start backtesting?
👉 Get your API Key:
https://mboum.com/pages/api