mirror of
https://github.com/aljazceru/hummingbot-dashboard.git
synced 2026-01-27 00:54:20 +01:00
(feat) remove unused components
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
from docker_manager import DockerManager
|
||||
from streamlit_elements import mui
|
||||
from frontend.components.dashboard import Dashboard
|
||||
|
||||
from backend.utils import os_utils
|
||||
|
||||
|
||||
class ExitedBotCard(Dashboard.Item):
|
||||
|
||||
def __init__(self, board, x, y, w, h, **item_props):
|
||||
super().__init__(board, x, y, w, h, **item_props)
|
||||
|
||||
@staticmethod
|
||||
def remove_container(bot_name):
|
||||
DockerManager().remove_container(bot_name)
|
||||
os_utils.remove_directory(f"./hummingbot_files/bot_configs/{bot_name}")
|
||||
|
||||
def __call__(self, bot_name: str):
|
||||
with mui.Card(key=self._key,
|
||||
sx={"display": "flex", "flexDirection": "column", "borderRadius": 2, "overflow": "auto"},
|
||||
elevation=2):
|
||||
mui.CardHeader(
|
||||
title=bot_name,
|
||||
subheader="Stopped",
|
||||
avatar=mui.Avatar("💀", sx={"bgcolor": "black"}),
|
||||
className=self._draggable_class,
|
||||
)
|
||||
|
||||
with mui.CardActions():
|
||||
with mui.Grid(container=True, spacing=2):
|
||||
with mui.Grid(item=True, xs=6):
|
||||
with mui.Button(onClick=lambda: DockerManager().start_container(bot_name),
|
||||
variant="outlined",
|
||||
color="success",
|
||||
sx={"width": "100%"}):
|
||||
mui.icon.PlayCircle()
|
||||
mui.Typography("Start Instance")
|
||||
with mui.Grid(item=True, xs=6):
|
||||
with mui.Button(onClick=lambda: self.remove_container(bot_name),
|
||||
variant="outlined",
|
||||
color="error",
|
||||
sx={"width": "100%"}):
|
||||
mui.icon.DeleteForever()
|
||||
mui.Typography("Delete Instance")
|
||||
@@ -1,97 +0,0 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from docker_manager import DockerManager
|
||||
import streamlit as st
|
||||
from streamlit_elements import mui, lazy
|
||||
|
||||
import constants
|
||||
from backend.utils.os_utils import get_directories_from_directory
|
||||
from .dashboard import Dashboard
|
||||
|
||||
|
||||
class LaunchBotCard(Dashboard.Item):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.is_master_bot_running = False
|
||||
self._bot_name = None
|
||||
self._image_name = "hummingbot/hummingbot:latest"
|
||||
self._base_bot_config = "master_bot_conf"
|
||||
|
||||
def _set_bot_name(self, event):
|
||||
self._bot_name = event.target.value
|
||||
|
||||
def _set_image_name(self, event):
|
||||
self._image_name = event.target.value
|
||||
|
||||
def _set_base_bot_config(self, event):
|
||||
self._base_bot_config = event.target.value
|
||||
|
||||
def launch_new_bot(self):
|
||||
if self._bot_name and self._image_name:
|
||||
bot_name = f"hummingbot-{self._bot_name}"
|
||||
DockerManager().create_hummingbot_instance(instance_name=bot_name,
|
||||
base_conf_folder=f"{constants.HUMMINGBOT_TEMPLATES}/{self._base_bot_config}/.",
|
||||
target_conf_folder=f"{constants.BOTS_FOLDER}/{bot_name}/.",
|
||||
controllers_folder=constants.CONTROLLERS_PATH,
|
||||
controllers_config_folder=constants.CONTROLLERS_CONFIG_PATH,
|
||||
image=self._image_name)
|
||||
with st.spinner('Starting Master Configs instance... This process may take a few seconds'):
|
||||
time.sleep(3)
|
||||
else:
|
||||
st.warning("You need to define the bot name and image in order to create one.")
|
||||
|
||||
def __call__(self):
|
||||
active_containers = DockerManager.get_active_containers()
|
||||
self.is_master_bot_running = "hummingbot-master_bot_conf" in active_containers
|
||||
password_file_path = os.path.join(constants.HUMMINGBOT_TEMPLATES + "/master_bot_conf/conf",
|
||||
'.password_verification')
|
||||
is_master_password_set = os.path.isfile(password_file_path)
|
||||
with mui.Paper(key=self._key,
|
||||
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"},
|
||||
elevation=1):
|
||||
with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False):
|
||||
mui.Typography("🚀 Create Instance", variant="h5")
|
||||
|
||||
with mui.Grid(container=True, spacing=2, sx={"padding": "10px 15px 10px 15px"}):
|
||||
with mui.Grid(item=True, xs=8):
|
||||
if not is_master_password_set:
|
||||
base_warning = "You need to set a master password in order to use the dashboard."
|
||||
if self.is_master_bot_running:
|
||||
mui.Alert(f"{base_warning} The Master Configs instance is running."
|
||||
f" Attach to it in Terminal to set the master password.", severity="success")
|
||||
else:
|
||||
mui.Alert(f"{base_warning} Master Configs instance isn't running. Start it and"
|
||||
f" set the master password to continue.", severity="error")
|
||||
else:
|
||||
mui.Alert("The new instance will contain the credentials configured in the following base instance:",
|
||||
severity="info")
|
||||
with mui.Grid(item=True, xs=4):
|
||||
master_configs = [conf.split("/")[-2] for conf in
|
||||
get_directories_from_directory(constants.HUMMINGBOT_TEMPLATES) if
|
||||
"bot_conf" in conf]
|
||||
with mui.FormControl(variant="standard", sx={"width": "100%"}):
|
||||
mui.FormHelperText("Base Configs")
|
||||
with mui.Select(label="Base Configs", defaultValue=master_configs[0],
|
||||
variant="standard", onChange=lazy(self._set_base_bot_config)):
|
||||
for master_config in master_configs:
|
||||
mui.MenuItem(master_config, value=master_config)
|
||||
with mui.Grid(item=True, xs=4):
|
||||
mui.TextField(label="Instance Name", variant="outlined", onChange=lazy(self._set_bot_name),
|
||||
sx={"width": "100%"})
|
||||
with mui.Grid(item=True, xs=4):
|
||||
mui.TextField(label="Hummingbot Image",
|
||||
defaultValue="hummingbot/hummingbot:latest",
|
||||
variant="outlined",
|
||||
placeholder="hummingbot-[name]",
|
||||
onChange=lazy(self._set_image_name),
|
||||
sx={"width": "100%"})
|
||||
|
||||
with mui.Grid(item=True, xs=4):
|
||||
with mui.Button(onClick=self.launch_new_bot,
|
||||
variant="outlined",
|
||||
color="success",
|
||||
sx={"width": "100%", "height": "100%"}):
|
||||
mui.icon.AddCircleOutline()
|
||||
mui.Typography("Create")
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from docker_manager import DockerManager
|
||||
import streamlit as st
|
||||
from streamlit_elements import mui, sync
|
||||
|
||||
import constants
|
||||
from .dashboard import Dashboard
|
||||
|
||||
|
||||
class LaunchBrokerCard(Dashboard.Item):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.is_broker_running = False
|
||||
|
||||
def manage_broker_container(self):
|
||||
if self.is_broker_running:
|
||||
DockerManager().stop_container("hummingbot-broker")
|
||||
with st.spinner('Stopping Hummingbot Broker... This process may take a few seconds...'):
|
||||
time.sleep(5)
|
||||
else:
|
||||
DockerManager().create_broker()
|
||||
with st.spinner('Starting Hummingbot Broker... This process may take a few seconds...'):
|
||||
time.sleep(20)
|
||||
|
||||
def __call__(self):
|
||||
active_containers = DockerManager.get_active_containers()
|
||||
self.is_broker_running = "hummingbot-broker" in active_containers
|
||||
with mui.Paper(key=self._key,
|
||||
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"},
|
||||
elevation=1):
|
||||
with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False):
|
||||
mui.Typography("🐙 Manage Broker", variant="h5")
|
||||
with mui.Grid(container=True, spacing=2, sx={"padding": "10px 15px 10px 15px"}):
|
||||
with mui.Grid(item=True, xs=8):
|
||||
if self.is_broker_running:
|
||||
mui.Alert("Hummingbot Broker is running - control your bots now!", severity="success")
|
||||
else:
|
||||
mui.Alert("Hummingbot Broker is not running - start it to control your bots.",
|
||||
severity="error")
|
||||
|
||||
with mui.Grid(item=True, xs=4):
|
||||
button_text = "Stop" if self.is_broker_running else "Start"
|
||||
color = "error" if self.is_broker_running else "success"
|
||||
icon = mui.icon.Stop if self.is_broker_running else mui.icon.PlayCircle
|
||||
with mui.Button(onClick=self.manage_broker_container,
|
||||
color=color,
|
||||
variant="outlined",
|
||||
sx={"width": "100%", "height": "100%"}):
|
||||
icon()
|
||||
mui.Typography(button_text)
|
||||
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from docker_manager import DockerManager
|
||||
import streamlit as st
|
||||
from streamlit_elements import mui
|
||||
|
||||
import constants
|
||||
from .dashboard import Dashboard
|
||||
|
||||
|
||||
class LaunchMasterBotCard(Dashboard.Item):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.is_master_bot_running = False
|
||||
|
||||
def manage_master_bot_container(self):
|
||||
if self.is_master_bot_running:
|
||||
DockerManager().stop_container("hummingbot-master_bot_conf")
|
||||
with st.spinner('Stopping Master Configs instance... This process may take a few seconds.'):
|
||||
time.sleep(5)
|
||||
else:
|
||||
DockerManager().remove_container("hummingbot-master_bot_conf")
|
||||
time.sleep(2)
|
||||
DockerManager().create_hummingbot_instance(instance_name="hummingbot-master_bot_conf",
|
||||
base_conf_folder="hummingbot_files/templates/master_bot_conf/.",
|
||||
target_conf_folder="hummingbot_files/templates/master_bot_conf/."
|
||||
)
|
||||
with st.spinner('Starting Master Configs instance... This process may take a few seconds.'):
|
||||
time.sleep(3)
|
||||
|
||||
def __call__(self):
|
||||
active_containers = DockerManager.get_active_containers()
|
||||
self.is_master_bot_running = "hummingbot-master_bot_conf" in active_containers
|
||||
password_file_path = os.path.join(constants.HUMMINGBOT_TEMPLATES + "/master_bot_conf/conf",
|
||||
'.password_verification')
|
||||
is_master_password_set = os.path.isfile(password_file_path)
|
||||
with mui.Paper(key=self._key,
|
||||
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"},
|
||||
elevation=1):
|
||||
with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False):
|
||||
mui.icon.Key()
|
||||
mui.Typography("Master Configs", variant="h6", sx={"marginLeft": 1})
|
||||
|
||||
with mui.Grid(container=True, spacing=2, sx={"padding": "10px 15px 10px 15px"}):
|
||||
with mui.Grid(item=True, xs=8):
|
||||
if not is_master_password_set:
|
||||
base_warning = "You need to set a master password in order to use the dashboard."
|
||||
if self.is_master_bot_running:
|
||||
mui.Alert(f"{base_warning} The Master Configs instance is running."
|
||||
f" Attach to it in Terminal to set the master password.", severity="success")
|
||||
else:
|
||||
mui.Alert(f"{base_warning} Master Configs instance isn't running. Start it and"
|
||||
f" set the master password to continue.", severity="error")
|
||||
else:
|
||||
if self.is_master_bot_running:
|
||||
mui.Alert("The Master Configs instance is running."
|
||||
" Attach to it in Terminal to add credentials.",
|
||||
severity="success",
|
||||
sx={"margin": 2})
|
||||
else:
|
||||
mui.Alert("Master Configs instance isn't running. Start it to add credentials.",
|
||||
severity="error")
|
||||
with mui.Grid(item=True, xs=4):
|
||||
button_text = "Stop" if self.is_master_bot_running else "Start"
|
||||
color = "error" if self.is_master_bot_running else "success"
|
||||
icon = mui.icon.Stop if self.is_master_bot_running else mui.icon.PlayCircle
|
||||
with mui.Button(onClick=self.manage_master_bot_container,
|
||||
color=color,
|
||||
variant="outlined",
|
||||
sx={"width": "100%", "height": "100%"}):
|
||||
icon()
|
||||
mui.Typography(button_text)
|
||||
|
||||
with mui.Grid(item=True, xs=8):
|
||||
if self.is_master_bot_running:
|
||||
mui.TextField(InputProps={"readOnly": True},
|
||||
label="Attach to Master Configs instance",
|
||||
value="docker attach hummingbot-master_bot_conf",
|
||||
sx={"width": "100%"})
|
||||
|
||||
Reference in New Issue
Block a user