Changed InterestMode enum implementation
This commit is contained in:
@@ -1,30 +1,24 @@
|
||||
from enum import Enum, auto
|
||||
from decimal import Decimal
|
||||
from freqtrade.exceptions import OperationalException
|
||||
|
||||
one = Decimal(1.0)
|
||||
four = Decimal(4.0)
|
||||
twenty_four = Decimal(24.0)
|
||||
|
||||
|
||||
class FunctionProxy:
|
||||
"""Allow to mask a function as an Object."""
|
||||
class InterestMode(Enum):
|
||||
|
||||
def __init__(self, function):
|
||||
self.function = function
|
||||
HOURSPERDAY = "HOURSPERDAY"
|
||||
HOURSPER4 = "HOURSPER4" # Hours per 4 hour segment
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
return self.function(*args, **kwargs)
|
||||
|
||||
borrowed, rate, hours = kwargs["borrowed"], kwargs["rate"], kwargs["hours"]
|
||||
|
||||
class InterestMode(Enum):
|
||||
"""Equations to calculate interest"""
|
||||
|
||||
# Interest_rate is per day, minimum time of 1 hour
|
||||
HOURSPERDAY = FunctionProxy(
|
||||
lambda borrowed, rate, hours: borrowed * rate * max(hours, one)/twenty_four
|
||||
)
|
||||
|
||||
# Interest_rate is per 4 hours, minimum time of 4 hours
|
||||
HOURSPER4 = FunctionProxy(
|
||||
lambda borrowed, rate, hours: borrowed * rate * (1 + max(0, (hours-four)/four))
|
||||
)
|
||||
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")
|
||||
|
Reference in New Issue
Block a user