Last active
December 8, 2025 04:18
-
-
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
Sensacional, funcionou perfeitamente, muito obrigado @hugobrilhante! e creio que sua solução vai ser duradoura. E pra quem quiser buscar outros valores é só trocar o 5 no "let precoTexto = latestMatch.columns[5].trim();" que voce vai ter outros resultados, o 5 por padrão é o valor de compra, como está comentado " [0]Tipo Titulo, [1]Data Vencimento, [2]Data Base, [5]PU Compra Manha" e acrescento que o 6 é o valor de venda. Não testei, mas creio que 3 e 4 são as taxas de compra e venda, respectivamente, vale o teste para quem quiser.