Split instrument IDs into batches for the Börsdata API, turn the quarterly reports in each reply into one row per stock and quarter, and use their publication dates.
After this lesson, you can request the quarterly reports of a list of stocks in batches, turn the replies into one row per stock and quarter, and check which figures were public on a date.
How do I split the IDs into batches?
range(0, len(instrument_ids), batch_size) gives the start of each batch, and slicing from each start takes up to batch_size IDs, so three IDs with a batch size of 2 give the batches [11, 22] and [33]. ",".join(map(str, batch)) writes each batch as the text the request needs, such as "11,22".
Börsdata accepts up to 50 instrument IDs per report request, and the example uses 2 on three made-up companies so the shorter last batch shows. A slice that runs past the end of the list stops at the end.
The following box makes the batches and their request texts.
ticker_of = {11: "AAA", 22: "BBB", 33: "CCC"}instrument_ids =list(ticker_of)batch_size =2batches = [instrument_ids[start:start + batch_size] for start inrange(0, len(instrument_ids), batch_size)]print(batches, [",".join(map(str, batch)) for batch in batches])
[[11, 22], [33]] ['11,22', '33']
How do I send each batch?
The borsdata-client package sends one request per batch to /instruments/reports with the IDs in instList, and each reply holds a reportList with one entry per instrument. maxR12QCount="40" asks for up to 40 quarters, maxYearCount="20" for up to 20 years, and original="1" for the reporting currency.
The access code comes from the environment variable BORSDATA_API_KEY, and with client closes the connection at the end. client._get is marked internal by its underscore, so the client’s version is pinned in the post on Börsdata stock data, which also shows the install command.
The following box, which does not run on this page, requests the reports in batches of 50.
from os import environfrom borsdata_client import BorsdataClientresponses = []with BorsdataClient(api_key=environ["BORSDATA_API_KEY"]) as client:for start inrange(0, len(instrument_ids), 50): batch = instrument_ids[start:start +50] responses.append(client._get("/instruments/reports", params={"instList": ",".join(map(str, batch)), "maxYearCount": "20", "maxR12QCount": "40", "original": "1"}))
How do I turn the replies into one row per quarter?
ReportsArrayResp(**response) checks each reply against the client’s model, and quarter.model_dump() turns each quarterly report into a dictionary, so a list comprehension gives one row per stock and quarter. AAA published its March quarter on 27 April 2026 with 2.5 million shares, CCC on 5 May with 4.0 million, and BBB has no quarterly report, so item.reports_quarter or [] gives it no rows.
**response passes each entry of the reply dictionary as a named argument. The made-up replies hold one March quarter each for AAA and CCC, with share counts in millions and the other required fields set to small values. Both reports cover the quarter ending 31 March, so using either share count on 1 April would be look-ahead bias, and a backtest uses a figure only after its publication date. With live data, item.error tells an error from a company without reports.
import pandas as pdfrom borsdata_client.models import ReportsArrayResprows = []for response in responses:for item in ReportsArrayResp(**response).report_list or []: rows += [{"ticker": ticker_of[item.instrument]} | quarter.model_dump() for quarter in item.reports_quarter or []]reports = pd.DataFrame(rows)[["ticker", "report_end_date", "report_date", "number_of_shares"]]print(reports)