Last active
January 24, 2026 19:37
-
-
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 Acessa radaropcoes.com e retorna informações de um título específico do Tesouro Direto | |
| * Endpoint: https://api.radaropcoes.com/bonds/{bondName} | |
| */ | |
| function TESOURODIRETO(bondName, argumento = "r") { | |
| let srcURL = "https://api.radaropcoes.com/bonds/" + encodeURIComponent(bondName); | |
| let response = UrlFetchApp.fetch(srcURL, { | |
| muteHttpExceptions: true | |
| }); | |
| console.log(srcURL) | |
| if (response.getResponseCode() !== 200) { | |
| throw new Error("Erro ao acessar a API ou título não encontrado."); | |
| } | |
| let bond = JSON.parse(response.getContentText()); | |
| // argumento: | |
| // "r" → valor de resgate | |
| // qualquer outro → valor unitário de investimento | |
| if (argumento === "r") { | |
| return bond.unitaryRedemptionValue; | |
| } else { | |
| return bond.unitaryInvestmentValue; | |
| } | |
| } |
Author
Funcionou perfeitamente para mim, parabéns Daniel.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.youtube.com/watch?v=a7JCfMpRhD0&t=1s