Parametrize tests

This commit is contained in:
Matthias 2021-08-09 11:35:27 +02:00
parent de4b0d1f7c
commit 599ae15460

View File

@ -1,65 +1,37 @@
from decimal import Decimal from decimal import Decimal
from math import isclose
import pytest
from freqtrade.leverage import interest from freqtrade.leverage import interest
# from freqtrade.exceptions import OperationalException
binance = "binance"
kraken = "kraken"
ftx = "ftx"
other = "bittrex"
def test_interest():
borrowed = Decimal(60.0)
interest_rate = Decimal(0.0005)
interest_rate_2 = Decimal(0.00025)
ten_mins = Decimal(1/6) ten_mins = Decimal(1/6)
five_hours = Decimal(5.0) five_hours = Decimal(5.0)
twentyfive_hours = Decimal(25.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 # Kraken
assert float(interest( ('kraken', 0.0005, ten_mins, 0.06),
exchange_name=kraken, ('kraken', 0.00025, ten_mins, 0.03),
borrowed=borrowed, ('kraken', 0.00025, five_hours, 0.045),
rate=interest_rate, ('kraken', 0.00025, twentyfive_hours, 0.12),
hours=ten_mins
)) == 0.06
assert float(interest(
exchange_name=kraken,
borrowed=borrowed,
rate=interest_rate_2,
hours=five_hours
)) == 0.045
# FTX # FTX
# TODO-lev # TODO-lev: - implement FTX tests
# assert float(interest( # ('ftx', Decimal(0.0005), ten_mins, 0.06),
# exchange_name=ftx, # ('ftx', Decimal(0.0005), five_hours, 0.045),
# borrowed=borrowed, ])
# rate=interest_rate, def test_interest(exchange, interest_rate, hours, expected):
# hours=ten_mins borrowed = Decimal(60.0)
# )) == 0.00125
# assert float(interest( assert isclose(interest(
# exchange_name=ftx, exchange_name=exchange,
# borrowed=borrowed, borrowed=borrowed,
# rate=interest_rate_2, rate=Decimal(interest_rate),
# hours=five_hours hours=hours
# )) == 0.003125 ), expected)