Fix currency.get() by migrating from discontinued BCB CSV to PTAX OData API#28
Open
Fix currency.get() by migrating from discontinued BCB CSV to PTAX OData API#28
Conversation
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: wilsonfreitas <1583922+wilsonfreitas@users.noreply.github.com> Agent-Logs-Url: https://github.com/wilsonfreitas/python-bcb/sessions/a113f59b-1247-4385-80e1-8e951d69a4d7
Copilot
AI
changed the title
[WIP] Fix error when fetching currency data using currency.get
Fix currency.get() by migrating from discontinued BCB CSV to PTAX OData API
Mar 24, 2026
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.
currency.get()was broken becausehttp://www4.bcb.gov.br/Download/fechamento/M{date}.csvnow returns an HTML "Requisição inválida!" error page (HTTP 200) instead of CSV, causingpandas.errors.ParserErroron every call.Changes
bcb/currency.pyReplaced the two-step legacy approach (HTML form scrape for numeric IDs + broken CSV for symbol mapping) with direct calls to the official BCB PTAX OData API at
olinda.bcb.gov.br:_get_valid_currency_list()— brokenwww4.bcb.gov.brCSVget_currency_list()→/Moedas?$format=json_currency_id_list()— HTML<select>scraper for numeric IDs_validate_currency_symbol()— checks symbol against OData list_get_currency_id()— merged both above to get symbol → numeric ID_currency_url()— numeric-ID-based HTML endpoint URL_currency_url()→CotacaoMoedaPeriodo(moeda=@moeda,...)OData function_get_symbol()— parsed semicolon-delimited CSV_get_symbol()— parses OData JSON, filterstipoBoletim == "Fechamento"for closing ratesRemoved now-unused imports:
re,warnings,date,timedelta,BytesIO,StringIO,numpy,lxml.html.get_currency_list()column schema changes: previously returnedcode,name,symbol,country_code,country_name,type,exclusion_date(from CSV); now returnssymbol,name,type(from ODataMoedasendpoint).tests/conftest.py+tests/test_currency.pyReplaced HTML/CSV mock fixtures with OData JSON mocks. Tests for removed helpers (
_currency_id_list,_get_currency_id) replaced with tests for_validate_currency_symbol.Example
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
astral.sh/usr/bin/curl curl -LsSf REDACTED(dns block)releases.astral.sh/home/REDACTED/.local/bin/uv uv sync(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.