Last active
November 17, 2025 13:06
-
-
Save lucashmsilva/9f4596f2924ac5c1eb0721c2c41dc257 to your computer and use it in GitHub Desktop.
API para criar a função TESOURODIRETO Google Sheets
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
| /* | |
| * @return Retorna a cotação atual de um título específico do Tesouro Direto Junto com a taxa anual de retorno | |
| * @customfunction | |
| **/ | |
| function TESOURODIRETO(bondName) { | |
| let srcURL = "https://www.tesourodireto.com.br/json/br/com/b3/tesourodireto/service/api/treasurybondsinfo.json"; | |
| let jsonData = UrlFetchApp.fetch(srcURL); | |
| let parsedData = JSON.parse(jsonData.getContentText()).response; | |
| for(let bond of parsedData.TrsrBdTradgList) { | |
| let currBondName = bond.TrsrBd.nm; | |
| if (currBondName === bondName) | |
| return [bond.TrsrBd.untrRedVal, bond.TrsrBd.anulInvstmtRate]; // créditos ao @figueiredods por ter encontrado o campo que retorna a taxa correta | |
| } | |
| throw new Error("Not Found"); | |
| } |
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
| /* | |
| * @return Retorna a cotação atual de um título específico do Tesouro Direto | |
| * @customfunction | |
| **/ | |
| function TESOURODIRETO(bondName) { | |
| let srcURL = "https://www.tesourodireto.com.br/json/br/com/b3/tesourodireto/service/api/treasurybondsinfo.json"; | |
| let jsonData = UrlFetchApp.fetch(srcURL); | |
| let parsedData = JSON.parse(jsonData.getContentText()).response; | |
| for(let bond of parsedData.TrsrBdTradgList) { | |
| let currBondName = bond.TrsrBd.nm; | |
| if (currBondName === bondName) | |
| return bond.TrsrBd.untrRedVal; | |
| } | |
| throw new Error("Not Found"); | |
| } |
Alguém já conseguiu solucionar o problema?
Alguém já conseguiu solucionar o problema?
Pessoal, a API do Tesouro Direto está indisponível desde agosto. Vocês conhecem uma outra API ou forma de atualização que esteja funcionando atualmente?
Pra quem teve o problema de perder acesso a API, realmente saiu do ar, neste thread já tem gente falando sobre isso e apontando soluções:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@EduardoJM vamos focar a conversa no link que o tulio mandou acima: https://gist.github.com/danperrout/b27197056fa38d0d669332647ab89d7a?permalink_comment_id=5159964#gistcomment-5159964