diff --git a/openbb_terminal/stocks/stocks_controller.py b/openbb_terminal/stocks/stocks_controller.py index 0314da7c9241..831f38b8efde 100644 --- a/openbb_terminal/stocks/stocks_controller.py +++ b/openbb_terminal/stocks/stocks_controller.py @@ -521,11 +521,13 @@ def call_options(self, _): @log_start_end(log=logger) def call_th(self, _): """Process th command""" - from openbb_terminal.stocks.tradinghours.tradinghours_controller import ( - TradingHoursController, - ) + from openbb_terminal.stocks.tradinghours import tradinghours_controller - self.queue = self.load_class(TradingHoursController, self.queue) + self.queue = self.load_class( + tradinghours_controller.TradingHoursController, + self.ticker, + self.queue, + ) @log_start_end(log=logger) def call_res(self, _): diff --git a/openbb_terminal/stocks/tradinghours/bursa_model.py b/openbb_terminal/stocks/tradinghours/bursa_model.py index 67261b37a301..0f84f7f968b6 100644 --- a/openbb_terminal/stocks/tradinghours/bursa_model.py +++ b/openbb_terminal/stocks/tradinghours/bursa_model.py @@ -233,6 +233,8 @@ def check_if_open(bursa, exchange): and localDatetime.minute >= lunchbreak_start.minute ): result = False + else: + result = True else: result = True elif ( @@ -256,6 +258,8 @@ def check_if_open(bursa, exchange): and localDatetime.minute >= lunchbreak_start.minute ): result = False + else: + result = True else: result = True else: diff --git a/openbb_terminal/stocks/tradinghours/bursa_view.py b/openbb_terminal/stocks/tradinghours/bursa_view.py index 4c9d4dfb5b26..3bee3add8b03 100644 --- a/openbb_terminal/stocks/tradinghours/bursa_view.py +++ b/openbb_terminal/stocks/tradinghours/bursa_view.py @@ -24,9 +24,9 @@ def display_exchange(symbol: str): if len(exchange) == 0 or exchange.empty: console.print( - "\n[red]" + "[red]" + "No exchange data loaded.\n" - + "Make sure you picked proper exchange symbol." + + "Make sure you picked a valid exchange symbol." + "[/red]\n" ) return @@ -50,7 +50,7 @@ def display_open(): exchanges = bursa_model.get_open() if exchanges.empty: - console.print("\n[red]" + "No exchange data loaded.\n" + "[/red]\n") + console.print("No exchange open.\n") return print_rich_table( @@ -70,7 +70,7 @@ def display_closed(): exchanges = bursa_model.get_closed() if exchanges.empty: - console.print("\n[red]" + "No exchange data loaded.\n" + "[/red]\n") + console.print("[red]" + "No exchange data loaded.\n" + "[/red]\n") return print_rich_table( @@ -90,7 +90,7 @@ def display_all(): exchanges = bursa_model.get_all() if exchanges.empty: - console.print("\n[red]" + "No exchange data loaded.\n" + "[/red]\n") + console.print("[red]" + "No exchange data loaded.\n" + "[/red]\n") return print_rich_table( diff --git a/openbb_terminal/stocks/tradinghours/tradinghours_controller.py b/openbb_terminal/stocks/tradinghours/tradinghours_controller.py index 7e63880c9ef4..094cc28d558e 100644 --- a/openbb_terminal/stocks/tradinghours/tradinghours_controller.py +++ b/openbb_terminal/stocks/tradinghours/tradinghours_controller.py @@ -37,7 +37,7 @@ class TradingHoursController(BaseController): PATH = "/stocks/th/" FILE_PATH = os.path.join(os.path.dirname(__file__), "README.md") - def __init__(self, queue: List[str] = None): + def __init__(self, ticker: str = "", queue: List[str] = None): """Construct Data.""" super().__init__(queue) @@ -49,10 +49,24 @@ def __init__(self, queue: List[str] = None): all_short_names = list(short_names) + list(short_names_index) self.all_exchange_short_names = sorted(list(all_short_names)) - self.exchange = None self.symbol = None self.symbol_name = None self.symbol_market_open = False + self.exchange = None + + if ticker: + if ticker in self.equities: + self.symbol = ticker + self.symbol_name = self.equities[ticker]["short_name"] + self.exchange = self.equities[ticker]["exchange"] + open_ex = get_open() + if self.exchange in open_ex.index: + self.symbol_market_open = True + else: + self.symbol_market_open = False + else: + console.print(f"The ticker {ticker} was not find in the database.") + self.source = "yf" self.data = pd.DataFrame() self.timezone = get_user_timezone_or_invalid() @@ -76,16 +90,17 @@ def print_help(self): exchange_opened = "" mt = MenuText("stocks/th/") + mt.add_cmd("open") + mt.add_cmd("closed") + mt.add_cmd("all") + mt.add_cmd("exchange") + mt.add_raw("\n") mt.add_cmd("symbol") mt.add_raw("\n") mt.add_param("_symbol_name", self.symbol_name or "") mt.add_param("_symbol", self.symbol_name or "") mt.add_param("_exchange", exchange_opened) - mt.add_raw("\n") - mt.add_cmd("open") - mt.add_cmd("closed") - mt.add_cmd("all") - mt.add_cmd("exchange") + console.print(text=mt.menu_text, menu="Stocks - Trading Hours") @log_start_end(log=logger) @@ -116,19 +131,22 @@ def call_symbol(self, other_args: List[str]): ns_parser = self.parse_known_args_and_warn(parser, other_args) if ns_parser: self.symbol = ns_parser.symbol - self.symbol_name = self.equities[self.symbol]["short_name"] # - self.exchange = self.equities[self.symbol]["exchange"] - open_ex = get_open() - if self.exchange in open_ex.index: - self.symbol_market_open = True + if ns_parser.symbol in self.equities: + self.symbol_name = self.equities[self.symbol]["short_name"] + self.exchange = self.equities[self.symbol]["exchange"] + open_ex = get_open() + if self.exchange in open_ex.index: + self.symbol_market_open = True + else: + self.symbol_market_open = False + # add currency + console.print( + f"\nSelected symbol\nSymbol: {self.symbol}\n" + f"Name: {self.symbol_name}\n" + f"Market open: {self.symbol_market_open}\n" + ) else: - self.symbol_market_open = False - # add currency - console.print( - f"\nSelected symbol\nSymbol: {self.symbol}\n" - f"Name: {self.symbol_name}\n" - f"Market open: {self.symbol_market_open}\n" - ) + console.print("[red]Symbol not found on database.[/red]\n") @log_start_end(log=logger) def call_exchange(self, other_args: List[str]): @@ -171,14 +189,13 @@ def call_open(self, other_args: List[str]): prog="exchange", description="Show currently open exchanges", ) - if other_args and "-h" not in other_args: other_args.insert(0, "-n") ns_parser = self.parse_known_args_and_warn(parser, other_args) if ns_parser: bursa_view.display_open() - else: + logger.error("No open exchanges right now.") console.print("[red]No open exchanges right now.[/red]\n")