Skip to content

Commit

Permalink
Fix div 0 error, add instance timers
Browse files Browse the repository at this point in the history
  • Loading branch information
froggleston committed Sep 22, 2024
1 parent 1c2b08e commit 5859126
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ftui/screens/dashboard_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def on_mount(self) -> None:
sd.loading = True

update_one_sec_render = self.set_interval(1, self.update_per_sec)
self.timers["1sec"] = update_one_sec_render
self.register_timer(f"{self.__class__.__name__}_1sec", update_one_sec_render)

update_five_sec_render = self.set_interval(5, self.update_per_five_sec)
self.timers["5sec"] = update_five_sec_render
self.register_timer(f"{self.__class__.__name__}_5sec", update_five_sec_render)

async def update_per_sec(self):
self.update_dashboard_all_bot_summary()
Expand Down
14 changes: 8 additions & 6 deletions ftui/screens/main_bot_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ def on_mount(self) -> None:
self.update_select_options()

update_one_sec_render = self.set_interval(1, self.update_per_sec)
self.timers["1sec"] = update_one_sec_render
self.register_timer(f"{self.__class__.__name__}_1sec", update_one_sec_render)

update_five_sec_render = self.set_interval(5, self.update_per_five_sec)
self.timers["5sec"] = update_five_sec_render
self.register_timer(f"{self.__class__.__name__}_5sec", update_five_sec_render)

update_one_min_render = self.set_interval(60, self.update_per_one_min)
self.timers["1min"] = update_one_min_render
self.register_timer(f"{self.__class__.__name__}_1min", update_one_min_render)

async def update_per_sec(self):
bot_id = self._get_bot_id_from_client_list()
Expand Down Expand Up @@ -385,10 +385,12 @@ def _render_open_trade_summary(self, ftuic):
pairstr = f"{t['pair']}{suff}"
rpfta = round(float(t["profit_abs"]), 2)
t_dir = "S" if t["is_short"] else "L"
stop_profit = round(
((t["stop_loss_abs"] - t["open_rate"]) / t["stop_loss_abs"]) * 100, 2
)

stop_profit = "--- "
if t["stop_loss_abs"] is not None and t["stop_loss_abs"] != 0:
stop_profit = round(
((t["stop_loss_abs"] - t["open_rate"]) / t["stop_loss_abs"]) * 100, 2
)
stp_txt = (
f"{t['stop_loss_abs']} [red]({stop_profit}%)"
if stop_profit <= 0
Expand Down
7 changes: 5 additions & 2 deletions ftui/widgets/timed_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
class TimedScreen(Screen):
timers = {}

def register_timer(self, name, timer):
self.timers[name] = timer

@on(ScreenSuspend)
def pause_timers(self):
for ts in self.timers.keys():
print(f"Pausing {self.id} {ts}")
print(f"Pausing {ts}")
self.timers[ts].pause()

@on(ScreenResume)
def resume_timers(self):
for ts in self.timers.keys():
print(f"Resuming {self.id} {ts}")
print(f"Resuming {ts}")
self.timers[ts].resume()

0 comments on commit 5859126

Please sign in to comment.