stable/freqtrade/enums/interestmode.py

25 lines
747 B
Python
Raw Normal View History

2021-07-06 03:48:56 +00:00
from enum import Enum, auto
from decimal import Decimal
from freqtrade.exceptions import OperationalException
2021-07-06 03:48:56 +00:00
one = Decimal(1.0)
four = Decimal(4.0)
twenty_four = Decimal(24.0)
class InterestMode(Enum):
2021-07-06 03:48:56 +00:00
HOURSPERDAY = "HOURSPERDAY"
HOURSPER4 = "HOURSPER4" # Hours per 4 hour segment
2021-07-06 03:48:56 +00:00
def __call__(self, *args, **kwargs):
borrowed, rate, hours = kwargs["borrowed"], kwargs["rate"], kwargs["hours"]
2021-07-06 03:48:56 +00:00
if self.name == "HOURSPERDAY":
return borrowed * rate * max(hours, one)/twenty_four
elif self.name == "HOURSPER4":
return borrowed * rate * (1 + max(0, (hours-four)/four))
else:
raise OperationalException(f"Leverage not available on this exchange with freqtrade")