Fix ROI calculation problem
Prior to that all ROI entries with a key > trade_duration where active. This causes a problem if the ROI is not linearly declining
This commit is contained in:
parent
9e0902e72f
commit
e9d61eb35d
@ -319,17 +319,18 @@ class IStrategy(ABC):
|
||||
def min_roi_reached(self, trade: Trade, current_profit: float, current_time: datetime) -> bool:
|
||||
"""
|
||||
Based an earlier trade and current price and ROI configuration, decides whether bot should
|
||||
sell
|
||||
sell. Requires current_profit to be in percent!!
|
||||
:return True if bot should sell at current rate
|
||||
"""
|
||||
|
||||
# Check if time matches and current rate is above threshold
|
||||
time_diff = (current_time.timestamp() - trade.open_date.timestamp()) / 60
|
||||
for duration, threshold in self.minimal_roi.items():
|
||||
if time_diff <= duration:
|
||||
continue
|
||||
if current_profit > threshold:
|
||||
return True
|
||||
trade_dur = (current_time.timestamp() - trade.open_date.timestamp()) / 60
|
||||
|
||||
# Get highest entry in ROI dict where key >= trade-duration
|
||||
roi_entry = max(list(filter(lambda x: trade_dur >= x, self.minimal_roi.keys())))
|
||||
threshold = self.minimal_roi[roi_entry]
|
||||
if current_profit > threshold:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user