Remove deprecated currencies dashboard and it's dependency

This commit is contained in:
Theodore Aptekarev
2023-03-16 11:41:13 +01:00
parent 25403f3be1
commit 34d18d8d61
5 changed files with 1 additions and 312 deletions

View File

@@ -1,289 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "da655985-c9b7-492e-aefa-fbe3bc1865d5",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"import time\n",
"from datetime import datetime, timedelta\n",
"from typing import Optional\n",
"\n",
"import ipywidgets as ipw\n",
"import matplotlib.pyplot as plt\n",
"from ipyflex import FlexLayout\n",
"import matplotlib_inline.backend_inline\n",
"from openbb_terminal.dashboards.widget_helpers import price_card, stylesheet\n",
"\n",
"from openbb_terminal.sdk import openbb, theme\n",
"\n",
"%matplotlib widget\n",
"theme.applyMPLstyle()\n",
"ipw.HTML(f\"<style>{stylesheet()}</style>\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f5905453-4de6-4f5f-8012-9acdfca50987",
"metadata": {},
"outputs": [],
"source": [
"def get_exchange_rate(currency_pair: str) -> str:\n",
" \"\"\"Get exchange rate for a currency pair.\"\"\"\n",
" from_symbol, to_symbol = currency_pair.split(\"/\")\n",
" exchange_data = openbb.forex.models.av.get_quote(\n",
" to_symbol=to_symbol, from_symbol=from_symbol\n",
" )\n",
" return exchange_data[\"Realtime Currency Exchange Rate\"][\"5. Exchange Rate\"][:6]\n",
"\n",
"\n",
"def get_candle_widget(\n",
" output: Optional[ipw.Output],\n",
" to_symbol: str,\n",
" from_symbol: str,\n",
") -> ipw.Output:\n",
" \"\"\"Plot a candle chart for a currency pair.\"\"\"\n",
" start_date = datetime.now() - timedelta(days=1)\n",
" start_date = start_date.strftime(\"%Y-%m-%d\")\n",
"\n",
" exchange_rate_data = openbb.forex.models.av.get_historical(\n",
" to_symbol=to_symbol,\n",
" from_symbol=from_symbol,\n",
" start_date=start_date,\n",
" resolution=\"i\",\n",
" interval=\"15\",\n",
" )\n",
" fig, ax = plt.subplots(1, 1, figsize=(11, 4))\n",
" openbb.forex.candle(\n",
" data=exchange_rate_data,\n",
" to_symbol=to_symbol,\n",
" from_symbol=from_symbol,\n",
" external_axes=[ax],\n",
" )\n",
"\n",
" ax.set_xlim(0, len(exchange_rate_data.index))\n",
" fig.canvas.header_visible = False\n",
" fig.canvas.footer_visible = False\n",
" with output:\n",
" output.clear_output(True)\n",
" fig.canvas.show()\n",
" return output\n",
"\n",
"\n",
"def on_dropdown_change(change):\n",
" \"\"\"Update charts on change of dropdown selection.\"\"\"\n",
" if change[\"type\"] == \"change\" and change[\"name\"] == \"value\":\n",
" output = ipw.Output()\n",
" get_candle_widget(\n",
" to_symbol=to_widget.value,\n",
" from_symbol=from_widget.value,\n",
" )\n",
" dashboard.children[\"Candle\"] = output"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5c768d15-37ad-441b-b069-506c4bdbb9a7",
"metadata": {},
"outputs": [],
"source": [
"exchange_rates = {\n",
" \"EUR/USD\": {\"latest\": None, \"previous\": None},\n",
" \"USD/JPY\": {\"latest\": None, \"previous\": None},\n",
" \"GBP/USD\": {\"latest\": None, \"previous\": None},\n",
" \"AUD/USD\": {\"latest\": None, \"previous\": None},\n",
" \"USD/CAD\": {\"latest\": None, \"previous\": None},\n",
" # \"USD/CNY\": {\"latest\": None, \"previous\": None},\n",
" # \"USD/CHF\": {\"latest\": None, \"previous\": None},\n",
" # \"USD/HKD\": {\"latest\": None, \"previous\": None},\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4968ab89-aafe-4234-933c-963bd672715d",
"metadata": {},
"outputs": [],
"source": [
"def compose_widgets():\n",
" widgets = {}\n",
" for currency_pair in exchange_rates:\n",
" price = exchange_rates[currency_pair][\"latest\"]\n",
" price_color = \"neutral_color\"\n",
" if exchange_rates[currency_pair][\"previous\"] is not None:\n",
" if (\n",
" exchange_rates[currency_pair][\"latest\"]\n",
" > exchange_rates[currency_pair][\"previous\"]\n",
" ):\n",
" price_color = \"up_color\"\n",
" elif (\n",
" exchange_rates[currency_pair][\"latest\"]\n",
" < exchange_rates[currency_pair][\"previous\"]\n",
" ):\n",
" price_color = \"down_color\"\n",
" widgets[currency_pair] = ipw.HTML(\n",
" price_card(ticker=currency_pair, price=price, price_color=price_color)\n",
" )\n",
" return widgets"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f35d1500-a411-4cff-94ee-d65d4d1810f9",
"metadata": {},
"outputs": [],
"source": [
"# for currency_code in rates_to_usd:\n",
"# rates_to_usd[currency_code][\"previous\"] = rates_to_usd[currency_code][\"latest\"]\n",
"# rates_to_usd[currency_code][\"latest\"] = get_rate_against_usd(currency_code)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8a72837b-4ddd-4c01-a493-ebb430202cbc",
"metadata": {},
"outputs": [],
"source": [
"widgets = compose_widgets()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c636543c-42fe-4dd6-a900-1552a3c28c7e",
"metadata": {},
"outputs": [],
"source": [
"currency_list = openbb.forex.models.av.get_currency_list()\n",
"from_widget = ipw.Dropdown(\n",
" options=currency_list,\n",
" value=\"EUR\",\n",
" description=\"From:\",\n",
" disabled=False,\n",
" layout=ipw.Layout(margin=\"130\"),\n",
")\n",
"to_widget = ipw.Dropdown(\n",
" options=currency_list,\n",
" value=\"USD\",\n",
" description=\"To:\",\n",
" disabled=False,\n",
")\n",
"exchange_selection = ipw.VBox([from_widget, to_widget])\n",
"\n",
"widgets[\"Select\"] = exchange_selection"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9d069845-d622-4878-8b18-b385c6cb7a7f",
"metadata": {},
"outputs": [],
"source": [
"output = ipw.Output()\n",
"output = get_candle_widget(\n",
" output=output,\n",
" to_symbol=to_widget.value,\n",
" from_symbol=from_widget.value,\n",
")\n",
"widgets[\"Candle\"] = output"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "81c7e5c7-2e52-45ba-bf7d-aa240f95be2d",
"metadata": {},
"outputs": [],
"source": [
"from_widget.observe(on_dropdown_change)\n",
"to_widget.observe(on_dropdown_change)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0c7d921-e5dc-4ce8-97f1-a59b414a676a",
"metadata": {},
"outputs": [],
"source": [
"dashboard = FlexLayout(\n",
" layout_config={\"borderLeft\": False, \"borderRight\": False, \"enableSection\": False},\n",
" style={\n",
" \"height\": \"calc(100vh - 80px)\",\n",
" \"backgroundColor\": \"rgb(0 0 0)\",\n",
" \"fontFamily\": \"Consolas\",\n",
" \"fontWeight\": 800,\n",
" },\n",
" header={\n",
" \"title\": \"Currencies\",\n",
" \"style\": {\n",
" \"backgroundColor\": \"rgb(0 0 0)\",\n",
" \"fontWeight\": 400,\n",
" \"fontSize\": \"28px\",\n",
" },\n",
" \"buttons\": [],\n",
" },\n",
" widgets=widgets,\n",
" template=os.path.join(\"widgets\", \"currencies.json\"),\n",
" editable=False,\n",
")\n",
"dashboard"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5fedac44-5e09-44f0-bbbe-fbad7c8716cd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c850ba2-408b-4061-947e-5a1b8a284d22",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.6 ('obb')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
},
"voila": {
"theme": "dark"
},
"vscode": {
"interpreter": {
"hash": "cb66ba39c97f15743fbb79e204a841ea03600987d49579cfb0ffc8e8dd934c69"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}

21
poetry.lock generated vendored
View File

@@ -3124,25 +3124,6 @@ retrying = ">=1.3.3"
six = ">=1.10"
urllib3 = ">=1.15"
[[package]]
name = "ipyflex"
version = "0.2.6"
description = "Jupyter Widget Flex Layout"
category = "main"
optional = false
python-versions = ">=3.6"
files = [
{file = "ipyflex-0.2.6-py2.py3-none-any.whl", hash = "sha256:3e6fa36842f101eea89dbec0317091eb6cdbbd1b75fb056f61ed574fa6c2788e"},
{file = "ipyflex-0.2.6.tar.gz", hash = "sha256:312ffc1fd5e19a4222055ff2761c9896c415b3c91e9c5046b637b218c72e857b"},
]
[package.dependencies]
ipywidgets = ">=7.0.0,<9"
[package.extras]
docs = ["jupyter-sphinx", "nbsphinx", "nbsphinx-link", "pypandoc", "pytest-check-links", "recommonmark", "sphinx (>=1.5)", "sphinx-rtd-theme"]
test = ["nbval", "pytest (>=4.6)", "pytest-cov"]
[[package]]
name = "ipykernel"
version = "6.21.2"
@@ -10242,4 +10223,4 @@ optimization = ["Riskfolio-Lib"]
[metadata]
lock-version = "2.0"
python-versions = "^3.8,<3.11, !=3.9.7"
content-hash = "9c3abf5dc3861d0a1c5364efab55c49b7c1de8202c1ff222cadc17a5c1403d32"
content-hash = "5673985d2547944f488da556023fe0e75961cb0bc6286c2ea9035326558df04b"

1
pyproject.toml vendored
View File

@@ -87,7 +87,6 @@ tokenterminal = "^1.0.1"
torch = {version = "~1.11.0", optional = true}
watchdog = "^2.1.9"
pythclient = "^0.1.2"
ipyflex = "^0.2.4"
"ruamel.yaml" = "^0.17.21"
setuptools = "<65.5.0"
numpy = "1.23.4"

View File

@@ -128,7 +128,6 @@ inflection==0.5.1 ; python_version >= "3.8" and python_full_version != "3.9.7" a
iniconfig==2.0.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
interface-meta==1.3.0 ; python_version >= "3.8" and python_version < "3.11" and python_full_version != "3.9.7"
intrinio-sdk==6.22.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
ipyflex==0.2.6 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
ipykernel==6.21.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
ipympl==0.8.4 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
ipython-genutils==0.2.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"

1
requirements.txt vendored
View File

@@ -80,7 +80,6 @@ importlib-resources==5.12.0 ; python_version >= "3.8" and python_full_version !=
inflection==0.5.1 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
interface-meta==1.3.0 ; python_version >= "3.8" and python_version < "3.11" and python_full_version != "3.9.7"
intrinio-sdk==6.22.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
ipyflex==0.2.6 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
ipykernel==6.21.2 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
ipympl==0.8.4 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"
ipython-genutils==0.2.0 ; python_version >= "3.8" and python_full_version != "3.9.7" and python_version < "3.11"