TelegramAktienBot/telegram_bot/shares/share_fetcher.py
Florian Kellermann ec4a6f98e3 Without currency
2022-05-07 19:33:02 +02:00

69 lines
1.8 KiB
Python

"""
script for share fetching (by symbols (e.g. AAPL, TSLA etc.))
"""
__author__ = "Florian Kellermann, Linus Eickhoff"
__date__ = "15.03.2022"
__version__ = "0.0.2"
__license__ = "None"
import yfinance
import investpy
import pandas
def get_share_price(str_search_for):
"""_summary_
Args:
str_search_for (_type_): _description_
Returns:
_type_: _description_
"""
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
countries=['germany'], n_results=1)
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
def get_share_price_no_currency(str_search_for):
"""_summary_
Args:
str_search_for (_type_): _description_
Returns:
_type_: _description_
"""
search_result = investpy.search_quotes(text=str_search_for, products=['stocks'],
countries=['germany'], n_results=1)
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'],
countries=['germany'], 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
if __name__ == "__main__":
print(get_share_price("AAPL"))
print(get_share_information("AAPL"))