Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/improve create controllers page #78

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pages/backtest_manager/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from streamlit_elements import elements, mui

from ui_components.dashboard import Dashboard
from ui_components.directional_strategies_file_explorer import DirectionalStrategiesFileExplorer
from ui_components.controllers_file_explorer import ControllersFileExplorer
from ui_components.directional_strategy_creation_card import DirectionalStrategyCreationCard
from ui_components.editor import Editor

Expand All @@ -23,7 +23,7 @@
ds_board = SimpleNamespace(
dashboard=board,
create_strategy_card=DirectionalStrategyCreationCard(board, 0, 0, 12, 1),
file_explorer=DirectionalStrategiesFileExplorer(board, 0, 2, 3, 7),
file_explorer=ControllersFileExplorer(board, 0, 2, 3, 7),
editor=Editor(board, 4, 2, 9, 7),
)
st.session_state.ds_board = ds_board
Expand Down
21 changes: 21 additions & 0 deletions ui_components/controllers_file_explorer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from streamlit_elements import mui

import constants
from ui_components.file_explorer_base import FileExplorerBase
from utils.os_utils import get_python_files_from_directory, load_controllers


class ControllersFileExplorer(FileExplorerBase):
def add_tree_view(self):
with mui.lab.TreeView(defaultExpandIcon=mui.icon.ChevronRight, defaultCollapseIcon=mui.icon.ExpandMore,
onNodeSelect=lambda event, node_id: self.set_selected_file(event, node_id),
defaultExpanded=["directional_strategies"]):
available_controllers = load_controllers(constants.CONTROLLERS_PATH)
with mui.lab.TreeItem(nodeId="directional_strategies", label=f"⚔️Directional Strategies"):
for controller in available_controllers:
if available_controllers[controller]["type"] == "directional_trading":
mui.lab.TreeItem(nodeId=constants.CONTROLLERS_PATH + "/" + controller + ".py", label=f"🐍{controller}")
with mui.lab.TreeItem(nodeId="market_making_strategies", label=f"🪙Market Making Strategies"):
for controller in available_controllers:
if available_controllers[controller]["type"] == "market_making":
mui.lab.TreeItem(nodeId=constants.CONTROLLERS_PATH + "/" + controller + ".py", label=f"🐍{controller}")
16 changes: 0 additions & 16 deletions ui_components/directional_strategies_file_explorer.py

This file was deleted.

2 changes: 1 addition & 1 deletion ui_components/optimization_creation_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _create_optimization(self, strategy_info):

def __call__(self):
available_strategies = load_controllers(constants.CONTROLLERS_PATH)
strategy_names = [strategy for strategy, strategy_info in available_strategies.items() if "class" in strategy_info]
strategy_names = [strategy for strategy, strategy_info in available_strategies.items() if strategy_info["type"] == "directional_trading"]
with mui.Paper(key=self._key,
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"},
elevation=1):
Expand Down
8 changes: 8 additions & 0 deletions utils/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from hummingbot.smart_components.strategy_frameworks.directional_trading import DirectionalTradingControllerBase, DirectionalTradingControllerConfigBase

import yaml
from hummingbot.smart_components.strategy_frameworks.market_making import MarketMakingControllerBase, \
MarketMakingControllerConfigBase


def remove_files_from_directory(directory: str):
Expand Down Expand Up @@ -91,8 +93,14 @@ def load_controllers(path):
for name, cls in inspect.getmembers(module, inspect.isclass):
if issubclass(cls, DirectionalTradingControllerBase) and cls is not DirectionalTradingControllerBase:
controllers[module_name]["class"] = cls
controllers[module_name]["type"] = "directional_trading"
if issubclass(cls, DirectionalTradingControllerConfigBase) and cls is not DirectionalTradingControllerConfigBase:
controllers[module_name]["config"] = cls
if issubclass(cls, MarketMakingControllerBase) and cls is not MarketMakingControllerBase:
controllers[module_name]["class"] = cls
controllers[module_name]["type"] = "market_making"
if issubclass(cls, MarketMakingControllerConfigBase) and cls is not MarketMakingControllerConfigBase:
controllers[module_name]["config"] = cls
return controllers


Expand Down