Skip to content

Commit

Permalink
improved swe functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoaquim committed Feb 2, 2023
1 parent 879bb6b commit 31292d7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
9 changes: 4 additions & 5 deletions openbb_terminal/mutual_funds/avanza_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 8 additions & 6 deletions openbb_terminal/mutual_funds/avanza_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down Expand Up @@ -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"
Expand Down
22 changes: 14 additions & 8 deletions openbb_terminal/mutual_funds/mutual_fund_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 31292d7

Please sign in to comment.