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/clean up repo #160

Merged
merged 23 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: detect-private-key

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.10.0
hooks:
- id: eslint
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [file]

- repo: https://github.com/CoinAlpha/git-hooks
rev: 78f0683233a09c68a072fd52740d32c0376d4f0f
hooks:
- id: detect-wallet-private-key
types: [file]
exclude: .json

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
files: "\\.(py)$"
args: [--settings-path=pyproject.toml]

- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies: ['flake8']
args: [--max-line-length=130]
5 changes: 3 additions & 2 deletions backend/services/backend_api_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Dict
from typing import Dict, Optional

import pandas as pd
import requests
Expand Down Expand Up @@ -115,7 +115,8 @@ def start_bot(self, start_bot_config: dict):
def stop_bot(self, bot_name: str, skip_order_cancellation: bool = False, async_backend: bool = True):
"""Stop a Hummingbot bot."""
endpoint = "stop-bot"
return self.post(endpoint, payload={"bot_name": bot_name, "skip_order_cancellation": skip_order_cancellation, "async_backend": async_backend})
return self.post(endpoint, payload={"bot_name": bot_name, "skip_order_cancellation": skip_order_cancellation,
"async_backend": async_backend})

def import_strategy(self, strategy_config: dict):
"""Import a trading strategy to a bot."""
Expand Down
4 changes: 2 additions & 2 deletions backend/services/coingecko_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re
import time

from pycoingecko import CoinGeckoAPI
import pandas as pd
import re
from pycoingecko import CoinGeckoAPI


class CoinGeckoClient:
Expand Down
2 changes: 1 addition & 1 deletion backend/services/miner_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd
import requests
from glom import *
from glom import glom


class MinerClient:
Expand Down
14 changes: 1 addition & 13 deletions backend/utils/optuna_database_manager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import json
import os
from typing import Optional

import pandas as pd
Expand Down Expand Up @@ -102,18 +102,6 @@ def _get_trial_system_attributes_table(self):
except Exception as e:
return f"Error: {str(e)}"

@property
def trial_system_attributes(self):
return self._get_trial_system_attributes_table()

def _get_trial_system_attributes_table(self):
try:
with self.session_maker() as session:
df = pd.read_sql_query(text("SELECT * FROM trial_system_attributes"), session.connection())
return df
except Exception as e:
return f"Error: {str(e)}"

@property
def version_info(self):
return self._get_version_info_table()
Expand Down
13 changes: 9 additions & 4 deletions backend/utils/os_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import glob
import subprocess
import importlib.util
import inspect
import os
import subprocess

import pandas as pd

import yaml
from hummingbot.strategy_v2.controllers.directional_trading_controller_base import DirectionalTradingControllerBase, DirectionalTradingControllerConfigBase
from hummingbot.strategy_v2.controllers.market_making_controller_base import MarketMakingControllerBase, MarketMakingControllerConfigBase
from hummingbot.strategy_v2.controllers.directional_trading_controller_base import (
DirectionalTradingControllerBase,
DirectionalTradingControllerConfigBase,
)
from hummingbot.strategy_v2.controllers.market_making_controller_base import (
MarketMakingControllerBase,
MarketMakingControllerConfigBase,
)


def remove_files_from_directory(directory: str):
Expand Down
3 changes: 3 additions & 0 deletions environment_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ dependencies:
- streamlit-elements==0.1.*
- streamlit-authenticator
- pydantic==1.10.4
- flake8
- isort
- pre-commit
7 changes: 4 additions & 3 deletions frontend/components/backtesting.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import streamlit as st
from datetime import datetime, timedelta

import streamlit as st


def backtesting_section(inputs, backend_api_client):
st.write("### Backtesting")
Expand All @@ -13,7 +14,8 @@ def backtesting_section(inputs, backend_api_client):
end_date = st.date_input("End Date", default_end_time,
help="End date is inclusive, make sure that you are not including the current date.")
with c3:
backtesting_resolution = st.selectbox("Backtesting Resolution", options=["1m", "3m", "5m", "15m", "30m", "1h", "1s"], index=0)
backtesting_resolution = st.selectbox("Backtesting Resolution",
options=["1m", "3m", "5m", "15m", "30m", "1h", "1s"], index=0)
with c4:
trade_cost = st.number_input("Trade Cost (%)", min_value=0.0, value=0.06, step=0.01, format="%.2f")
with c5:
Expand All @@ -33,7 +35,6 @@ def backtesting_section(inputs, backend_api_client):
except Exception as e:
st.error(e)
return None

if len(backtesting_results["processed_data"]) == 0:
st.error("No trades were executed during the backtesting period.")
return None
Expand Down
49 changes: 31 additions & 18 deletions frontend/components/bot_performance_card.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import pandas as pd
import streamlit as st
from hummingbot.strategy_v2.models.executors import CloseType
from streamlit_elements import mui

