> ## Documentation Index
> Fetch the complete documentation index at: https://docs.financialdatasets.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Get Stock Prices

> Learn how to fetch historical stock price data for any US ticker using Python and the Financial Datasets API. Includes daily, weekly, and monthly intervals.

Historical stock price data is essential for backtesting trading strategies, building financial models, and rendering price charts. This guide walks you through fetching OHLCV (open, high, low, close, volume) price data using Python.

## Prerequisites

* Python 3.7+
* A Financial Datasets API key ([sign up here](https://financialdatasets.ai))
* The `requests` library (`pip install requests`)

## Step 1: Set Up Authentication

Every API request requires your API key in the `X-API-KEY` header.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import requests

headers = {
    "X-API-KEY": "your_api_key_here"
}
```

## Step 2: Fetch Daily Stock Prices

Use the [Prices API](/api/prices/historical) to pull end-of-day prices for any US ticker. You must specify a `ticker`, `interval`, `start_date`, and `end_date`.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import requests

headers = {
    "X-API-KEY": "your_api_key_here"
}

ticker = "AAPL"
interval = "day"  # options: day, week, month, year
start_date = "2024-01-01"
end_date = "2024-12-31"

url = (
    f"https://api.financialdatasets.ai/prices/"
    f"?ticker={ticker}"
    f"&interval={interval}"
    f"&start_date={start_date}"
    f"&end_date={end_date}"
)

response = requests.get(url, headers=headers)
prices = response.json().get("prices")

for price in prices[:5]:
    print(f"{price['time']}: Open={price['open']}, Close={price['close']}")
```

## Step 3: Change the Interval

Switch `interval` to get weekly, monthly, or yearly aggregated prices:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Weekly prices
interval = "week"

# Monthly prices
interval = "month"

# Yearly prices
interval = "year"
```

## Step 4: Get a Real-Time Price Snapshot

For the latest price, use the [Snapshot API](/api/prices/snapshot):

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
url = f"https://api.financialdatasets.ai/prices/snapshot?ticker=AAPL"

response = requests.get(url, headers=headers)
snapshot = response.json().get("snapshot")

print(f"Price: ${snapshot['price']}")
```

## Available Tickers

You can fetch the full list of available tickers:

```
GET https://api.financialdatasets.ai/prices/tickers/
```

This returns all 27,000+ tickers with historical price data from exchanges like NYSE and NASDAQ, including 3 years of data.

## Next Steps

* [Stock Prices API Reference](/api/prices/historical) — full parameter documentation
* [Financial Statements Guide](/guides/analyze-financial-statements-python) — combine price data with fundamentals
* [Quick Start](/quickstart) — overview of all available endpoints
