Last active
August 30, 2024 15:22
-
-
Save lucashmsilva/9f4596f2924ac5c1eb0721c2c41dc257 to your computer and use it in GitHub Desktop.
API para criar a 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 Junto com a taxa anual de retorno | |
* @customfunction | |
**/ | |
function TESOURODIRETO(bondName) { | |
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 === bondName) | |
return [bond.TrsrBd.untrRedVal, bond.TrsrBd.anulInvstmtRate]; // créditos ao @figueiredods por ter encontrado o campo que retorna a taxa correta | |
} | |
throw new Error("Not Found"); | |
} |
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 | |
* @customfunction | |
**/ | |
function TESOURODIRETO(bondName) { | |
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 === bondName) | |
return bond.TrsrBd.untrRedVal; | |
} | |
throw new Error("Not Found"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Já, vide https://gist.github.com/danperrout/b27197056fa38d0d669332647ab89d7a?permalink_comment_id=5159964#gistcomment-5159964