Skip to content

Commit 806754c

Browse files
committed
Fiscal data
1 parent 3d227c6 commit 806754c

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

quantflow/data/fiscal_data.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,17 @@ async def securities(self, record_date: date | None = None) -> pd.DataFrame:
4646

4747
async def get_all(self, path: str, params: dict[str, str]) -> list:
4848
"""Get all data from the API"""
49-
url = f"{self.url}{path}"
50-
payload = await self.get(url, params=params)
51-
data = payload["data"]
52-
return data
49+
next_url: str | None = f"{self.url}{path}"
50+
full_data = []
51+
while next_url:
52+
payload = await self.get(next_url, params=params)
53+
full_data.extend(payload["data"])
54+
params = {}
55+
if links := payload.get("links"):
56+
if next_path := links.get("next"):
57+
next_url = f"{self.url}{next_path}"
58+
else:
59+
next_url = None
60+
else:
61+
next_url = None
62+
return full_data

quantflow_tests/test_data.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from aiohttp.client_exceptions import ClientError
55

66
from quantflow.data.fed import FederalReserve
7+
from quantflow.data.fiscal_data import FiscalData
78
from quantflow.data.fmp import FMP
89

910
pytestmark = pytest.mark.skipif(not FMP().key, reason="No FMP API key found")
@@ -50,3 +51,14 @@ async def test_fed_rates() -> None:
5051
assert df.shape[1] == 2
5152
except (ConnectionError, ClientError) as e:
5253
pytest.skip(f"Skipping test_fed due to network issue: {e}")
54+
55+
56+
async def __test_fiscal_data() -> None:
57+
try:
58+
async with FiscalData() as fd:
59+
df = await fd.securities()
60+
assert df is not None
61+
assert df.shape[0] > 0
62+
assert df.shape[1] == 2
63+
except (ConnectionError, ClientError) as e:
64+
pytest.skip(f"Skipping test_fed due to network issue: {e}")

0 commit comments

Comments
 (0)