Skip to content

Instantly share code, notes, and snippets.

@danperrout
Last active January 24, 2026 19:37
Show Gist options
  • Select an option

  • Save danperrout/b27197056fa38d0d669332647ab89d7a to your computer and use it in GitHub Desktop.

Select an option

Save danperrout/b27197056fa38d0d669332647ab89d7a to your computer and use it in GitHub Desktop.
API Função TESOURODIRETO Google Sheets
/*
* @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;
}
}
@robsonrb77
Copy link

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