From 31292d7d0305a621bcce117fbb39026da5b2336e Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 2 Feb 2023 16:17:10 +0000 Subject: [PATCH] improved swe functions --- openbb_terminal/mutual_funds/avanza_model.py | 9 ++++---- openbb_terminal/mutual_funds/avanza_view.py | 14 +++++++----- .../mutual_funds/mutual_fund_controller.py | 22 ++++++++++++------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/openbb_terminal/mutual_funds/avanza_model.py b/openbb_terminal/mutual_funds/avanza_model.py index bad8328c8779..5a90874c6bf7 100644 --- a/openbb_terminal/mutual_funds/avanza_model.py +++ b/openbb_terminal/mutual_funds/avanza_model.py @@ -15,20 +15,19 @@ @log_start_end(log=logger) -def get_data(name: str): +def get_data(isin: str): """Gets the data from Avanza Parameters ---------- - name: str - Full name of the fund + isin: str + ISIN of the fund """ ava_fund = pd.read_csv( os.path.join("openbb_terminal", "mutual_funds", "avanza_fund_ID.csv"), index_col=0, ) - ava_fund.index = ava_fund.index.str.upper() - fund_id = ava_fund.loc[name, "ID"] + fund_id = ava_fund.loc[ava_fund["ISIN"] == isin]["ID"].tolist()[0] url = f"https://www.avanza.se/_api/fund-guide/guide/{fund_id}" response = request(url) fund_data = response.json() diff --git a/openbb_terminal/mutual_funds/avanza_view.py b/openbb_terminal/mutual_funds/avanza_view.py index 164f0aa85ffa..2f87be7878f2 100644 --- a/openbb_terminal/mutual_funds/avanza_view.py +++ b/openbb_terminal/mutual_funds/avanza_view.py @@ -28,18 +28,20 @@ @log_start_end(log=logger) -def display_allocation(name: str, focus: str): +def display_allocation(name: str, isin: str, focus: str): """Displays the allocation of the selected swedish fund Parameters ---------- name: str Full name of the fund + isin: str + ISIN of the fund focus: str The focus of the displayed allocation/exposure of the fund """ # Taken from: https://github.com/northern-64bit/Portfolio-Report-Generator/tree/main - fund_data = avanza_model.get_data(name.upper()) + fund_data = avanza_model.get_data(isin) if focus in ["holding", "all"]: table_row = [] console.print("") @@ -81,15 +83,15 @@ def display_allocation(name: str, focus: str): @log_start_end(log=logger) -def display_info(name: str): +def display_info(isin: str): """Displays info of swedish funds Parameters ---------- - name: str - Full name of the fund + isin: str + ISIN of the fund """ - fund_data = avanza_model.get_data(name.upper()) + fund_data = avanza_model.get_data(isin) text = f"\nSwedish Description:\n\n{fund_data['description']}\n\nThe fund is managed by:\n" for manager in fund_data["fundManagers"]: text = text + f"\t- {manager['name']} since {manager['startDate']}\n" diff --git a/openbb_terminal/mutual_funds/mutual_fund_controller.py b/openbb_terminal/mutual_funds/mutual_fund_controller.py index aa6e47d127ee..4c4947418c87 100644 --- a/openbb_terminal/mutual_funds/mutual_fund_controller.py +++ b/openbb_terminal/mutual_funds/mutual_fund_controller.py @@ -107,8 +107,8 @@ def print_help(self): mt.add_cmd("holdings", self.fund_symbol) mt.add_cmd("carbon", self.fund_symbol) mt.add_cmd("exclusion", self.fund_symbol) - mt.add_cmd("alswe", self.fund_symbol) - mt.add_cmd("infoswe", self.fund_symbol) + mt.add_cmd("alswe", self.fund_symbol and self.country == "sweden") + mt.add_cmd("infoswe", self.fund_symbol and self.country == "sweden") if self.country == "sweden": mt.add_cmd("alswe", self.fund_symbol) @@ -151,10 +151,14 @@ def call_alswe(self, other_args: List[str]): "Avanza implementation currently only supports funds from sweden." ) return self.queue - if self.fund_name.upper() not in ava_fund.index.str.upper().to_numpy(): - console.print("No fund data. Please use another fund") + + if self.fund_isin not in ava_fund["ISIN"].tolist(): + console.print("No fund data. Please use another fund.") return self.queue - avanza_view.display_allocation(self.fund_name, ns_parser.focus) + + avanza_view.display_allocation( + name=self.fund_name, isin=self.fund_isin, focus=ns_parser.focus + ) return self.queue @@ -179,10 +183,12 @@ def call_infoswe(self, other_args: List[str]): "Avanza implementation currently only supports funds from sweden." ) return self.queue - if self.fund_name.upper() not in ava_fund.index.str.upper().to_numpy(): - console.print("No fund data. Please use another fund") + + if self.fund_isin not in ava_fund["ISIN"].tolist(): + console.print("No fund data. Please use another fund.") return self.queue - avanza_view.display_info(self.fund_name) + + avanza_view.display_info(self.fund_isin) return self.queue