Use FtPrecise in interest calculation
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
from decimal import Decimal
|
||||
from math import ceil
|
||||
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.util import FtPrecise
|
||||
|
||||
|
||||
one = Decimal(1.0)
|
||||
four = Decimal(4.0)
|
||||
twenty_four = Decimal(24.0)
|
||||
one = FtPrecise(1.0)
|
||||
four = FtPrecise(4.0)
|
||||
twenty_four = FtPrecise(24.0)
|
||||
|
||||
|
||||
def interest(
|
||||
exchange_name: str,
|
||||
borrowed: Decimal,
|
||||
rate: Decimal,
|
||||
hours: Decimal
|
||||
) -> Decimal:
|
||||
borrowed: FtPrecise,
|
||||
rate: FtPrecise,
|
||||
hours: FtPrecise
|
||||
) -> FtPrecise:
|
||||
"""
|
||||
Equation to calculate interest on margin trades
|
||||
|
||||
@@ -31,13 +31,13 @@ def interest(
|
||||
"""
|
||||
exchange_name = exchange_name.lower()
|
||||
if exchange_name == "binance":
|
||||
return borrowed * rate * ceil(hours) / twenty_four
|
||||
return borrowed * rate * FtPrecise(ceil(hours)) / twenty_four
|
||||
elif exchange_name == "kraken":
|
||||
# Rounded based on https://kraken-fees-calculator.github.io/
|
||||
return borrowed * rate * (one + ceil(hours / four))
|
||||
return borrowed * rate * (one + FtPrecise(ceil(hours / four)))
|
||||
elif exchange_name == "ftx":
|
||||
# As Explained under #Interest rates section in
|
||||
# https://help.ftx.com/hc/en-us/articles/360053007671-Spot-Margin-Trading-Explainer
|
||||
return borrowed * rate * ceil(hours) / twenty_four
|
||||
return borrowed * rate * FtPrecise(ceil(hours)) / twenty_four
|
||||
else:
|
||||
raise OperationalException(f"Leverage not available on {exchange_name} with freqtrade")
|
||||
|
Reference in New Issue
Block a user