Stock market data infrastructure
Get historical stock prices with Python
Fetch a historical OHLCV series with httpx, parse the bars envelope, and preserve adjusted price metadata and missing-data states.
Documentation revised
Fetch one daily series
Install httpx in your own client environment and set STOCKMARKET_API_KEY before running this example. It requests one year of daily bars for an illustrative NASDAQ listing and raises on an HTTP failure before parsing JSON.
import os
import httpx
response = httpx.get(
"https://stockmarketapi.ai/api/v1/companies/AAPL/prices",
params={"range": "1Y", "interval": "1d", "exchange": "NASDAQ"},
headers={"X-API-Key": os.environ["STOCKMARKET_API_KEY"]},
timeout=30,
)
response.raise_for_status()
payload = response.json()
for bar in payload["bars"]:
print(bar["t"], bar["close"], bar.get("close_split_adjusted"))
Retain the response metadata
Store payload adjustment, source, currency, currency_basis, and interval beside the bars. The close field has a split-and-dividend basis for daily history; close_split_adjusted is split-only. Inspect each bar's t value rather than assuming observations occur on every calendar day.
Make gaps visible
If bars is empty, record an unavailable-series result rather than generating zero-valued bars. Compare the latest returned date with the exchange calendar. The requested range anchors to the newest stored observation, so a successful 1Y request can still be stale.