What you'll build: A script that monitors your watchlist for upcoming dividends and recent stock splits, so you can track income from dividend-paying stocks and stay aware of corporate actions that affect share counts.
Endpoints used:
GET /v2/tickers/{symbol}/dividends— Get dividend history for a tickerGET /v2/tickers/{symbol}/splits— Get split history for a tickerGET /v2/tickers/{symbol}/eod/latest— Get current price for yield calculation
Scenario: You hold dividend-paying stocks (AAPL, MSFT, JNJ) and want to see recent dividend payments, calculate current yield, and check for any stock splits.
Step 1 — Get recent dividends for each ticker:
GET https://api.marketstack.com/v2/tickers/AAPL/dividends?access_key=YOUR_API_KEY&date_from=2025-01-01&sort=DESC&limit=10
Each dividend record includes dividend (amount per share), ex_date, record_date, pay_date, and declaration_date.
Step 2 — Get latest price to calculate yield:
GET https://api.marketstack.com/v2/eod/latest?access_key=YOUR_API_KEY&symbols=AAPL,MSFT,JNJ
Step 3 — Check for recent splits:
GET https://api.marketstack.com/v2/tickers/AAPL/splits?access_key=YOUR_API_KEY&date_from=2024-01-01
Python example:
python
import requests
from datetime import datetime, timedelta
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.marketstack.com/v2"
watchlist = ["AAPL", "MSFT", "JNJ"]
lookback_date = (datetime.now() - timedelta(days=365)).strftime("%Y-%m-%d")
# Step 1: Get latest prices for all tickers
symbols = ",".join(watchlist)
prices_resp = requests.get(f"{BASE_URL}/eod/latest", params={
"access_key": API_KEY,
"symbols": symbols
})
prices_data = {r["symbol"]: r["adj_close"] for r in prices_resp.json()["data"]}
# Step 2: Get dividends and splits for each ticker
print(f"{'='*60}")
print(f" Dividend & Corporate Actions Monitor")
print(f" Watchlist: {', '.join(watchlist)}")
print(f" Lookback: {lookback_date} to today")
print(f"{'='*60}\n")
for ticker in watchlist:
# Get dividends
div_resp = requests.get(f"{BASE_URL}/tickers/{ticker}/dividends", params={
"access_key": API_KEY,
"date_from": lookback_date,
"sort": "DESC",
"limit": 10
})
dividends = div_resp.json().get("data", [])
# Get splits
split_resp = requests.get(f"{BASE_URL}/tickers/{ticker}/splits", params={
"access_key": API_KEY,
"date_from": lookback_date
})
splits = split_resp.json().get("data", [])
# Current price
price = prices_data.get(ticker, 0)
# Calculate trailing 12-month yield
annual_dividends = sum(d["dividend"] for d in dividends)
dividend_yield = (annual_dividends / price * 100) if price > 0 else 0
print(f"--- {ticker} (${price:.2f}) ---")
print(f"Trailing 12-month dividends: ${annual_dividends:.2f}/share")
print(f"Current dividend yield: {dividend_yield:.2f}%")
if dividends:
print(f"\nRecent payments:")
for d in dividends[:4]: # Show last 4
ex_date = d.get("ex_date", "N/A")[:10]
pay_date = d.get("pay_date", "N/A")[:10] if d.get("pay_date") else "N/A"
print(f" ${d['dividend']:.4f} ex-date: {ex_date} pay-date: {pay_date}")
if splits:
print(f"\n⚠ Stock splits in period:")
for s in splits:
print(f" {s['date'][:10]} split factor: {s['split_factor']}")
elif not splits:
print(f"\nNo stock splits in this period.")
print()
# Summary table
print(f"{'='*60}")
print(f"{'Ticker':<8} {'Price':>10} {'Annual Div':>12} {'Yield':>8}")
print(f"{'-'*60}")
for ticker in watchlist:
price = prices_data.get(ticker, 0)
# Re-fetch for summary (in production, cache the dividend data)
div_resp = requests.get(f"{BASE_URL}/tickers/{ticker}/dividends", params={
"access_key": API_KEY,
"date_from": lookback_date,
"sort": "DESC",
"limit": 10
})
annual_div = sum(d["dividend"] for d in div_resp.json().get("data", []))
yld = (annual_div / price * 100) if price > 0 else 0
print(f"{ticker:<8} {price:>10.2f} {annual_div:>12.2f} {yld:>7.2f}%")
print(f"{'='*60}")Example output:
============================================================
Dividend & Corporate Actions Monitor
Watchlist: AAPL, MSFT, JNJ
Lookback: 2024-09-11 to today
============================================================
--- AAPL ($237.45) ---
Trailing 12-month dividends: $1.00/share
Current dividend yield: 0.42%
Recent payments:
$0.2500 ex-date: 2025-08-11 pay-date: 2025-08-14
$0.2500 ex-date: 2025-05-12 pay-date: 2025-05-15
$0.2500 ex-date: 2025-02-10 pay-date: 2025-02-13
$0.2500 ex-date: 2024-11-08 pay-date: 2024-11-14
No stock splits in this period.
--- MSFT ($442.18) ---
Trailing 12-month dividends: $3.32/share
Current dividend yield: 0.75%
Recent payments:
$0.8300 ex-date: 2025-08-20 pay-date: 2025-09-11
$0.8300 ex-date: 2025-05-15 pay-date: 2025-06-12
$0.8300 ex-date: 2025-02-19 pay-date: 2025-03-13
$0.8300 ex-date: 2024-11-20 pay-date: 2024-12-12
No stock splits in this period.
--- JNJ ($162.30) ---
Trailing 12-month dividends: $5.04/share
Current dividend yield: 3.10%
Recent payments:
$1.2600 ex-date: 2025-08-25 pay-date: 2025-09-09
$1.2600 ex-date: 2025-05-27 pay-date: 2025-06-10
$1.2600 ex-date: 2025-02-24 pay-date: 2025-03-11
$1.2600 ex-date: 2024-11-25 pay-date: 2024-12-10
No stock splits in this period.
============================================================
Ticker Price Annual Div Yield
------------------------------------------------------------
AAPL 237.45 1.00 0.42%
MSFT 442.18 3.32 0.75%
JNJ 162.30 5.04 3.10%
============================================================Tips:
The
ex_dateis the key date for dividend eligibility — you must own the stock before this date to receive the paymentDividend amounts are per share and not adjusted for splits — if a 2:1 split occurred, pre-split dividends will appear double the post-split amount
Run this script weekly or monthly rather than daily — dividend announcements don't change frequently
For a production dashboard, cache the dividend data and only re-fetch when a new quarter begins
Companies may pay dividends quarterly (most US stocks), semi-annually, or annually — the pattern varies