Added tests for interest_function

This commit is contained in:
Sam Germain 2021-08-09 00:00:50 -06:00
parent 8e941e6836
commit 06206335d9
2 changed files with 67 additions and 29 deletions

View File

@ -15,8 +15,8 @@ def interest(
rate: Decimal, rate: Decimal,
hours: Decimal hours: Decimal
) -> Decimal: ) -> Decimal:
"""Equation to calculate interest on margin trades """
Equation to calculate interest on margin trades
:param exchange_name: The exchanged being trading on :param exchange_name: The exchanged being trading on
:param borrowed: The amount of currency being borrowed :param borrowed: The amount of currency being borrowed
@ -28,7 +28,6 @@ def interest(
not support margin trading for this exchange not support margin trading for this exchange
Returns: The amount of interest owed (currency matches borrowed) Returns: The amount of interest owed (currency matches borrowed)
""" """
exchange_name = exchange_name.lower() exchange_name = exchange_name.lower()
if exchange_name == "binance": if exchange_name == "binance":

View File

@ -1,26 +1,65 @@
# from decimal import Decimal from decimal import Decimal
from freqtrade.leverage import interest
# from freqtrade.enums import Collateral, TradingMode
# from freqtrade.leverage import interest
# from freqtrade.exceptions import OperationalException # from freqtrade.exceptions import OperationalException
# binance = "binance" binance = "binance"
# kraken = "kraken" kraken = "kraken"
# ftx = "ftx" ftx = "ftx"
# other = "bittrex" other = "bittrex"
def test_interest(): def test_interest():
return
borrowed = Decimal(60.0)
interest_rate = Decimal(0.0005)
interest_rate_2 = Decimal(0.00025)
ten_mins = Decimal(1/6)
five_hours = Decimal(5.0)
# Binance # Binance
# assert interest(binance, borrowed=60, rate=0.0005, assert float(interest(
# hours = 1/6) == round(0.0008333333333333334, 8) exchange_name=binance,
# TODO-lev: The below tests borrowed=borrowed,
# assert interest(binance, borrowed=60, rate=0.00025, hours=5.0) == 1.0 rate=interest_rate,
hours=ten_mins
)) == 0.00125
# # Kraken assert float(interest(
# assert interest(kraken, borrowed=60, rate=0.0005, hours=1.0) == 1.0 exchange_name=binance,
# assert interest(kraken, borrowed=60, rate=0.00025, hours=5.0) == 1.0 borrowed=borrowed,
rate=interest_rate_2,
hours=five_hours
)) == 0.003125
# # FTX # Kraken
# assert interest(ftx, borrowed=60, rate=0.0005, hours=1.0) == 1.0 assert float(interest(
# assert interest(ftx, borrowed=60, rate=0.00025, hours=5.0) == 1.0 exchange_name=kraken,
borrowed=borrowed,
rate=interest_rate,
hours=ten_mins
)) == 0.06
assert float(interest(
exchange_name=kraken,
borrowed=borrowed,
rate=interest_rate_2,
hours=five_hours
)) == 0.045
# FTX
# TODO-lev
# assert float(interest(
# exchange_name=ftx,
# borrowed=borrowed,
# rate=interest_rate,
# hours=ten_mins
# )) == 0.00125
# assert float(interest(
# exchange_name=ftx,
# borrowed=borrowed,
# rate=interest_rate_2,
# hours=five_hours
# )) == 0.003125