-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_fmp_api.py
More file actions
57 lines (43 loc) · 1.71 KB
/
test_fmp_api.py
File metadata and controls
57 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""Manual smoke test for the Financial Modeling Prep earnings API."""
from __future__ import annotations
import os
from pathlib import Path
import pytest
import requests
def _load_backtesting_env() -> None:
env_path = Path("backtesting/.env")
if not env_path.exists():
return
with open(env_path, encoding="utf-8") as f:
for line in f:
if "=" in line and not line.startswith("#"):
key, value = line.strip().split("=", 1)
os.environ.setdefault(key, value)
def _masked_key(api_key: str) -> str:
if len(api_key) <= 10:
return "***"
return f"{api_key[:5]}...{api_key[-5:]}"
def test_fmp_api_smoke() -> None:
_load_backtesting_env()
api_key = os.getenv("FMP_API_KEY")
if not api_key:
pytest.skip("FMP_API_KEY is not configured; skipping live FMP smoke test.")
print(f"FMP API Key: {_masked_key(api_key)}")
symbols = ["AAPL", "MSFT", "AMZN", "NVDA", "GOOGL"]
for symbol in symbols:
url = f"https://financialmodelingprep.com/api/v3/earnings-surprises/{symbol}?apikey={api_key}"
response = requests.get(url, timeout=10)
print(f"{symbol}: {response.status_code}")
response.raise_for_status()
assert isinstance(response.json(), list)
url = f"https://financialmodelingprep.com/api/v3/earnings_calendar?from=2022-01-01&to=2022-06-30&apikey={api_key}"
response = requests.get(url, timeout=10)
response.raise_for_status()
assert isinstance(response.json(), list)
if __name__ == "__main__":
_load_backtesting_env()
key = os.getenv("FMP_API_KEY")
if not key:
raise SystemExit("FMP_API_KEY is not configured.")
test_fmp_api_smoke()