Repository navigation
feat(ledger): BCB PTAX exchange-rate provider - #355
Merged
Merged
Conversation
sonikro
force-pushed
the
feat/ledger-fx
branch
from
October 11, 2026 02:55
dd0b8e9 to
4ecfafb
Compare
sonikro
force-pushed
the
feat/ledger-fx
branch
3 times, most recently
from
October 15, 2026 12:55
adb6d02 to
5afa59d
Compare
Follow the repository convention for a module whose main export is a class, and keep the export path in the fx barrel in step. The exported BcbPtaxProvider symbol is unchanged, so consumers are unaffected.
The provider queried CotacaoMoedaDia, which returns five bulletins for a business day with the opening rate first, and took values[0]. Every USD donation and the bot infrastructure cost were therefore converted at the opening rate while being recorded as the PTAX rate. Query CotacaoDolarDia instead, which returns exactly the closing bulletin row. Verified against the live endpoint for 2026-10-14: the old operation returned five rows starting at 5.04620, the new one returns the single closing row at 5.04410, identical to the last row of the old response. The date literal stays MM-DD-YYYY: the ISO form returns HTTP 200 with an empty value array, which is why the fallback walk never surfaced the problem.
The msw matchers are URL-specific, so a provider that reverted to the wrong BCB operation would not match any handler and the request would pass through to the live endpoint, letting the suite pass against the real API. Make an unhandled request an error.
sonikro
force-pushed
the
feat/ledger-fx
branch
from
October 15, 2026 13:36
5afa59d to
4a032ea
Compare
This was referenced Oct 15, 2026
sonikro
marked this pull request as ready for review
October 15, 2026 13:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack 2/4 — BCB PTAX exchange rates (base:
feat/ledger-core)The exchange-rate provider the ledger uses to convert USD into BRL.
What this PR adds
BcbPtaxProvider: the BCB Olinda PTAX provider, with a 7-day step-back over non-publishingdays, a per-day cache, an abort timeout, and JSON/response guards.
fxbarrel of@tf2qs/providers.The fix this PR carries
The provider originally queried
CotacaoMoedaDia, which returns five bulletins for a businessday with the opening rate first, and took the first row. Every USD donation and the bot
infrastructure cost were therefore converted at the opening rate while being recorded as PTAX.
It now queries
CotacaoDolarDia, which returns exactly the closing bulletin. Verified againstthe live endpoint for 2026-10-14: the old operation returned five rows starting at 5.04620, the
new one returns the single closing row at 5.04410, identical to the last row of the old response.
The date literal must stay
MM-DD-YYYY: the ISO form returns HTTP 200 with an empty valuearray, which is why the fallback walk never surfaced the problem.
Testing
CI=true npx vitest run→ 105 files, 756 tests, 0 failures.npm run build:backend→ clean.msw'sonUnhandledRequest: "error", so reverting to the wrongoperation fails the tests instead of passing them against the live API.
Notes
release.yamlonly triggerspull_requestonmain, and thisbranch's base is another feature branch. It was verified locally at the stack tip.
quotedAtis parsed from the BCB timestamp without a zone, so it lands in host-local time.Nothing consumes it; fixing it is a follow-up.
Stack
Previous: #354 (
feat/ledger-core). Next: #356 (feat/ledger-commands→ this branch).