-
-
Save thiagoszbarros/d07d4ff63c3414bfc182c9b643ff5057 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 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://www.tesourodireto.com.br/json/br/com/b3/tesourodireto/service/api/treasurybondsinfo.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