mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-05-06 14:03:15 +08:00
fix: ooooo
This commit is contained in:
@@ -54,6 +54,7 @@ class Backend(pywry.PyWry):
|
||||
super().__init__(daemon=daemon, max_retries=max_retries)
|
||||
self.plotly_html: Path = (PLOTS_CORE_PATH / "plotly_temp.html").resolve()
|
||||
self.table_html: Path = (PLOTS_CORE_PATH / "table.html").resolve()
|
||||
self.liveoptions_html: Path = (PLOTS_CORE_PATH / "liveoptions.html").resolve()
|
||||
self.inject_path_to_html()
|
||||
self.isatty = (
|
||||
not JUPYTER_NOTEBOOK
|
||||
@@ -103,6 +104,12 @@ class Backend(pywry.PyWry):
|
||||
return str(self.table_html)
|
||||
return ""
|
||||
|
||||
def get_liveoptions_html(self) -> str:
|
||||
"""Get the table html file."""
|
||||
if self.liveoptions_html and self.liveoptions_html.exists():
|
||||
return str(self.liveoptions_html)
|
||||
return ""
|
||||
|
||||
def get_window_icon(self) -> str:
|
||||
"""Get the window icon."""
|
||||
icon_path = PLOTS_CORE_PATH / "assets" / "Terminal_icon.png"
|
||||
@@ -231,6 +238,53 @@ class Backend(pywry.PyWry):
|
||||
)
|
||||
)
|
||||
|
||||
def send_liveoptions(self, df_table: pd.DataFrame, title: str = ""):
|
||||
"""Send table data to the backend to be displayed in a table.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
df_table : pd.DataFrame
|
||||
Dataframe to send to backend.
|
||||
title : str, optional
|
||||
Title to display in the window, by default ""
|
||||
"""
|
||||
self.loop.run_until_complete(self.check_backend())
|
||||
|
||||
if title:
|
||||
# We remove any html tags and markdown from the title
|
||||
title = re.sub(r"<[^>]*>", "", title)
|
||||
title = re.sub(r"\[\/?[a-z]+\]", "", title)
|
||||
|
||||
# we get the length of each column using the max length of the column
|
||||
# name and the max length of the column values as the column width
|
||||
columnwidth = [
|
||||
max(len(str(df_table[col].name)), df_table[col].astype(str).str.len().max())
|
||||
for col in df_table.columns
|
||||
]
|
||||
|
||||
# we add a percentage of max to the min column width
|
||||
columnwidth = [
|
||||
int(x + (max(columnwidth) - min(columnwidth)) * 0.2) for x in columnwidth
|
||||
]
|
||||
|
||||
# in case of a very small table we set a min width
|
||||
width = max(int(min(sum(columnwidth) * 9.7, self.WIDTH + 100)), 800)
|
||||
|
||||
json_data = json.loads(df_table.to_json(orient="split"))
|
||||
json_data.update(dict(title=title))
|
||||
|
||||
self.outgoing.append(
|
||||
json.dumps(
|
||||
{
|
||||
"html_path": self.get_liveoptions_html(),
|
||||
"json_data": json.dumps(json_data),
|
||||
"width": width,
|
||||
"height": self.HEIGHT - 100,
|
||||
**self.get_kwargs(title),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
def send_html(self, html_str: str = "", html_path: str = "", title: str = ""):
|
||||
"""Send HTML to the backend to be displayed in a window.
|
||||
|
||||
|
||||
21
openbb_terminal/core/plots/liveoptions.html
vendored
Normal file
21
openbb_terminal/core/plots/liveoptions.html
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -8,6 +8,9 @@ from typing import List, Optional
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from openbb_terminal import (
|
||||
plots_backend,
|
||||
)
|
||||
from openbb_terminal.core.session.current_user import get_current_user
|
||||
from openbb_terminal.custom_prompt_toolkit import NestedCompleter
|
||||
from openbb_terminal.decorators import log_start_end
|
||||
@@ -85,6 +88,7 @@ class OptionsController(BaseController):
|
||||
"vsurf",
|
||||
"greeks",
|
||||
"eodchain",
|
||||
"live"
|
||||
]
|
||||
CHOICES_MENUS = [
|
||||
"pricing",
|
||||
@@ -306,6 +310,18 @@ class OptionsController(BaseController):
|
||||
return ["stocks", f"load {self.ticker}", "options"]
|
||||
return []
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_live(self, other_args: List[str]):
|
||||
"""Process live command"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
prog="live",
|
||||
description="Live option chain.",
|
||||
)
|
||||
|
||||
plots_backend().send_liveoptions(df_table=pd.DataFrame(), title="live options")
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def call_calc(self, other_args: List[str]):
|
||||
"""Process calc command"""
|
||||
|
||||
Reference in New Issue
Block a user