From 599ae15460eb1ddf39817378a87e310d5e5d6466 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 9 Aug 2021 11:35:27 +0200 Subject: [PATCH] Parametrize tests --- tests/leverage/test_leverage.py | 82 +++++++++++---------------------- 1 file changed, 27 insertions(+), 55 deletions(-) diff --git a/tests/leverage/test_leverage.py b/tests/leverage/test_leverage.py index 963051f7d..7b7ca0f9b 100644 --- a/tests/leverage/test_leverage.py +++ b/tests/leverage/test_leverage.py @@ -1,65 +1,37 @@ from decimal import Decimal +from math import isclose + +import pytest from freqtrade.leverage import interest -# from freqtrade.exceptions import OperationalException -binance = "binance" -kraken = "kraken" -ftx = "ftx" -other = "bittrex" +ten_mins = Decimal(1/6) +five_hours = Decimal(5.0) +twentyfive_hours = Decimal(25.0) -def test_interest(): - - 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 - assert float(interest( - exchange_name=binance, - borrowed=borrowed, - rate=interest_rate, - hours=ten_mins - )) == 0.00125 - - assert float(interest( - exchange_name=binance, - borrowed=borrowed, - rate=interest_rate_2, - hours=five_hours - )) == 0.003125 - +@pytest.mark.parametrize('exchange,interest_rate,hours,expected', [ + ('binance', 0.0005, ten_mins, 0.00125), + ('binance', 0.00025, ten_mins, 0.000625), + ('binance', 0.00025, five_hours, 0.003125), + ('binance', 0.00025, twentyfive_hours, 0.015625), # Kraken - assert float(interest( - 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 - + ('kraken', 0.0005, ten_mins, 0.06), + ('kraken', 0.00025, ten_mins, 0.03), + ('kraken', 0.00025, five_hours, 0.045), + ('kraken', 0.00025, twentyfive_hours, 0.12), # FTX - # TODO-lev - # assert float(interest( - # exchange_name=ftx, - # borrowed=borrowed, - # rate=interest_rate, - # hours=ten_mins - # )) == 0.00125 + # TODO-lev: - implement FTX tests + # ('ftx', Decimal(0.0005), ten_mins, 0.06), + # ('ftx', Decimal(0.0005), five_hours, 0.045), +]) +def test_interest(exchange, interest_rate, hours, expected): + borrowed = Decimal(60.0) - # assert float(interest( - # exchange_name=ftx, - # borrowed=borrowed, - # rate=interest_rate_2, - # hours=five_hours - # )) == 0.003125 + assert isclose(interest( + exchange_name=exchange, + borrowed=borrowed, + rate=Decimal(interest_rate), + hours=hours + ), expected)