Examples & tutorials
Copy-paste starting points for common builds.
Tutorials
- Real-time stock news alert bot (Python, WebSocket, Discord)
- Give an AI agent real-time market news (tool calling, RAG)
- REST vs WebSocket: which to use
Poll for new articles (Node.js)
poll.mjs
const KEY = process.env.MARKETNEWSAPI_KEY;
let since = new Date(Date.now() - 5 * 60_000).toISOString();
const seen = new Set();
async function poll() {
const params = new URLSearchParams({ tickers: "AAPL,TSLA", from: since, sort: "published_asc", limit: "100" });
const res = await fetch(`https://api.marketnewsapi.com/v1/news?${params}`, { headers: { Authorization: `Bearer ${KEY}` } });
const { data } = await res.json();
for (const a of data) {
if (seen.has(a.id)) continue;
seen.add(a.id);
since = a.published_at;
console.log(a.published_at, a.tickers.join(","), a.title);
}
}
setInterval(poll, 15_000);
poll();Most-talked-about symbols (cURL + jq)
curl -s "https://api.marketnewsapi.com/v1/trending?window=1h&limit=10" \
-H "Authorization: Bearer $MARKETNEWSAPI_KEY" \
| jq -r '.data[] | "\(.symbol)\t\(.articles)"'Latest press releases with full text (Python)
import os
import requests
r = requests.get(
"https://api.marketnewsapi.com/v1/news",
params={"type": "press_release", "tickers": "PFE", "limit": 5},
headers={"Authorization": f"Bearer {os.environ['MARKETNEWSAPI_KEY']}"},
timeout=10,
)
for a in r.json()["data"]:
print(a["title"])
print((a["body"] or "")[:500], "\n")Generate a client from OpenAPI
Point any OpenAPI 3.1 generator at https://marketnewsapi.com/openapi.json:
npx @openapitools/openapi-generator-cli generate \
-i https://marketnewsapi.com/openapi.json -g python -o ./marketnewsapi-client