2021-07-06 03:48:56 +00:00
|
|
|
from decimal import Decimal
|
2021-07-08 03:14:08 +00:00
|
|
|
from enum import Enum
|
2021-07-11 02:44:57 +00:00
|
|
|
from math import ceil
|
2021-07-08 03:14:08 +00:00
|
|
|
|
2021-07-08 03:04:38 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2021-07-06 03:48:56 +00:00
|
|
|
|
2021-07-08 03:14:08 +00:00
|
|
|
|
2021-07-06 03:48:56 +00:00
|
|
|
one = Decimal(1.0)
|
|
|
|
four = Decimal(4.0)
|
|
|
|
twenty_four = Decimal(24.0)
|
|
|
|
|
|
|
|
|
2021-07-08 03:04:38 +00:00
|
|
|
class InterestMode(Enum):
|
2021-07-08 03:14:08 +00:00
|
|
|
"""Equations to calculate interest"""
|
2021-07-06 03:48:56 +00:00
|
|
|
|
2021-07-08 03:04:38 +00:00
|
|
|
HOURSPERDAY = "HOURSPERDAY"
|
|
|
|
HOURSPER4 = "HOURSPER4" # Hours per 4 hour segment
|
2021-07-08 03:14:08 +00:00
|
|
|
NONE = "NONE"
|
2021-07-06 03:48:56 +00:00
|
|
|
|
2021-07-13 01:39:35 +00:00
|
|
|
def __call__(self, borrowed: Decimal, rate: Decimal, hours: Decimal):
|
2021-07-06 03:48:56 +00:00
|
|
|
|
2021-07-08 03:04:38 +00:00
|
|
|
if self.name == "HOURSPERDAY":
|
2021-07-11 02:44:57 +00:00
|
|
|
return borrowed * rate * ceil(hours)/twenty_four
|
2021-07-08 03:04:38 +00:00
|
|
|
elif self.name == "HOURSPER4":
|
2021-07-13 01:39:35 +00:00
|
|
|
# Rounded based on https://kraken-fees-calculator.github.io/
|
2021-07-11 02:44:57 +00:00
|
|
|
return borrowed * rate * (1+ceil(hours/four))
|
2021-07-08 03:04:38 +00:00
|
|
|
else:
|
2021-07-08 03:14:08 +00:00
|
|
|
raise OperationalException("Leverage not available on this exchange with freqtrade")
|