from frontend.components.dashboard import Dashboard

from frontend.st_utils import get_backend_api_client

TRADES_TO_SHOW = 5
Expand All @@ -31,10 +28,12 @@ class BotPerformanceCardV2(Dashboard.Item):
{"field": 'connector', "headerName": 'Connector', "width": SMALL_COL_WIDTH, "editable": False},
{"field": 'trading_pair', "headerName": 'Trading Pair', "width": SMALL_COL_WIDTH, "editable": False},
{"field": 'realized_pnl_quote', "headerName": 'Realized PNL ($)', "width": MEDIUM_COL_WIDTH, "editable": False},
{"field": 'unrealized_pnl_quote', "headerName": 'Unrealized PNL ($)', "width": MEDIUM_COL_WIDTH, "editable": False},
{"field": 'unrealized_pnl_quote', "headerName": 'Unrealized PNL ($)', "width": MEDIUM_COL_WIDTH,
"editable": False},
{"field": 'global_pnl_quote', "headerName": 'NET PNL ($)', "width": MEDIUM_COL_WIDTH, "editable": False},
{"field": 'volume_traded', "headerName": 'Volume ($)', "width": SMALL_COL_WIDTH, "editable": False},
{"field": 'open_order_volume', "headerName": 'Liquidity Placed ($)', "width": MEDIUM_COL_WIDTH, "editable": False},
{"field": 'open_order_volume', "headerName": 'Liquidity Placed ($)', "width": MEDIUM_COL_WIDTH,
"editable": False},
{"field": 'imbalance', "headerName": 'Imbalance ($)', "width": SMALL_COL_WIDTH, "editable": False},
{"field": 'close_types', "headerName": 'Close Types', "width": ULTRA_WIDE_COL_WIDTH, "editable": False}
]
Expand Down Expand Up @@ -88,7 +87,9 @@ def __call__(self, bot_name: str):
subheader="Not Available",
avatar=mui.Avatar("🤖", sx={"bgcolor": "red"}),
className=self._draggable_class)
mui.Alert(f"An error occurred while fetching bot status of the bot {bot_name}. Please check the bot client.", severity="error")
mui.Alert(
f"An error occurred while fetching bot status of the bot {bot_name}. Please check the bot client.",
severity="error")
else:
bot_data = bot_status.get("data")
is_running = bot_data.get("status") == "running"
Expand All @@ -103,7 +104,8 @@ def __call__(self, bot_name: str):
{"id": controller, "error": inner_dict.get("error")})
continue
controller_performance = inner_dict.get("performance")
controller_config = next((config for config in controller_configs if config.get("id") == controller), {})
controller_config = next(
(config for config in controller_configs if config.get("id") == controller), {})
controller_name = controller_config.get("controller_name", controller)
connector_name = controller_config.get("connector_name", "NaN")
trading_pair = controller_config.get("trading_pair", "NaN")
Expand Down Expand Up @@ -159,7 +161,9 @@ def __call__(self, bot_name: str):
title=bot_name,
subheader=status,
avatar=mui.Avatar("🤖", sx={"bgcolor": color}),
action=mui.IconButton(mui.icon.Stop, onClick=lambda: stop_bot(bot_name)) if is_running else mui.IconButton(mui.icon.Archive, onClick=lambda: archive_bot(bot_name)),
action=mui.IconButton(mui.icon.Stop,
onClick=lambda: stop_bot(bot_name)) if is_running else mui.IconButton(
mui.icon.Archive, onClick=lambda: archive_bot(bot_name)),
className=self._draggable_class)
if is_running:
with mui.CardContent(sx={"flex": 1}):
Expand All @@ -171,47 +175,53 @@ def __call__(self, bot_name: str):
elevation=1):
with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False):
mui.Typography("🏦 NET PNL", variant="h6")
mui.Typography(f"$ {total_global_pnl_quote:.3f}", variant="h6", sx={"padding": "10px 15px 10px 15px"})
mui.Typography(f"$ {total_global_pnl_quote:.3f}", variant="h6",
sx={"padding": "10px 15px 10px 15px"})
with mui.Grid(item=True, xs=2):
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("📊 NET PNL (%)", variant="h6")
mui.Typography(f"{total_global_pnl_pct:.3%}", variant="h6", sx={"padding": "10px 15px 10px 15px"})
mui.Typography(f"{total_global_pnl_pct:.3%}", variant="h6",
sx={"padding": "10px 15px 10px 15px"})
with mui.Grid(item=True, xs=2):
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("💸 Volume Traded", variant="h6")
mui.Typography(f"$ {total_volume_traded:.2f}", variant="h6", sx={"padding": "10px 15px 10px 15px"})
mui.Typography(f"$ {total_volume_traded:.2f}", variant="h6",
sx={"padding": "10px 15px 10px 15px"})
with mui.Grid(item=True, xs=2):
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("📖 Liquidity Placed", variant="h6")
mui.Typography(f"$ {total_open_order_volume:.2f}", variant="h6", sx={"padding": "10px 15px 10px 15px"})
mui.Typography(f"$ {total_open_order_volume:.2f}", variant="h6",
sx={"padding": "10px 15px 10px 15px"})
with mui.Grid(item=True, xs=2):
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("💹 Unrealized PNL", variant="h6")
mui.Typography(f"$ {total_unrealized_pnl_quote:.2f}", variant="h6", sx={"padding": "10px 15px 10px 15px"})
mui.Typography(f"$ {total_unrealized_pnl_quote:.2f}", variant="h6",
sx={"padding": "10px 15px 10px 15px"})
with mui.Grid(item=True, xs=2):
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("📊 Imbalance", variant="h6")
mui.Typography(f"$ {total_imbalance:.2f}", variant="h6", sx={"padding": "10px 15px 10px 15px"})
mui.Typography(f"$ {total_imbalance:.2f}", variant="h6",
sx={"padding": "10px 15px 10px 15px"})

