Last active
November 22, 2025 03:07
-
-
Save danperrout/b27197056fa38d0d669332647ab89d7a to your computer and use it in GitHub Desktop.
API 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 Acesse radaropcoes.com Retorna a cotação atual de um título específico do Tesouro Direto. | |
| * API: https://radaropcoes.com/ | |
| * Fonte: https://www.tesourodireto.com.br/titulos/precos-e-taxas.htm | |
| **/ | |
| function TESOURODIRETO(bondName, argumento="r") { | |
| let srcURL = "https://api.radaropcoes.com/bonds.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.toLowerCase() === bondName.toLowerCase()) | |
| if(argumento == "r") | |
| return bond.TrsrBd.untrRedVal; | |
| else | |
| return bond.TrsrBd.untrInvstmtVal; | |
| } | |
| throw new Error("Título não encontrado."); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Criei essa versão que busca só o preço. Demora um pouco por conta do tamanho do arquivo mas funciona.