Skip to content

Commit

Permalink
Fix MODES to be Callables, add suspend/resume to screens, separate sc…
Browse files Browse the repository at this point in the history
…reen files
  • Loading branch information
froggleston committed Aug 24, 2024
1 parent 760d4b4 commit 3122892
Show file tree
Hide file tree
Showing 10 changed files with 744 additions and 709 deletions.
2 changes: 1 addition & 1 deletion ftui/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.3"
__version__ = "0.1.4"
69 changes: 16 additions & 53 deletions ftui/ftui.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@

import ftui.ftui_client as ftuic
import ftui.ftui_helpers as fth
from ftui.ftui_screens import (
DashboardScreen,
HelpScreen,
MainBotScreen,
SettingsScreen,
TradeInfoScreen,
)
from ftui.screens.dashboard_screen import DashboardScreen
from ftui.screens.help_screen import HelpScreen
from ftui.screens.main_bot_screen import MainBotScreen
from ftui.screens.modal_screens import TradeInfoScreen
from ftui.screens.settings_screen import SettingsScreen

urlre = r"^\[([a-zA-Z0-9]+)\]*([a-zA-Z0-9\-._~%!$&'()*+,;=]+)?:([ a-zA-Z0-9\-._~%!$&'()*+,;=]+)@?([a-z0-9\-._~%]+|\[[a-f0-9:.]+\]|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\]):([0-9]+)?"

Expand Down Expand Up @@ -92,21 +90,21 @@ class FreqText(App):

loglimit = 100

# setup screens
dash_screen = DashboardScreen()
# # setup screens
# dash_screen = DashboardScreen()

bot_screen = MainBotScreen()
# bot_screen = MainBotScreen()

settings_screen = SettingsScreen()
# settings_screen.set_settings(settings)
# settings_screen = SettingsScreen()
# # settings_screen.set_settings(settings)

help_screen = HelpScreen()
# help_screen = HelpScreen()

MODES = {
"dashboard": dash_screen,
"bots": bot_screen,
"settings": settings_screen,
"help": help_screen,
"dashboard": DashboardScreen,
"bots": MainBotScreen,
"settings": SettingsScreen,
"help": HelpScreen,
}

# supported colours: https://textual.textualize.io/api/color/
Expand Down Expand Up @@ -394,37 +392,9 @@ def watch_show_clients(self, show_clients: bool) -> None:
self.set_class(show_clients, "-show-clients")

# ACTIONS
async def action_switch_to_bot(self, bot_id) -> None:
current_screen = self.screen

for ts in current_screen.timers.keys():
print(f"Pausing {current_screen.id} {ts}")
current_screen.timers[ts].pause()

await self.switch_mode("bots")

for ts in self.MODES["bots"].timers.keys():
print(f"Resuming bots {ts}")
self.MODES["bots"].timers[ts].resume()

self.MODES["bots"].update_select_options(bot_id)

async def action_switch_ftui_mode(self, mode) -> None:
current_screen = self.screen

for ts in current_screen.timers.keys():
print(f"Pausing {current_screen.id} {ts}")
current_screen.timers[ts].pause()

for ts in self.MODES[mode].timers.keys():
print(f"Resuming {mode} {ts}")
self.MODES[mode].timers[ts].resume()

await self.switch_mode(mode)

if mode == "bots":
self.MODES["bots"].update_select_options()

def action_update_chart(self, bot_id, pair) -> None:
self.MODES["bots"].update_chart(bot_id, pair)

Expand All @@ -437,13 +407,6 @@ def action_show_trade_info_dialog(self, trade_id, cl_name) -> None:
tis.client = self.client_dict[cl_name]
self.push_screen(tis)

# def action_open_link(self, link) -> None:
# try:
# webbrowser.open(link, new=2)
# except Exception as e:
# print(f"Error opening link: {e}")
# pass


def setup(args):
config = args.config
Expand All @@ -455,7 +418,7 @@ def setup(args):
for s in args.servers:
try:
ftui_client = ftuic.FTUIClient(
name=s["name"],
name=s["name"] if "name" in s else None,
url=s["ip"],
port=s["port"],
username=s["username"],
Expand Down
9 changes: 6 additions & 3 deletions ftui/ftui_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def setup_client(self):
self.username = config.get("api_server", {}).get("username")
self.password = config.get("api_server", {}).get("password")

if self.name is None:
self.name = f"{self.url}:{self.port}"
#if self.name is None:
# self.name = f"{self.url}:{self.port}"

server_url = f"http://{self.url}:{self.port}"

Expand Down Expand Up @@ -89,7 +89,10 @@ def setup_client(self):

self.rest_client = client
current_config = self.get_client_config()
self.name = current_config.get("bot_name", self.name)
self.name = current_config.get(
"bot_name",
f"{self.url}:{self.port}"
) if self.name is None else self.name
bot_state = current_config["state"]
runmode = current_config["runmode"]
strategy = current_config["strategy"]
Expand Down
Loading

0 comments on commit 3122892

Please sign in to comment.