From d712fce7cb80e4c67852c911ec616a476b225e7c Mon Sep 17 00:00:00 2001 From: Chavithra Date: Mon, 28 Nov 2022 19:20:57 +0100 Subject: ETF : update choices (#3610) * Moving Docker folder into Build * Workflows : update Docker * Docker : update compose image version * Docker : fix volumes path * etf/disc : update choices * etf/scr : update choices * etf/scr : update choices * ETF : update choices Co-authored-by: James Maslek --- openbb_terminal/etf/discovery/disc_controller.py | 19 +-- openbb_terminal/etf/etf_controller.py | 104 +++--------- .../etf/screener/screener_controller.py | 33 ++-- .../etf/technical_analysis/ta_controller.py | 183 ++++++++------------- .../etf/technical_analysis/test_ta_controller.py | 4 +- 5 files changed, 114 insertions(+), 229 deletions(-) diff --git a/openbb_terminal/etf/discovery/disc_controller.py b/openbb_terminal/etf/discovery/disc_controller.py index e4af43d3165..0c8ee2a9205 100644 --- a/openbb_terminal/etf/discovery/disc_controller.py +++ b/openbb_terminal/etf/discovery/disc_controller.py @@ -29,29 +29,14 @@ class DiscoveryController(BaseController): "active", ] PATH = "/etf/disc/" + CHOICES_GENERATION = True def __init__(self, queue: List[str] = None): """Constructor""" super().__init__(queue) if session and obbff.USE_PROMPT_TOOLKIT: - choices: dict = {c: {} for c in self.controller_choices} - - choices["gainers"] = { - "--limit": None, - "-l": "--limit", - } - choices["decliners"] = { - "--limit": None, - "-l": "--limit", - } - choices["active"] = { - "--limit": None, - "-l": "--limit", - } - - choices["support"] = self.SUPPORT_CHOICES - choices["about"] = self.ABOUT_CHOICES + choices: dict = self.choices_default self.completer = NestedCompleter.from_nested_dict(choices) diff --git a/openbb_terminal/etf/etf_controller.py b/openbb_terminal/etf/etf_controller.py index 626d92ce1d3..a131e4ca428 100644 --- a/openbb_terminal/etf/etf_controller.py +++ b/openbb_terminal/etf/etf_controller.py @@ -28,7 +28,6 @@ from openbb_terminal.etf.technical_analysis import ta_controller from openbb_terminal.helper_funcs import ( EXPORT_BOTH_RAW_DATA_AND_FIGURES, EXPORT_ONLY_RAW_DATA_ALLOWED, - check_non_negative_float, check_positive, export_data, valid_date, @@ -37,7 +36,7 @@ from openbb_terminal.helper_funcs import ( ) from openbb_terminal.menu import session from openbb_terminal.parent_classes import BaseController -from openbb_terminal.rich_config import console, MenuText, get_ordered_list_sources +from openbb_terminal.rich_config import console, MenuText from openbb_terminal.stocks import stocks_helper from openbb_terminal.stocks.comparison_analysis import ca_controller @@ -82,6 +81,7 @@ class ETFController(BaseController): PATH = "/etf/" FILE_PATH = os.path.join(os.path.dirname(__file__), "README.md") + CHOICES_GENERATION = True def __init__(self, queue: List[str] = None): """Constructor""" @@ -93,58 +93,7 @@ class ETFController(BaseController): self.TRY_RELOAD = True if session and obbff.USE_PROMPT_TOOLKIT: - choices: dict = {c: {} for c in self.controller_choices} - one_to_hundred: dict = {str(c): {} for c in range(1, 100)} - choices["search"] = { - "--name": None, - "-n": "--name", - "--description": None, - "-d": "--description", - "--source": { - c: {} for c in get_ordered_list_sources(f"{self.PATH}search") - }, - "--limit": None, - "-l": "--limit", - } - choices["load"] = { - "--ticker": None, - "-t": "--ticker", - "--start": None, - "-s": "--start", - "--end": None, - "-e": "--end", - "--limit": None, - "-l": "--limit", - } - choices["weights"] = {"--min": one_to_hundred, "-m": "--min", "--raw": {}} - - choices["candle"] = { - "--sort": {c: {} for c in self.CANDLE_COLUMNS}, - "-s": "--sort", - "--plotly": {}, - "-p": "--plotly", - "--ma": None, - "--reverse": {}, - "-r": "--reverse", - "--trend": {}, - "-t": "--trend", - "--raw": {}, - "--num": one_to_hundred, - "-n": "--num", - } - choices["pir"] = { - "--etfs": None, - "-e": "--etfs", - "--filename": None, - "--folder": None, - } - choices["compare"] = { - "--etfs": None, - "-e": "--etfs", - } - - choices["support"] = self.SUPPORT_CHOICES - choices["about"] = self.ABOUT_CHOICES + choices: dict = self.choices_default self.completer = NestedCompleter.from_nested_dict(choices) @@ -372,9 +321,6 @@ class ETFController(BaseController): help="Number of holdings to get", default=10, ) - if not self.etf_name: - console.print("Please load a ticker using . \n") - return if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-l") @@ -382,12 +328,15 @@ class ETFController(BaseController): parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED ) if ns_parser: - stockanalysis_view.view_holdings( - symbol=self.etf_name, - limit=ns_parser.limit, - export=ns_parser.export, - ) - console.print() + if self.etf_name: + stockanalysis_view.view_holdings( + symbol=self.etf_name, + limit=ns_parser.limit, + export=ns_parser.export, + ) + console.print() + else: + console.print("Please load a ticker using . \n") @log_start_end(log=logger) def call_news(self, other_args: List[str]): @@ -497,13 +446,6 @@ class ETFController(BaseController): "Only works when raw data is displayed." ), ) - parser.add_argument( - "--raw", - action="store_true", - dest="raw", - default=False, - help="Shows raw data instead of chart", - ) parser.add_argument( "-n", "--num", @@ -511,6 +453,8 @@ class ETFController(BaseController): help="Number to show if raw selected", dest="num", default=20, + choices=range(1, 100), + metavar="NUM", ) parser.add_argument( "-t", @@ -532,7 +476,10 @@ class ETFController(BaseController): ) ns_parser = self.parse_known_args_and_warn( - parser, other_args, EXPORT_BOTH_RAW_DATA_AND_FIGURES + parser, + other_args, + EXPORT_BOTH_RAW_DATA_AND_FIGURES, + raw=True, ) if ns_parser: if not self.etf_name: @@ -655,22 +602,21 @@ class ETFController(BaseController): parser.add_argument( "-m", "--min", - type=check_non_negative_float, + type=check_positive, dest="min", help="Minimum positive float to display sector", default=5, - ) - parser.add_argument( - "--raw", - action="store_true", - dest="raw", - help="Only output raw data", + choices=range(1, 100), + metavar="MIN", ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-l") ns_parser = self.parse_known_args_and_warn( - parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES + parser, + other_args, + export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES, + raw=True, ) if ns_parser: yfinance_view.display_etf_weightings( diff --git a/openbb_terminal/etf/screener/screener_controller.py b/openbb_terminal/etf/screener/screener_controller.py index 42480232603..8536bdf1420 100644 --- a/openbb_terminal/etf/screener/screener_controller.py +++ b/openbb_terminal/etf/screener/screener_controller.py @@ -33,7 +33,8 @@ class ScreenerController(BaseController): "sbc", ] - preset_choices = screener_model.get_preset_choices() + PRESET_CHOICES = screener_model.get_preset_choices() + ETF_CATEGORY_LIST = financedatabase_model.get_etfs_categories() sortby_screen_choices = [ "Assets", @@ -53,6 +54,7 @@ class ScreenerController(BaseController): ] PATH = "/etf/scr/" + CHOICES_GENERATION = True def __init__(self, queue: List[str] = None): """Constructor""" @@ -62,15 +64,10 @@ class ScreenerController(BaseController): self.screen_tickers: List = list() if session and obbff.USE_PROMPT_TOOLKIT: - choices: dict = {c: {} for c in self.controller_choices} - choices["view"] = {c: None for c in self.preset_choices} - choices["set"] = {c: None for c in self.preset_choices} - choices["sbc"] = { - c: None for c in financedatabase_model.get_etfs_categories() - } - - choices["support"] = self.SUPPORT_CHOICES - choices["about"] = self.ABOUT_CHOICES + choices: dict = self.choices_default + choices["view"].update({c: None for c in self.PRESET_CHOICES}) + choices["set"].update({c: None for c in self.PRESET_CHOICES}) + choices["sbc"].update({c: None for c in self.ETF_CATEGORY_LIST}) self.completer = NestedCompleter.from_nested_dict(choices) @@ -103,7 +100,7 @@ class ScreenerController(BaseController): type=str, help="View specific custom preset", default="", - choices=self.preset_choices, + choices=self.PRESET_CHOICES, ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-p") @@ -112,7 +109,7 @@ class ScreenerController(BaseController): if ns_parser.preset: preset_filter = configparser.RawConfigParser() preset_filter.optionxform = str # type: ignore - preset_filter.read(self.preset_choices[ns_parser.preset]) + preset_filter.read(self.PRESET_CHOICES[ns_parser.preset]) headers = [ "Price", @@ -144,9 +141,9 @@ class ScreenerController(BaseController): else: console.print("\nPresets:") - for preset in self.preset_choices: + for preset in self.PRESET_CHOICES: with open( - self.preset_choices[preset], + self.PRESET_CHOICES[preset], encoding="utf8", ) as f: description = "" @@ -174,7 +171,7 @@ class ScreenerController(BaseController): type=str, default="template", help="Filter presets", - choices=self.preset_choices, + choices=self.PRESET_CHOICES, ) if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-p") @@ -251,6 +248,8 @@ class ScreenerController(BaseController): nargs="+", help="Category to look for", required="-h" not in other_args, + choices=self.ETF_CATEGORY_LIST, + metavar="CATEGORY", ) parser.add_argument( "-l", @@ -269,7 +268,7 @@ class ScreenerController(BaseController): ) if ns_parser: category = " ".join(ns_parser.category) - if category in financedatabase_model.get_etfs_categories(): + if category in self.ETF_CATEGORY_LIST: financedatabase_view.display_etf_by_category( category=category, limit=ns_parser.limit, @@ -278,5 +277,5 @@ class ScreenerController(BaseController): else: console.print( "The category selected does not exist, choose one from:" - f" {', '.join(financedatabase_model.get_etfs_categories())}\n" + f" {', '.join(self.ETF_CATEGORY_LIST)}\n" ) diff --git a/openbb_terminal/etf/technical_analysis/ta_controller.py b/openbb_terminal/etf/technical_analysis/ta_controller.py index b05664f75b1..d97b0d8fbc1 100644 --- a/openbb_terminal/etf/technical_analysis/ta_controller.py +++ b/openbb_terminal/etf/technical_analysis/ta_controller.py @@ -27,6 +27,7 @@ from openbb_terminal.common.technical_analysis import ( from openbb_terminal.decorators import log_start_end from openbb_terminal.helper_funcs import ( EXPORT_BOTH_RAW_DATA_AND_FIGURES, + check_non_negative, check_positive, check_positive_list, valid_date, @@ -72,6 +73,7 @@ class TechnicalAnalysisController(BaseController): ] PATH = "/etf/ta/" + CHOICES_GENERATION = True def __init__( self, @@ -90,112 +92,6 @@ class TechnicalAnalysisController(BaseController): if session and obbff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} - one_to_hundred: dict = {str(c): {} for c in range(1, 100)} - zero_to_hundred: dict = {str(c): {} for c in range(0, 100)} - ma = { - "--length": None, - "-l": "--length", - "--offset": zero_to_hundred, - "-o": "--offset", - } - choices["ema"] = ma - choices["sma"] = ma - choices["wma"] = ma - choices["hma"] = ma - choices["zlma"] = ma - choices["vwap"] = { - "--offset": zero_to_hundred, - "-o": "--offset", - "--start": None, - "--end": None, - } - choices["cci"] = { - "--length": one_to_hundred, - "-l": "--length", - "--scalar": None, - "-s": "--scalar", - } - choices["macd"] = { - "--fast": one_to_hundred, - "--slow": "--fast", - "--signal": "--fast", - } - choices["cci"] = { - "--length": one_to_hundred, - "-l": "--length", - "--scalar": None, - "-s": "--scalar", - "--drift": "--length", - "-d": "--drift", - } - choices["stoch"] = { - "--fastkperiod": one_to_hundred, - "-k": "--fastkperiod", - "--slowdperiod": "--fastkperiod", - "-d": "--slowdperiod", - "--slowkperiod": "--fastkperiod", - } - choices["fisher"] = { - "--length": one_to_hundred, - "-l": "--length", - } - choices["cg"] = { - "--length": one_to_hundred, - "-l": "--length", - } - choices["adx"] = { - "--length": one_to_hundred, - "-l": "--length", - "--scalar": None, - "-s": "--scalar", - "--drift": "--length", - "-d": "--drift", - } - choices["aroon"] = { - "--length": one_to_hundred, - "-l": "--length", - "--scalar": None, - "-s": "--scalar", - } - choices["bbands"] = { - "--length": one_to_hundred, - "-l": "--length", - "--std": {str(c): {} for c in np.arange(0.0, 10, 0.25)}, - "-s": "--std", - "--mamode": {c: {} for c in volatility_model.MAMODES}, - "-m": "--mamode", - } - choices["donchian"] = { - "--length_upper": one_to_hundred, - "-u": "--length_upper", - "--length_lower": "--length_upper", - "-l": "--length_lower", - } - choices["kc"] = { - "--length": one_to_hundred, - "-l": "--length", - "--scalar": None, - "-s": "--scalar", - "--mamode": {c: {} for c in volatility_model.MAMODES}, - "-m": "--mamode", - "--offset": zero_to_hundred, - "-o": "--offset", - } - choices["ad"]["--open"] = {} - choices["adosc"] = { - "--open": {}, - "--fast": one_to_hundred, - "--slow": "--fast", - } - choices["fib"] = { - "--period": {str(c): {} for c in range(1, 960)}, - "--start": None, - "--end": None, - } - - choices["support"] = self.SUPPORT_CHOICES - choices["about"] = self.ABOUT_CHOICES - self.completer = NestedCompleter.from_nested_dict(choices) def print_help(self): @@ -273,9 +169,11 @@ class TechnicalAnalysisController(BaseController): "--offset", action="store", dest="n_offset", - type=int, + type=check_non_negative, default=0, help="offset", + choices=range(0, 100), + metavar="N_OFFSET", ) if other_args and "-" not in other_args[0][0]: @@ -325,9 +223,11 @@ class TechnicalAnalysisController(BaseController): "--offset", action="store", dest="n_offset", - type=int, + type=check_non_negative, default=0, help="offset", + choices=range(0, 100), + metavar="N_OFFSET", ) if other_args and "-" not in other_args[0][0]: @@ -374,9 +274,11 @@ class TechnicalAnalysisController(BaseController): "--offset", action="store", dest="n_offset", - type=int, + type=check_non_negative, default=0, help="offset", + choices=range(0, 100), + metavar="N_OFFSET", ) if other_args and "-" not in other_args[0][0]: @@ -423,9 +325,11 @@ class TechnicalAnalysisController(BaseController): "--offset", action="store", dest="n_offset", - type=int, + type=check_non_negative, default=0, help="offset", + choices=range(0, 100), + metavar="N_OFFSET", ) if other_args and "-" not in other_args[0][0]: @@ -475,9 +379,11 @@ class TechnicalAnalysisController(BaseController): "--offset", action="store", dest="n_offset", - type=int, + type=check_non_negative, default=0, help="offset", + choices=range(0, 100), + metavar="N_OFFSET", ) if other_args and "-" not in other_args[0][0]: @@ -513,9 +419,11 @@ class TechnicalAnalysisController(BaseController): "--offset", action="store", dest="n_offset", - type=int, + type=check_non_negative, default=0, help="offset", + choices=range(0, 100), + metavar="N_OFFSET", ) parser.add_argument( "--start", @@ -582,6 +490,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=14, help="length", + choices=range(1, 100), + metavar="N_LENGTH", ) parser.add_argument( "-s", @@ -631,6 +541,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=12, help="The short period.", + choices=range(1, 100), + metavar="N_FAST", ) parser.add_argument( "--slow", @@ -639,6 +551,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=26, help="The long period.", + choices=range(1, 100), + metavar="N_SLOW", ) parser.add_argument( "--signal", @@ -647,6 +561,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=9, help="The signal period.", + choices=range(1, 100), + metavar="N_SIGNAL", ) ns_parser = self.parse_known_args_and_warn( @@ -686,6 +602,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=14, help="length", + choices=range(1, 100), + metavar="N_LENGTH", ) parser.add_argument( "-s", @@ -704,6 +622,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=1, help="drift", + choices=range(1, 100), + metavar="N_DRIFT", ) if other_args and "-" not in other_args[0][0]: @@ -746,6 +666,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=14, help="The time period of the fastk moving average", + choices=range(1, 100), + metavar="N_FASTKPERIOD", ) parser.add_argument( "-d", @@ -755,6 +677,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=3, help="The time period of the slowd moving average", + choices=range(1, 100), + metavar="N_SLOWDPERIOD", ) parser.add_argument( "--slowkperiod", @@ -763,6 +687,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=3, help="The time period of the slowk moving average", + choices=range(1, 100), + metavar="N_SLOWKPERIOD", ) ns_parser = self.parse_known_args_and_warn( @@ -801,6 +727,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=14, help="length", + choices=range(1, 100), + metavar="N_LENGTH", ) if other_args and "-" not in other_args[0][0]: @@ -840,6 +768,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=14, help="length", + choices=range(1, 100), + metavar="N_LENGTH", ) if other_args and "-" not in other_args[0][0]: @@ -877,6 +807,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=14, help="length", + choices=range(1, 100), + metavar="N_LENGTH", ) parser.add_argument( "-s", @@ -895,6 +827,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=1, help="drift", + choices=range(1, 100), + metavar="N_DRIFT", ) if other_args and "-" not in other_args[0][0]: @@ -942,6 +876,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=25, help="length", + choices=range(1, 100), + metavar="N_LENGTH", ) parser.add_argument( "-s", @@ -997,6 +933,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=15, help="length", + choices=range(1, 100), + metavar="N_LENGTH", ) parser.add_argument( "-s", @@ -1006,6 +944,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=2, help="std", + choices=np.arange(0.0, 10, 0.25).tolist(), + metavar="N_STD", ) parser.add_argument( "-m", @@ -1014,6 +954,7 @@ class TechnicalAnalysisController(BaseController): dest="s_mamode", default="sma", help="mamode", + choices=volatility_model.MAMODES, ) if other_args and "-" not in other_args[0][0]: @@ -1056,6 +997,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=20, help="length", + choices=range(1, 100), + metavar="N_LENGTH_UPPER", ) parser.add_argument( "-l", @@ -1065,6 +1008,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=20, help="length", + choices=range(1, 100), + metavar="N_LENGTH_LOWER", ) ns_parser = self.parse_known_args_and_warn( @@ -1102,6 +1047,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=20, help="Window length", + choices=range(1, 100), + metavar="N_LENGTH", ) parser.add_argument( "-s", @@ -1126,9 +1073,11 @@ class TechnicalAnalysisController(BaseController): "--offset", action="store", dest="n_offset", - type=int, + type=check_non_negative, default=0, help="offset", + choices=range(0, 100), + metavar="N_OFFSET", ) if other_args and "-" not in other_args[0][0]: @@ -1218,6 +1167,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=3, help="fast length", + choices=range(1, 100), + metavar="N_LENGTH_FAST", ) parser.add_argument( "--slow", @@ -1226,6 +1177,8 @@ class TechnicalAnalysisController(BaseController): type=check_positive, default=10, help="slow length", + choices=range(1, 100), + metavar="N_LENGTH_SLOW", ) ns_parser = self.parse_known_args_and_warn( @@ -1282,9 +1235,11 @@ class TechnicalAnalysisController(BaseController): "-p", "--period", dest="period", - type=int, + type=check_positive, help="Days to look back for retracement", default=120, + choices=range(1, 960), + metavar="PERIOD", ) parser.add_argument( "--start", diff --git a/tests/openbb_terminal/etf/technical_analysis/test_ta_controller.py b/tests/openbb_terminal/etf/technical_analysis/test_ta_controller.py index 9583e1a3eb4..39f7d0b0e29 100644 --- a/tests/openbb_terminal/etf/technical_analysis/test_ta_controller.py +++ b/tests/openbb_terminal/etf/technical_analysis/test_ta_controller.py @@ -507,7 +507,7 @@ def test_call_func_expect_queue(expected_queue, func, queue): [ "1", "--std=2", - "--mamode=MOCK_MAMODE", + "--mamode=ema", "--export=csv", ], "volatility_view.display_bbands", @@ -517,7 +517,7 @@ def test_call_func_expect_queue(expected_queue, func, queue): data=MOCK_STOCK_DF, window=1, n_std=2, - mamode="MOCK_MAMODE", + mamode="ema", export="csv", ), ), -- cgit v1.2.3