Merge branch 'main' into New-Portfolio-Optimization-Menu

This commit is contained in:
Jeroen Bouma
2022-04-06 06:59:49 +02:00
committed by GitHub
8 changed files with 51 additions and 19 deletions

View File

@@ -91,7 +91,11 @@ def get_global_market() -> pd.DataFrame:
for key, date in global_markets.items():
if "date" in key:
try:
global_markets[key] = parser.parse(date).strftime("%Y-%m-%d %H:%M:%S")
if isinstance(date, datetime):
new_date = date
else:
new_date = parser.parse(date)
global_markets[key] = new_date.strftime("%Y-%m-%d %H:%M:%S")
except (KeyError, ValueError, TypeError) as e:
logger.exception(str(e))
console.print(e)

View File

@@ -15,13 +15,14 @@
"import numpy as np\n",
"import pandas as pd\n",
"from IPython.display import display\n",
"from openbb_terminal import api as openbb\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"module_path = os.path.abspath(os.path.join(\"../..\"))\n",
"module_path = os.path.abspath(os.path.join(\"../../..\"))\n",
"\n",
"if module_path not in sys.path:\n",
" sys.path.append(module_path)"
" sys.path.append(module_path)\n",
"\n",
"from openbb_terminal import api as openbb"
]
},
{
@@ -153,7 +154,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.8.13"
}
},
"nbformat": 4,

View File

@@ -15,7 +15,7 @@
"import warnings\n",
"\n",
"warnings.filterwarnings(\"ignore\")\n",
"module_path = os.path.abspath(os.path.join(\"../..\"))\n",
"module_path = os.path.abspath(os.path.join(\"../../..\"))\n",
"\n",
"if module_path not in sys.path:\n",
" sys.path.append(module_path)"
@@ -254,7 +254,7 @@
"hash": "158b8ab50e95ded652d8f2b468df64cac8eaa223c5e60f12cdaaeaccc6039b6d"
},
"kernelspec": {
"display_name": "Python 3.8.12 64-bit ('gst': conda)",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -268,7 +268,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
"version": "3.8.13"
}
},
"nbformat": 4,

View File

@@ -231,9 +231,9 @@
"metadata": {
"celltoolbar": "Tags",
"kernelspec": {
"display_name": "",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": ""
"name": "python3"
},
"language_info": {
"codemirror_mode": {
@@ -245,7 +245,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
"version": "3.8.13"
}
},
"nbformat": 4,

View File

@@ -14,6 +14,7 @@ from openbb_terminal.cryptocurrency.coinbase_helpers import (
)
from openbb_terminal.decorators import log_start_end
from openbb_terminal.rich_config import console
import openbb_terminal.cryptocurrency.due_diligence.coinbase_model as cbm
logger = logging.getLogger(__name__)
@@ -72,15 +73,32 @@ def get_accounts(add_current_price: bool = True, currency: str = "USD") -> pd.Da
if add_current_price:
current_prices = []
for _, row in df.iterrows():
for index, row in df.iterrows():
_, pairs = cbm.show_available_pairs_for_given_symbol(row.currency)
if currency not in pairs:
df.drop(index, inplace=True)
continue
to_get = f"{row.currency}-{currency}"
current_prices.append(
float(
make_coinbase_request(f"/products/{to_get}/stats", auth=auth)[
"last"
]
# Check pair validity. This is needed for delisted products like XRP
try:
cb_request = make_coinbase_request(
f"/products/{to_get}/stats", auth=auth
)
)
except Exception as e:
if "Not allowed for delisted products" in str(e):
message = f"Coinbase product is delisted {str(e)}"
logger.debug(message)
else:
message = (
f"Coinbase does not recognize this pair {to_get}: {str(e)}"
)
logger.debug(message)
df.drop(index, inplace=True)
continue
current_prices.append(float(cb_request["last"]))
df["current_price"] = current_prices
df[f"BalanceValue({currency})"] = df.current_price * df.balance.astype(float)

View File

@@ -88,5 +88,8 @@ def get_comparison_data(data_type: str, similar: List[str]):
try:
return screen.screener_view(verbose=0)
except IndexError:
console.print("[red]Invalid data from website[red]")
console.print("[red]Invalid data from website[red]\n")
return pd.DataFrame()
except AttributeError:
console.print("[red]Invalid data from website[red]\n")
return pd.DataFrame()

View File

@@ -165,6 +165,9 @@ def view_historical_greeks(
ax.set_title(
f"{(greek).capitalize()} historical for {ticker.upper()} {strike} {['Call','Put'][put]}"
)
if df.empty:
console.print("[red]Data from API is not valid.[/red]\n")
return
ax.set_xlim(df.index[0], df.index[-1])
ims = im1 + im2
labels = [lab.get_label() for lab in ims]

View File

@@ -105,6 +105,9 @@ def get_screener_data(preset_loaded: str, data_type: str, limit: int, ascend: bo
except IndexError:
console.print("[red]Invalid data provided by the website[/red]\n")
return pd.DataFrame()
except AttributeError:
console.print("[red]Invalid data provided by the website[/red]\n")
return pd.DataFrame()
else:
preset_filter = configparser.RawConfigParser()