Refactor FMP menu

This commit is contained in:
didier
2021-03-13 14:58:49 +00:00
parent 67b342d0a2
commit 39bdc06d53
2 changed files with 134 additions and 57 deletions

View File

@@ -43,19 +43,8 @@ def print_fundamental_analysis(s_ticker, s_start, s_interval):
print(" cal calendar earnings and estimates of the company")
print("")
print("Other Sources:")
print(" av Alpha Vantage API")
print("")
print("Financial Modeling Prep API")
print(" profile profile of the company")
print(" quote quote of the company")
print(" enterprise enterprise value of the company over time")
print(" dcf discounted cash flow of the company over time")
print(" fmp_income income statements of the company")
print(" fmp_balance balance sheet of the company")
print(" fmp_cash cash flow statement of the company")
print(" metrics key metrics of the company")
print(" ratios financial ratios of the company")
print(" growth financial statement growth of the company")
print("> av Alpha Vantage MENU")
print("> fmp Financial Modeling Prep MENU")
print("")
return
@@ -100,25 +89,16 @@ def fa_menu(s_ticker, s_start, s_interval):
"q",
"quit",
"screener",
"income",
"balance",
"cash",
"mgmt",
"info",
"shrs",
"sust",
"cal",
"av",
"income",
"balance",
"cash",
"profile",
"quote",
"enterprise",
"dcf",
"fmp_income",
"fmp_balance",
"fmp_cash",
"metrics",
"ratios",
"growth",
"fmp",
]
fa_parser.add_argument("cmd", choices=choices)
completer = NestedCompleter.from_nested_dict({c: None for c in choices})
@@ -200,38 +180,13 @@ def fa_menu(s_ticker, s_start, s_interval):
should_print_help = True
# FINANCIAL MODELING PREP API
# Details:
elif ns_known_args.cmd == "profile":
fmp_api.profile(l_args, s_ticker)
elif ns_known_args.cmd == "fmp":
b_quit = fmp_api.menu(s_ticker, s_start, s_interval)
elif ns_known_args.cmd == "quote":
fmp_api.quote(l_args, s_ticker)
elif ns_known_args.cmd == "enterprise":
fmp_api.enterprise(l_args, s_ticker)
elif ns_known_args.cmd == "dcf":
fmp_api.discounted_cash_flow(l_args, s_ticker)
# Financial statement:
elif ns_known_args.cmd == "fmp_income":
fmp_api.income_statement(l_args, s_ticker)
elif ns_known_args.cmd == "fmp_balance":
fmp_api.balance_sheet(l_args, s_ticker)
elif ns_known_args.cmd == "fmp_cash":
fmp_api.cash_flow(l_args, s_ticker)
# Ratios:
elif ns_known_args.cmd == "metrics":
fmp_api.key_metrics(l_args, s_ticker)
elif ns_known_args.cmd == "ratios":
fmp_api.financial_ratios(l_args, s_ticker)
elif ns_known_args.cmd == "growth":
fmp_api.financial_statement_growth(l_args, s_ticker)
if b_quit:
return True
else:
should_print_help = True
else:
print("Command not recognized!")

View File

@@ -8,7 +8,129 @@ from gamestonk_terminal.helper_funcs import (
long_number_format,
check_positive,
parse_known_args_and_warn,
get_flair,
)
from gamestonk_terminal.menu import session
from prompt_toolkit.completion import NestedCompleter
def print_menu(s_ticker, s_start, s_interval):
""" Print help """
s_intraday = (f"Intraday {s_interval}", "Daily")[s_interval == "1440min"]
if s_start:
print(f"\n{s_intraday} Stock: {s_ticker} (from {s_start.strftime('%Y-%m-%d')})")
else:
print(f"\n{s_intraday} Stock: {s_ticker}")
print("\nFinancial Modeling Prep API")
print(" help show this financial modeling prep menu again")
print(" q quit this menu, and shows back to main menu")
print(" quit quit to abandon program")
print("")
print(" profile profile of the company")
print(" quote quote of the company")
print(" enterprise enterprise value of the company over time")
print(" dcf discounted cash flow of the company over time")
print(" income income statements of the company")
print(" balance balance sheet of the company")
print(" cash cash flow statement of the company")
print(" metrics key metrics of the company")
print(" ratios financial ratios of the company")
print(" growth financial statement growth of the company")
print("")
def menu(s_ticker, s_start, s_interval):
# Add list of arguments that the fundamental analysis parser accepts
fmp_parser = argparse.ArgumentParser(prog="fmp", add_help=False)
choices = [
"help",
"q",
"quit",
"profile",
"quote",
"enterprise",
"dcf",
"fmp_income",
"fmp_balance",
"fmp_cash",
"metrics",
"ratios",
"growth",
]
fmp_parser.add_argument("cmd", choices=choices)
completer = NestedCompleter.from_nested_dict({c: None for c in choices})
print_menu(s_ticker, s_start, s_interval)
# Loop forever and ever
while True:
# Get input command from user
if session:
as_input = session.prompt(
f"{get_flair()} (fa)>(av)> ",
completer=completer,
)
else:
as_input = input(f"{get_flair()} (fa)>(av)> ")
# Parse alpha vantage command of the list of possible commands
try:
(ns_known_args, l_args) = fmp_parser.parse_known_args(as_input.split())
except SystemExit:
print("The command selected doesn't exist\n")
continue
if ns_known_args.cmd == "help":
print_menu(s_ticker, s_start, s_interval)
elif ns_known_args.cmd == "q":
# Just leave the menu
return False
elif ns_known_args.cmd == "quit":
# Abandon the program
return True
# Details:
elif ns_known_args.cmd == "profile":
profile(l_args, s_ticker)
elif ns_known_args.cmd == "quote":
quote(l_args, s_ticker)
elif ns_known_args.cmd == "enterprise":
enterprise(l_args, s_ticker)
elif ns_known_args.cmd == "dcf":
discounted_cash_flow(l_args, s_ticker)
# Financial statement:
elif ns_known_args.cmd == "income":
income_statement(l_args, s_ticker)
elif ns_known_args.cmd == "balance":
balance_sheet(l_args, s_ticker)
elif ns_known_args.cmd == "cash":
cash_flow(l_args, s_ticker)
# Ratios:
elif ns_known_args.cmd == "metrics":
key_metrics(l_args, s_ticker)
elif ns_known_args.cmd == "ratios":
financial_ratios(l_args, s_ticker)
elif ns_known_args.cmd == "growth":
financial_statement_growth(l_args, s_ticker)
else:
print("Command not recognized!")
def profile(l_args, s_ticker):