with mui.Grid(container=True, spacing=1, sx={"padding": "10px 15px 10px 15px"}):
with mui.Grid(item=True, xs=11):
Expand Down Expand Up @@ -242,7 +252,8 @@ def __call__(self, bot_name: str):
with mui.Grid(container=True, spacing=1, sx={"padding": "10px 15px 10px 15px"}):
with mui.Grid(item=True, xs=11):
with mui.Paper(key=self._key,
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3,
sx={"display": "flex", "flexDirection": "column",
"borderRadius": 3,
"overflow": "hidden"},
elevation=1):
with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False):
Expand All @@ -268,7 +279,8 @@ def __call__(self, bot_name: str):
with mui.Grid(container=True, spacing=1, sx={"padding": "10px 15px 10px 15px"}):
with mui.Grid(item=True, xs=11):
with mui.Paper(key=self._key,
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3,
sx={"display": "flex", "flexDirection": "column",
"borderRadius": 3,
"overflow": "hidden"},
elevation=1):
with self.title_bar(padding="10px 15px 10px 15px", dark_switcher=False):
Expand Down Expand Up @@ -326,5 +338,6 @@ def __call__(self, bot_name: str):
action=mui.IconButton(mui.icon.Stop, onClick=lambda: stop_bot(bot_name)),
className=self._draggable_class)
with mui.CardContent(sx={"flex": 1}):
mui.Typography("An error occurred while fetching bot status.", sx={"padding": "10px 15px 10px 15px"})
mui.Typography(str(e), sx={"padding": "10px 15px 10px 15px"})
mui.Typography("An error occurred while fetching bot status.",
sx={"padding": "10px 15px 10px 15px"})
mui.Typography(str(e), sx={"padding": "10px 15px 10px 15px"})
8 changes: 6 additions & 2 deletions frontend/components/bots_file_explorer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from streamlit_elements import mui

import constants
from backend.utils.os_utils import get_directories_from_directory, get_python_files_from_directory, \
get_yml_files_from_directory, get_log_files_from_directory
from backend.utils.os_utils import (
get_directories_from_directory,
get_log_files_from_directory,
get_python_files_from_directory,
get_yml_files_from_directory,
)
from frontend.components.file_explorer_base import FileExplorerBase


Expand Down
6 changes: 4 additions & 2 deletions frontend/components/card.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from streamlit_elements import mui

from frontend.components.dashboard import Dashboard


class Card(Dashboard.Item):

DEFAULT_CONTENT = (
"This impressive paella is a perfect party dish and a fun meal to cook "
"together with your guests. Add 1 cup of frozen peas along with the mussels, "
"if you like."
)

def __call__(self, content):
with mui.Card(key=self._key, sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"}, elevation=1):
with mui.Card(key=self._key,
sx={"display": "flex", "flexDirection": "column", "borderRadius": 3, "overflow": "hidden"},
elevation=1):
mui.CardHeader(
title="Shrimp and Chorizo Paella",
subheader="September 14, 2016",
Expand Down
5 changes: 2 additions & 3 deletions frontend/components/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ def get_default_config_loader(controller_name: str):
configs = [config for config in all_configs if config["controller_name"] == controller_name]
if len(configs) > 0:
default_config = st.selectbox("Select a config", [config["id"] for config in configs])
st.session_state["default_config"] = next((config for config in all_configs if config["id"] == default_config), None)
st.session_state["default_config"] = next(
(config for config in all_configs if config["id"] == default_config), None)
st.session_state["default_config"]["id"] = st.session_state["default_config"]["id"].split("_")[0]
else:
st.warning("No existing configs found for this controller.")


Loading