Last active
June 8, 2026 16:50
-
-
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
| // ============================================================ | |
| // COLE SEU TOKEN AQUI (entre as aspas). | |
| // Gere em https://radaropcoes.com → /profile/ → card API. | |
| // ============================================================ | |
| const RADAR_TOKEN = "rop_COLE_SEU_TOKEN_AQUI"; | |
| // ============================================================ | |
| /* | |
| * @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, { | |
| headers: { "Authorization": "Bearer " + RADAR_TOKEN }, | |
| 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()); | |
| // A API responde 200 mesmo com token inválido/ausente/quota: campos numéricos vêm null | |
| // e os textos contêm a mensagem do erro. Surface esse caso pro usuário. | |
| if (bond.treasuryBondCode === null) { | |
| throw new Error(bond.indication); | |
| } | |
| // argumento: | |
| // "r" → valor de resgate | |
| // qualquer outro → valor unitário de investimento | |
| if (argumento === "r") { | |
| return bond.unitaryRedemptionValue; | |
| } else { | |
| return bond.unitaryInvestmentValue; | |
| } | |
| } |
@andreluistosato agradeço por ter compartilhado seu conhecimento. Resolveu aqui. Vida longa a você.
Author
Tem algum lugar com mais instruções de como utilizar? O código, instruções de como puxar para o Google planilhas, etc? Obrigado! Sucesso!
Funcionou perfeitamente para mim, parabéns Daniel.
Aqui parou de funcionar. Aparace a informação: https://api.radaropcoes.com/bonds/undefined
Author
Entre em radaropcoes.com para gerar um token
Em seg., 8 de jun. de 2026 às 14:36, Alexandre Azevedo <
***@***.***> escreveu:
… ***@***.**** commented on this gist.
------------------------------
Aqui parou de funcionar. Aparace a informação:
https://api.radaropcoes.com/bonds/undefined
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/danperrout/b27197056fa38d0d669332647ab89d7a#gistcomment-6188324>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA47QFEX3UQOJIFUZUQQZT34626M7BFHORZGSZ3HMVZKMY3SMVQXIZNMON2WE2TFMN2F65DZOBS2WR3JON2EG33NNVSW45FGORXXA2LDOOIYFJDUPFYGLJDHNFZXJJLWMFWHKZNJGEYDIMZVHA3DIM5KMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJZYGUZDGMRWHCSG4YLNMWUGCY3UN5ZF62LEQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZQKSXMYLMOVS2IZ3JON2KI3TBNVS2W5DIOJSWCZC7OR4XAZI>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quão difícil é isso para alguém que não tem esse conhecimento técnico todo?
Eu estou frustrado com toda esse mudança do site do Tesouro Direto pois o script que eu usava funcionou muito bem por muitos anos.
Ficarei muito grato se puder me dar orientações ou referências para que eu consiga implementar isso na minha planilha.
Sei que estou pedindo muito e entenderei caso não consiga.
Muito obrigado por toda informação compartilhada até agora.