Skip to content

Commit

Permalink
Merge pull request #2 from vitorgamer58/graham
Browse files Browse the repository at this point in the history
Implementada à Função /graham
  • Loading branch information
vitorgamer58 authored Apr 18, 2021
2 parents acec003 + b68a1a2 commit 1f66b0e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/conf/__pycache__/
78 changes: 70 additions & 8 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
import requests
import os
from conf.settings import BASE_API_URL, TELEGRAM_TOKEN, BISCOINT, PHOEMUR
import logging
import math

logger = logging.getLogger()
logger.setLevel(logging.INFO)


logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

def corrigir_virgulas(price):
price = price.replace('.', ',')
#substitui ponto por vírcula
return price


def start(bot, update):
bot.send_message(
Expand All @@ -27,7 +42,9 @@ def funpricestock(bot, update, args):
symbol = json['symbol']
bot.send_message(
chat_id=update.message.chat_id,
text=f"O preço da ação {symbol} é: {priceaction}, sendo a variação no dia de {changeaction}%")
text=f"O preço da ação {symbol} é: R$ {priceaction}, sendo a variação no dia de {changeaction}%")
string_log = f"{symbol}, {priceaction}"
logging.info(string_log)
else:
if(json.status_code==404):
bot.send_message(
Expand All @@ -41,12 +58,17 @@ def funpricestock(bot, update, args):
def funbitcoin(bot, update):
buscabtc = BISCOINT
jsonbtc = requests.get(buscabtc)
jsonbtc = jsonbtc.json()
pricebtc = jsonbtc['data']['last']
bot.send_message(
chat_id=update.message.chat_id,
text=f"O preço do Bitcoin é R$ {pricebtc}"
)
if(jsonbtc.status_code==200):
jsonbtc = jsonbtc.json()
pricebtc = jsonbtc['data']['last']
bot.send_message(
chat_id=update.message.chat_id,
text=f"O preço do Bitcoin é R$ {pricebtc}")
else:
bot.send_message(
chat_id=update.message.chat_id,
text="Sistema temporariamente indisponível")


def fundamentus(bot, update, args):
busca = PHOEMUR
Expand Down Expand Up @@ -108,7 +130,44 @@ def fundamentus(bot, update, args):
"\n"
f"ROIC: {roic}%"
)


def graham(bot, update, args):
ticker=args[0]
url= "https://mfinance.com.br/api/v1/stocks/indicators/"
urlticker = url + ticker
json = requests.get(urlticker)
if(json.status_code==200):
json = json.json()
vpa = json['bookValuePerShare']['value']
lpa = json['earningsPerShare']['value']
if (vpa>0 and vpa!=0):
if (lpa>0):
graham = round(math.sqrt(22.5 * lpa * vpa), 2)
bot.send_message(
chat_id=update.message.chat_id,
text=f"O preço justo da ação {ticker} segundo a fórmula de Graham é: R$ {graham}")
string_log = f"{ticker}, {vpa}, {lpa}"
logging.info(string_log)
else:
bot.send_message(
chat_id=update.message.chat.id,
text="LPA menor que zero, não é possível calcular!")
else:
if(vpa<0):
bot.send_message(
chat_id=update.message.chat.id,
text="VPA menor que zero, não é possível calcular!")
else:
if(vpa==0):
bot.send_message(
chat_id=update.message.chat.id,
text="API mfinance está fora do ar ou o código digitado é inválido.")
else:
bot.send_message(
chat_id=update.message.chat_id,
text="A API mfinance está indisponível no momento por um motivo desconhecido.")


def unknown(bot, update):
bot.send_message(
chat_id=update.message.chat_id,
Expand All @@ -130,6 +189,9 @@ def main():
dispatcher.add_handler(
CommandHandler('fundamentus', fundamentus, pass_args=True)
)
dispatcher.add_handler(
CommandHandler('graham', graham, pass_args=True)
)
dispatcher.add_handler(
MessageHandler(Filters.command, unknown)
)
Expand Down

0 comments on commit 1f66b0e

Please sign in to comment.