TelegramAktienBot/telegram_bot/shares/share_fetcher.py

60 lines
1.8 KiB
Python
Raw Normal View History

2022-03-15 07:55:12 +00:00
"""
script for share fetching (by symbols (e.g. AAPL, TSLA etc.))
"""
__author__ = "Florian Kellermann, Linus Eickhoff"
__date__ = "15.03.2022"
2022-05-07 17:34:54 +00:00
__version__ = "1.0.0"
__license__ = "None"
import investpy
import pandas
def get_share_price(str_search_for):
2022-05-07 17:34:54 +00:00
"""get stock price per share for company name or isin or symbol
Args:
2022-05-07 17:38:17 +00:00
str_search_for (string): search for this string/isin
2022-05-07 17:38:17 +00:00
Returns: none
"""
2022-05-07 17:51:05 +00:00
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'], n_results=1, countries=['germany'])
currency = str(search_result.retrieve_currency())
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
stock_price = recent_data.iloc[-1]["Close"]
str_return =str(stock_price) + " " + str(currency)
return str_return
2022-05-07 17:33:02 +00:00
def get_share_price_no_currency(str_search_for):
2022-05-07 17:38:17 +00:00
"""get stock price per share for company name or isin or symbol no currency
2022-05-07 17:33:02 +00:00
Args:
2022-05-07 17:38:17 +00:00
str_search_for (string): search for this string/isin
2022-05-07 17:33:02 +00:00
2022-05-07 17:38:17 +00:00
Returns: none
2022-05-07 17:33:02 +00:00
"""
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
2022-05-07 17:42:28 +00:00
countries=['germany', 'united states'], n_results=1)
2022-05-07 17:33:02 +00:00
recent_data = pandas.DataFrame(search_result.retrieve_recent_data())
stock_price = recent_data.iloc[-1]["Close"]
return stock_price
def get_share_information(str_search_for):
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
2022-05-07 17:42:28 +00:00
countries=['germany', 'united states'], n_results=1)
str_return = "Company: " + search_result.name + "\nSymbol: " + search_result.symbol + "\nCurrent Price/Share: " + get_share_price(str_search_for)
return str_return