Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trading hours bringing ticker in #2038

Merged
merged 4 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions openbb_terminal/stocks/stocks_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, _):
Expand Down
4 changes: 4 additions & 0 deletions openbb_terminal/stocks/tradinghours/bursa_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions openbb_terminal/stocks/tradinghours/bursa_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
59 changes: 38 additions & 21 deletions openbb_terminal/stocks/tradinghours/tradinghours_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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]):
Expand Down Expand Up @@ -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")

Expand Down