Last active
November 6, 2024 16:03
-
-
Save danperrout/b27197056fa38d0d669332647ab89d7a to your computer and use it in GitHub Desktop.
API Função TESOURODIRETO Google Sheets
This file contains 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. | |
* 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
Perfeito Artur! Valeu!