mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
allow to switch between stocks and options contexts (#666)
This commit is contained in:
@@ -26,6 +26,7 @@ from gamestonk_terminal.options import (
|
||||
tradier_model,
|
||||
fdscanner_view,
|
||||
)
|
||||
from gamestonk_terminal.stocks import stocks_controller
|
||||
|
||||
from gamestonk_terminal.config_terminal import TRADIER_TOKEN
|
||||
from gamestonk_terminal.menu import session
|
||||
@@ -42,7 +43,7 @@ class OptionsController:
|
||||
"quit",
|
||||
]
|
||||
|
||||
CHOICES_COMMANDS = [
|
||||
CHOICES_MENUS = [
|
||||
"disp",
|
||||
"scr",
|
||||
"calc",
|
||||
@@ -58,9 +59,10 @@ class OptionsController:
|
||||
"chains",
|
||||
"grhist",
|
||||
"unu",
|
||||
"stocks",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
CHOICES += CHOICES_MENUS
|
||||
|
||||
PRESET_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), "presets/")
|
||||
|
||||
@@ -74,10 +76,18 @@ class OptionsController:
|
||||
"premium",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
"""Construct data."""
|
||||
self.ticker = ""
|
||||
self.expiry_dates = []
|
||||
def __init__(self, ticker):
|
||||
"""Constructor"""
|
||||
self.ticker = ticker
|
||||
|
||||
if ticker:
|
||||
if TRADIER_TOKEN == "REPLACE_ME":
|
||||
print("Loaded expiry dates from Yahoo Finance")
|
||||
self.expiry_dates = yfinance_model.option_expirations(self.ticker)
|
||||
else:
|
||||
print("Loaded expiry dates from Tradier")
|
||||
self.expiry_dates = tradier_model.option_expirations(self.ticker)
|
||||
|
||||
self.selected_date = ""
|
||||
|
||||
self.op_parser = argparse.ArgumentParser(add_help=False, prog="options")
|
||||
@@ -89,8 +99,7 @@ class OptionsController:
|
||||
def print_help(self):
|
||||
"""Print help."""
|
||||
colored = self.ticker and self.selected_date
|
||||
print_str = f"""
|
||||
https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/options
|
||||
help_text = """https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/options
|
||||
|
||||
>> OPTIONS <<
|
||||
|
||||
@@ -100,6 +109,13 @@ What do you want to do?
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
|
||||
"""
|
||||
help_text += ">> stocks go into stocks context"
|
||||
if self.ticker:
|
||||
help_text += f" with {self.ticker}"
|
||||
|
||||
help_text += f"""
|
||||
|
||||
Explore:
|
||||
disp display all preset screeners filters
|
||||
scr output screener options [Syncretism.io]
|
||||
@@ -120,7 +136,7 @@ Current Expiry: {self.selected_date or None}
|
||||
hist plot option history [Tradier]
|
||||
grhist plot option greek history [Syncretism.io]
|
||||
{Style.RESET_ALL if not colored else ''}"""
|
||||
print(print_str)
|
||||
print(help_text)
|
||||
|
||||
def switch(self, an_input: str):
|
||||
"""Process and dispatch input.
|
||||
@@ -1014,10 +1030,14 @@ Current Expiry: {self.selected_date or None}
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
|
||||
def call_stocks(self, _):
|
||||
"""Process stocks command"""
|
||||
return stocks_controller.menu(self.ticker)
|
||||
|
||||
def menu():
|
||||
|
||||
def menu(ticker: str = ""):
|
||||
"""Options Menu."""
|
||||
op_controller = OptionsController()
|
||||
op_controller = OptionsController(ticker)
|
||||
op_controller.call_help(None)
|
||||
while True:
|
||||
# Get input command from user
|
||||
|
||||
@@ -11,7 +11,6 @@ from gamestonk_terminal.menu import session
|
||||
from gamestonk_terminal import feature_flags as gtff
|
||||
|
||||
from gamestonk_terminal.stocks.stocks_helper import load, candle, quote
|
||||
|
||||
from gamestonk_terminal.stocks.discovery import disc_controller
|
||||
from gamestonk_terminal.stocks.screener import screener_controller
|
||||
from gamestonk_terminal.stocks.insider import insider_controller
|
||||
@@ -27,6 +26,8 @@ from gamestonk_terminal.stocks.residuals_analysis import ra_controller
|
||||
from gamestonk_terminal.stocks.exploratory_data_analysis import eda_controller
|
||||
from gamestonk_terminal.stocks.report import report_controller
|
||||
|
||||
from gamestonk_terminal.options import options_controller
|
||||
|
||||
# pylint: disable=R1710
|
||||
|
||||
|
||||
@@ -66,13 +67,19 @@ class StocksController:
|
||||
"dd",
|
||||
"ca",
|
||||
"report",
|
||||
"options",
|
||||
]
|
||||
|
||||
CHOICES += CHOICES_COMMANDS
|
||||
CHOICES += CHOICES_MENUS
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, ticker):
|
||||
"""Constructor"""
|
||||
self.stock = pd.DataFrame()
|
||||
self.ticker = ticker
|
||||
self.start = ""
|
||||
self.interval = "1440min"
|
||||
|
||||
self.stocks_parser = argparse.ArgumentParser(add_help=False, prog="stocks")
|
||||
self.stocks_parser.add_argument(
|
||||
"cmd",
|
||||
@@ -82,11 +89,6 @@ class StocksController:
|
||||
{c: None for c in self.CHOICES}
|
||||
)
|
||||
|
||||
self.stock = pd.DataFrame()
|
||||
self.ticker = ""
|
||||
self.start = ""
|
||||
self.interval = "1440min"
|
||||
|
||||
def print_help(self):
|
||||
"""Print help"""
|
||||
help_text = """https://github.com/GamestonkTerminal/GamestonkTerminal/tree/main/gamestonk_terminal/stocks
|
||||
@@ -114,6 +116,13 @@ What do you want to do?
|
||||
quote view the current price for a specific stock ticker
|
||||
candle view a candle chart for a specific stock ticker
|
||||
|
||||
"""
|
||||
help_text += ">> options go into options context"
|
||||
if self.ticker:
|
||||
help_text += f" with {self.ticker}"
|
||||
|
||||
help_text += """
|
||||
|
||||
> disc discover trending stocks, \t e.g. map, sectors, high short interest
|
||||
> scr screener stocks, \t\t e.g. overview/performance, using preset filters
|
||||
> gov government menu, \t\t house trading, contracts, corporate lobbying
|
||||
@@ -438,10 +447,14 @@ What do you want to do?
|
||||
else:
|
||||
return True
|
||||
|
||||
def call_options(self, _):
|
||||
"""Process options command"""
|
||||
return options_controller.menu(self.ticker)
|
||||
|
||||
def menu():
|
||||
|
||||
def menu(ticker: str = ""):
|
||||
"""Stocks Menu"""
|
||||
stocks_controller = StocksController()
|
||||
stocks_controller = StocksController(ticker)
|
||||
stocks_controller.call_help(None)
|
||||
while True:
|
||||
if session and gtff.USE_PROMPT_TOOLKIT:
|
||||
|
||||
@@ -167,13 +167,13 @@ What do you want to do?
|
||||
return crypto_controller.menu()
|
||||
|
||||
def call_economy(self, _):
|
||||
"""Process econ command"""
|
||||
"""Process economy command"""
|
||||
from gamestonk_terminal.economy import economy_controller
|
||||
|
||||
return economy_controller.menu()
|
||||
|
||||
def call_options(self, _):
|
||||
"""Process op command"""
|
||||
"""Process options command"""
|
||||
from gamestonk_terminal.options import options_controller
|
||||
|
||||
return options_controller.menu()
|
||||
@@ -185,7 +185,7 @@ What do you want to do?
|
||||
return etf_controller.menu()
|
||||
|
||||
def call_forex(self, _):
|
||||
"""Process fx command"""
|
||||
"""Process forex command"""
|
||||
from gamestonk_terminal.forex import forex_controller
|
||||
|
||||
return forex_controller.menu()
|
||||
|
||||
Reference in New Issue
Block a user