freqtrade / ftui

FTUI - a terminal-based Freqtrade UI client
MIT License
66 stars 8 forks source link

FTUI ZeroDivisionError when executing _get_open_trade_dataframe #7

Closed tlecocq-dd closed 2 months ago

tlecocq-dd commented 2 months ago

FTUI ZeroDivisionError when executing _get_open_trade_dataframe

Problem Description

FTUI was working correctly yesterday, but today a zero division error occurs during execution.

Error Message

File "/home/opc/ftui/ftui/ftui.py", line 474, in main
  op_data = ftapp._get_open_trade_dataframe(cl)
File "/home/opc/ftui/ftui/ftui.py", line 160, in _get_open_trade_dataframe
  ((t["stop_loss_abs"] - t["open_rate"]) / t["stop_loss_abs"]) * 100, 2
ZeroDivisionError: float division by zero

Additional Details

Impact

The application cannot run correctly due to this error.

Possible Solution

Check if t["stop_loss_abs"] is equal to zero before performing the division, and handle this case appropriately.

Environment

xmatthias commented 2 months ago

I guess you're using custom pricing - so the order is still open? (that's the only instance where stoploss_abs can be 0 - unless you use a stoploss of -1).

At any rate, while from a data perspective, it's not something that'll happen often - it still shouldn't crash ftui.

froggleston commented 2 months ago

So in this instance what would be the preferred output?

xmatthias commented 2 months ago

i'd assume that the actual happening is "this is the initial phase, before a stoploss is set". setting a stop at -1 - and get the math to align 100% to become 0 is rather difficult :laughing:

froggleston commented 2 months ago

OK in that case I'll settle for - 😄

froggleston commented 2 months ago

Addressed in https://github.com/freqtrade/ftui/commit/5859126d1dc1b01a5c4a9edb1247b52d952d105d. Will be in the next release.