spb/hfmarketdata
Public
Open high-frequency market data platform — FirstRate full-history downloader, DuckDB/Parquet lake, open REST API and React docs platform (www.hfmarketdata.io)
JavaScript 53.7%
Python 38.3%
CSS 4.6%
TypeScript 3.1%
1"""Bulk fundamentals extracts: listing, Parquet download, ETag / 304."""2from __future__ import annotations34import io56import pandas as pd7import pytest89pytestmark = pytest.mark.usefixtures("fundamentals_data")101112def test_bulk_list_and_download_with_etag(client):13 r = client.get("/v1/bulk/fundamentals")14 assert r.status_code == 20015 years = [y["year"] for y in r.json()["data"]]16 assert 2024 in years17 r = client.get("/v1/bulk/fundamentals/2024.parquet")18 assert r.status_code == 200 and r.headers["content-type"] == "application/vnd.apache.parquet"19 etag = r.headers["ETag"]20 assert etag.startswith('"') and int(r.headers["X-Row-Count"]) > 021 df = pd.read_parquet(io.BytesIO(r.content))22 assert set(df["ticker"]) == {"AAPL", "MSFT", "SHAK"} and set(df["fiscal_year"]) == {2024}23 assert {"income", "balance", "cashflow"} == set(df["statement"])24 aapl_q2 = df[(df.ticker == "AAPL") & (df.statement == "income") & (df.fiscal_quarter == 2)]25 assert len(aapl_q2) == 1 and float(aapl_q2["revenue"].iloc[0]) == 90_753_000_00026 # latest version only: one row per (company, statement, period)27 assert not df.duplicated(["cik", "statement", "fiscal_year", "fiscal_quarter"]).any()28 r304 = client.get("/v1/bulk/fundamentals/2024.parquet", headers={"If-None-Match": etag})29 assert r304.status_code == 304 and r304.headers["X-Row-Count"] == "0" and r304.headers["ETag"] == etag30 r = client.get("/v1/bulk/fundamentals/2024.parquet", headers={"If-None-Match": '"stale"'})31 assert r.status_code == 20032 listed = next(y for y in client.get("/v1/bulk/fundamentals").json()["data"] if y["year"] == 2024)33 assert listed["etag"] == etag and listed["stale"] is False343536def test_bulk_errors(client):37 r = client.get("/v1/bulk/fundamentals/1999.parquet")38 assert r.status_code == 400 and r.json()["error"]["code"] == "INVALID_PARAMETER"39 r = client.get("/v1/bulk/fundamentals/2099.parquet")40 assert r.status_code == 404 and r.json()["error"]["code"] == "NOT_FOUND" and "available_years" in r.json()["error"]["details"]41