What you'll build: A script that takes a list of stock tickers and returns the current value of each holding, total portfolio value, and daily change — the core of any portfolio dashboard.
Endpoints used:
GET /v2/eod/latest— Get the most recent closing pricesGET /v2/tickers/{symbol}— Look up company name and exchange infoGET /v2/currencies— Verify the trading currency for each holding
Scenario: You hold 50 shares of AAPL, 20 shares of MSFT, and 100 shares of GOOGL. You want to see each position's current market value and your total portfolio value.
Step 1 — Get the latest closing prices for your holdings:
GET https://api.marketstack.com/v2/eod/latest?access_key=YOUR_API_KEY&symbols=AAPL,MSFT,GOOGL
This single call returns the latest EOD data for all three tickers. Each record includes close (the closing price) and adj_close (adjusted for splits and dividends).
Step 2 — Enrich with company details (optional):
If you want to display company names and exchange information alongside prices:
GET https://api.marketstack.com/v2/tickers/AAPL?access_key=YOUR_API_KEY
Repeat for each ticker, or use /v2/tickerslist?search=AAPL for autocomplete-style lookups.
Step 3 — Calculate portfolio value:
Python example:
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.marketstack.com/v2"
# Your portfolio: ticker → shares held
portfolio = {
"AAPL": 50,
"MSFT": 20,
"GOOGL": 100
}
# Step 1: Get latest closing prices
symbols = ",".join(portfolio.keys())
response = requests.get(f"{BASE_URL}/eod/latest", params={
"access_key": API_KEY,
"symbols": symbols
})
data = response.json()
if "error" in data:
print(f"API Error: {data['error']['message']}")
exit()
# Step 2: Calculate position values
total_value = 0
print(f"{'Ticker':<8} {'Shares':>8} {'Price':>10} {'Value':>12} {'Daily Chg':>10}")
print("-" * 52)
for record in data["data"]:
ticker = record["symbol"]
price = record["adj_close"] # Use adjusted close for accuracy
shares = portfolio[ticker]
value = shares * price
# Daily change: close vs open
daily_change = ((record["close"] - record["open"]) / record["open"]) * 100
total_value += value
print(f"{ticker:<8} {shares:>8} {price:>10.2f} {value:>12.2f} {daily_change:>+9.2f}%")
print("-" * 52)
print(f"{'Total':<8} {'':>8} {'':>10} {total_value:>12.2f}")Example output:
Ticker Shares Price Value Daily Chg
----------------------------------------------------
AAPL 50 237.45 11,872.50 +0.84%
MSFT 20 442.18 8,843.60 -0.32%
GOOGL 100 178.92 17,892.00 +1.15%
----------------------------------------------------
Total 38,608.10Tips:
Use
adj_closeinstead ofclosefor accurate long-term tracking — it accounts for splits and dividendsThe
symbolsparameter accepts up to multiple tickers in one call, reducing your request countCache ticker details (
/v2/tickers/{symbol}) since company names and exchange info rarely changeCall this once per day after market close — EOD data is final; calling more often won't return new data