Skip to content

Commit

Permalink
Indicadores fundamentalistas e bitcoin
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorgamer58 authored Oct 20, 2020
2 parents 90f6934 + 8fb3d08 commit acec003
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 11 deletions.
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
# Telegram_Bot_Bovespa
Este é o código Backend escrito em Python de um Bot do Telegram

## Funcionamento em Funções
A função principal do Bot é retornar a cotação de alguma ação listada na Bolsa de Valores B3, de acordo com a solicitação do usuário
A solicitação das cotações se dá através da API [mfinance](https://mfinance.com.br/swagger/index.html)
## Instalação
abra /src/conf/.env e digite o token do seu bot do telegram na linha 1 e então na pasta raiz, digite:

pip install -r requirements.txt
python scr/core.py

e então baixe o programa [phoemur](https://github.com/phoemur/fundamentus) e na pasta raiz deste digite

python fundamentos.py

A unica função disponível é /price + código da ação em letras maiusculas
com os dois programas rodando, basta usar

## Funcionamento em Funções
A função principal do Bot é retornar a cotação de alguma ação listada na Bolsa de Valores B3, de acordo com a solicitação do usuário, a solicitação das cotações se dá através da API [mfinance](https://mfinance.com.br/swagger/index.html), a solicitação dos fundamentos atráves do programa phoemur, e o preço do bitcoin atráves da api da biscoint.
| Funções | Descrição |
|--|--|
| /price + código da ação | retorna a cotação e a variação no dia |
| /bitcoin | retorna a cotação do bitcoin |
| /fundamentus + código da ação | retorna indicadores fundamentalistas

## Devidos créditos e direitos autorais de terceiros
O código base para a criação deste bot se deu por um tutorial postado no medium.com de autoria do Mauro de Carvalho, que pode ser encontrado aqui: [https://medium.com/@mdcg.dev/desenvolvendo-o-seu-primeiro-chatbot-no-telegram-com-python-a9ad787bdf6](https://medium.com/@mdcg.dev/desenvolvendo-o-seu-primeiro-chatbot-no-telegram-com-python-a9ad787bdf6)
O código base para a criação deste bot se deu por um tutorial postado no medium.com de autoria do Mauro de Carvalho, que pode ser encontrado aqui: [https://medium.com/](https://medium.com/@mdcg.dev/desenvolvendo-o-seu-primeiro-chatbot-no-telegram-com-python-a9ad787bdf6)

O código base encontra-se aqui: [/commit/a64fe47fb1b5f101ea68736c3099d9b7f9a08b67](https://github.com/vitorgamer58/Telegram_Bot_Bovespa/commit/a64fe47fb1b5f101ea68736c3099d9b7f9a08b67)

Para o preço do bitcoin usa-se a api da [Biscoint](https://biscoint.io/)

O código base encontra-se aqui: [https://github.com/vitorgamer58/Telegram_Bot_Bovespa/commit/a64fe47fb1b5f101ea68736c3099d9b7f9a08b67](https://github.com/vitorgamer58/Telegram_Bot_Bovespa/commit/a64fe47fb1b5f101ea68736c3099d9b7f9a08b67)
### Fundamentus
Utiliza-se o código [phoemur](https://github.com/phoemur/fundamentus) que puxa os dados do site [Fundamentus](https://fundamentus.com.br/)

### Licença
## Licença
Você é livre para usar, copiar, modificar, distribuir, fazer uso privado ou comercial, **desde que** dê os devidos créditos aos autores, de acordo com a [licença MIT](https://github.com/vitorgamer58/Telegram_Bot_Bovespa/blob/master/LICENSE).
3 changes: 2 additions & 1 deletion src/conf/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TELEGRAM_TOKEN=
BASE_API_URL=https://mfinance.com.br/api/v1/stocks/
BISCOINT_API_URL=https://api.biscoint.io/v1/ticker?base=BTC&quote=BRL
BISCOINT_API_URL=https://api.biscoint.io/v1/ticker?base=BTC&quote=BRL
FUNDAMENTUS=http://127.0.0.1:5000/
3 changes: 2 additions & 1 deletion src/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
BASE_API_URL = os.getenv("BASE_API_URL")
BISCOINT = os.getenv("BISCOINT_API_URL")
BISCOINT = os.getenv("BISCOINT_API_URL")
PHOEMUR = os.getenv("FUNDAMENTUS")
72 changes: 70 additions & 2 deletions src/core.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# coding: utf-8
# vitorgamer58
from telegram.ext import CommandHandler, Filters, MessageHandler, Updater
import requests
import os
from conf.settings import BASE_API_URL, TELEGRAM_TOKEN, BISCOINT
from conf.settings import BASE_API_URL, TELEGRAM_TOKEN, BISCOINT, PHOEMUR

def start(bot, update):
bot.send_message(
chat_id=update.message.chat_id,
text="Olá, eu sou um robô, meus comandos são:"
"\n"
"/price + Código da ação (Responde com o valor da ação)"
"\n"
"/bitcoin (responde com a cotação do bitcoin na biscoint)"
"\n"
"/fundamentus + Código da ação (Responde com o valor da ação)"
)

def funpricestock(bot, update, args):
Expand Down Expand Up @@ -44,6 +48,67 @@ def funbitcoin(bot, update):
text=f"O preço do Bitcoin é R$ {pricebtc}"
)

def fundamentus(bot, update, args):
busca = PHOEMUR
ticker = args[0]
busca1 = requests.get(busca)
busca1 = busca1.json()
cotacao = busca1[ticker]['Cotacao']
DY = round(((busca1[ticker]['DY'])*100), 2) #função ROUND faz com que o numero só tenha 2 casas decimais
div_brut_pat = round(((busca1[ticker]['Div.Brut/Pat.'])*100), 2)
ev_ebit = busca1[ticker]['EV/EBIT']
ev_ebitda = busca1[ticker]['EV/EBITDA']
liq_corrente = busca1[ticker]['Liq.Corr.']
mrg_ebit = round(((busca1[ticker]['Mrg.Ebit'])*100), 2)
mrg_liq = round(((busca1[ticker]['Mrg.Liq.'])*100), 2)
p_acl = busca1[ticker]['P/ACL']
p_ativos = busca1[ticker]['P/Ativo']
p_cap_giro = busca1[ticker]['P/Cap.Giro']
p_ebit = busca1[ticker]['P/EBIT']
p_l = busca1[ticker]['P/L']
p_vp = busca1[ticker]['P/VP']
psr = busca1[ticker]['PSR']
roe = round(((busca1[ticker]['ROE'])*100), 2)
roic = round(((busca1[ticker]['ROIC'])*100), 2)
bot.send_message(
chat_id=update.message.chat_id,
text=f"FUNDAMENTUS {ticker}"
"\n"
f"Cotação no Fundamentus: {cotacao}"
"\n"
f"Dividend Yield: {DY}%"
"\n"
f"Dívida bruta / Patrimônio Líquido: {div_brut_pat}%"
"\n"
f"Margem EBIT: {mrg_ebit}%"
"\n"
f"Margem líquida: {mrg_liq}%"
"\n"
f"Valor da firma / EBIT: {ev_ebit}"
"\n"
f"Valor da firma / EBITDA: {ev_ebitda}"
"\n"
f"Liquidez corrente: {liq_corrente}"
"\n"
f"Preço / Ativo circulante líquido: {p_acl}"
"\n"
f"Preço / Ativos: {p_ativos}"
"\n"
f"Preço / Capital de giro: {p_cap_giro}"
"\n"
f"Preço / EBIT: {p_ebit}"
"\n"
f"Preço / Lucro: {p_l}"
"\n"
f"Preço / Valor Patrimonial: {p_vp}"
"\n"
f"Price Sales Ratio: {psr}"
"\n"
f"ROE: {roe}%"
"\n"
f"ROIC: {roic}%"
)

def unknown(bot, update):
bot.send_message(
chat_id=update.message.chat_id,
Expand All @@ -62,6 +127,9 @@ def main():
dispatcher.add_handler(
CommandHandler('bitcoin', funbitcoin, pass_args=False)
)
dispatcher.add_handler(
CommandHandler('fundamentus', fundamentus, pass_args=True)
)
dispatcher.add_handler(
MessageHandler(Filters.command, unknown)
)
Expand All @@ -71,4 +139,4 @@ def main():

if __name__ == '__main__':
print("press CTRL + C to cancel.")
main()
main()

0 comments on commit acec003

Please sign in to comment.