These reports follow the COSIF standard and must match the XML structure defined by BACEN. You can adapt the logic to your own data model, but the XML format must be respected.
What is CADOC 4111?
The CADOC 4111 is a regulatory document required by the Brazilian Central Bank (BACEN) that reports daily balances of accounting accounts grouped by COSIF code (Chart of Accounts for Institutions of the National Financial System).
What BACEN expects to receive
- Consolidated balances by COSIF code
- Report base date
- Institution’s CNPJ (first 8 digits)
- Submission type (
I= Inclusion,S= Replacement)
Submission requirements
| Document | Deadline | STA Code |
|---|---|---|
| 4111 | Day following the reference date (or next business day) | ACOS011 |
The STA code identifies the document type in BACEN’s transmission system. Use
ACOS011 when submitting CADOC 4111.Understanding the data structure
Before building the template, it’s essential to understand how data is organized in the Midaz ledger.
Operation routes
Operation routes function as accounting classifiers. Each route has:- Unique identifier (
id): Used internally to relate operations - COSIF code (
code): The 10-digit accounting code that will be reported to BACEN
Operations
Operations represent financial movements in the ledger. Each operation contains:- Associated account (
account_id): Which account was affected - Route (
route): ID of the applied accounting route/classification - Balance after operation (
available_balance_after): The account balance immediately after this operation - Date and time (
created_at): When the operation occurred
Relationship between routes and operations

CADOC structure
Base format
The CADOC report must be an XML file and must follow the structure defined by BACEN:Mandatory fields
These fields are required and must be included:<?xml version="1.0" encoding="UTF-8"?>
Always starts the file. It defines the XML version and encoding so the system knows how to read the content.
<documento> tag
Wraps the entire CADOC structure and includes:
| Field | Description | Format |
|---|---|---|
codigoDocumento | Fixed identifier | "4111" |
cnpj | First 8 digits of CNPJ | Numeric, 8 positions |
dataBase | Reference date | YYYY-MM |
tipoRemessa | Submission type | "I" or "S" |
If your first submission was rejected due to errors, you still need to use
"I" on your next attempt. Only use "S" for replacing previously approved data.<contas> tag
Groups all account entries for the reporting period.
<conta> tag
codigoConta: COSIF code from the operation route (10 numeric digits)saldoDia: Consolidated balance in decimal format (two decimal places)
Template construction logic
General structure
The template follows an aggregation logic at two levels:- First level: Iterate through all available operation routes
- Second level: For each route, sum the balances of linked operations
Document header
The XML header must contain:- Document code: Fixed identifier
4111 - CNPJ: Extracted from organization data, limited to first 8 digits
- Base date: Report generation date in
YYYY-MMformat - Submission type:
Ifor inclusion
Iterating over routes
The template must iterate through all registered operation routes. For each route:- Check for COSIF code: Only routes with a valid COSIF code should generate lines in the report
- Filter operations: Select only operations belonging to that specific route
- Calculate balance: Sum the balances of filtered operations
Not all routes have a COSIF code filled in. Routes without a code are used for internal controls and should not appear in the regulatory report.
Filtering operations by route
The association between operations and routes is made through the route identifier. The template uses this identifier to:- Access a specific route
- Find all operations that reference this route
- Process only these operations in the aggregation
Summing balances
For each set of operations from a route, the template sums the available balances. The field used is the available balance after each operation. The aggregation function iterates through all operations that meet the filter criteria (same route) and accumulates the balance field values.Using Reporter
Here’s the complete template for generating CADOC 4111 in Reporter:
Code breakdown
Line 1 - XML declaration
Line 2 - Root element <documento>
codigoDocumento="4111": Fixed document type identifiercnpj: Accesses the organization’s legal document and extracts the first 8 characters using theslicefilterdataBase: Generates the current date in BACEN’s required format using thedate_timetagtipoRemessa="I": Indicates data inclusion
Line 4 - Start of for loop
op_route: Variable that receives each route during iteration (name chosen to avoid conflict with theroutefield in operations)midaz_transaction.operation_route: Collection of all operation routes
Line 5 - if condition
Line 6 - <conta> element
codigoConta: Displays the current route’s COSIF codesaldoDia: Uses thesum_bytag to sum balances, filtering only operations whose route matches the current route identifier (op_route.id)
Lines 7-8 - Closing blocks
Tags and filters reference
| Element | Type | Function |
|---|---|---|
{{ variable }} | Expression | Displays a variable’s value |
{% tag %} | Tag | Executes logic (loop, condition, aggregation) |
|slice:":8" | Filter | Extracts the first 8 characters |
for ... in | Tag | Iterates through a collection |
if | Tag | Execution condition |
sum_by ... by ... if | Tag | Sums values with conditional filter |
date_time | Tag | Generates formatted date |
Date filter considerations
Request example with date filter
To generate CADOC 4111 for a specific day, send aPOST /v1/reports request with the X-Organization-Id header and the following body:
Field explanation
| Field | Description |
|---|---|
templateId | CADOC 4111 template identifier registered in Reporter |
filters.midaz_transaction.operation | Indicates the filter will be applied to the operations collection |
created_at.between | Filters operations created within the specified interval |
between[0] | Start date and time (midnight of desired day) |
between[1] | End date and time (last second of desired day) |
Dates must be in ISO 8601 format with UTC timezone (
Z).Template evolution and balance extraction
We are working on evolving our main template to support balance aggregation in compliance with BACEN CADOC 4111, which requires the final balance from the last business day. While this feature is being developed, we provide an alternative version for extracting these balances using the following template.
Extraction template
This auxiliary template is designed to correctly calculate balances, ensuring compliance of your reports through the following steps:- Group operations by account
- Sort entries by date and time
- Select the last record from each account to obtain the final balance
- Sum final balances by COSIF code
Extraction template example
Extraction output
The template exports all operations in CSV format, containing:- Account identifier
- Account alias
- COSIF code
- Operation date and time
- Available balance
Best practices for template construction
Variable naming
Use descriptive and unique names for iteration variables, avoiding conflicts with entity field names.Field validation
Always check if optional fields have values before using them. Empty fields can generate unwanted lines in the report.Date format
BACEN requires dates inYYYY-MM format. Make sure to configure the format correctly in the template.
CNPJ handling
The CNPJ must be presented with only the first 8 digits, without formatting (dots, slashes, or dashes).Component summary
| Component | Data Source | Usage in Template |
|---|---|---|
| CNPJ | Organization (Onboarding) | Document header |
| COSIF Code | Operation Route (Transaction) | Account identifier |
| Balance | Operation (Transaction) | Value to be aggregated |
| Base Date | Current date function | Document header |

