2021-08-09 06:00:50 +00:00
|
|
|
from decimal import Decimal
|
2021-08-09 09:35:27 +00:00
|
|
|
from math import isclose
|
2021-08-09 06:00:50 +00:00
|
|
|
|
2021-08-09 09:35:27 +00:00
|
|
|
import pytest
|
2021-08-06 07:15:18 +00:00
|
|
|
|
2021-08-09 09:35:27 +00:00
|
|
|
from freqtrade.leverage import interest
|
2021-08-09 06:00:50 +00:00
|
|
|
|
|
|
|
|
2022-04-11 16:02:02 +00:00
|
|
|
ten_mins = Decimal(1 / 6)
|
2021-08-09 09:35:27 +00:00
|
|
|
five_hours = Decimal(5.0)
|
|
|
|
twentyfive_hours = Decimal(25.0)
|
2021-08-09 06:00:50 +00:00
|
|
|
|
|
|
|
|
2021-08-09 09:35:27 +00:00
|
|
|
@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),
|
2021-08-09 06:00:50 +00:00
|
|
|
# Kraken
|
2021-08-09 09:35:27 +00:00
|
|
|
('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),
|
2021-08-09 06:00:50 +00:00
|
|
|
# FTX
|
2021-09-19 06:05:29 +00:00
|
|
|
('ftx', 0.0005, ten_mins, 0.00125),
|
|
|
|
('ftx', 0.00025, ten_mins, 0.000625),
|
|
|
|
('ftx', 0.00025, five_hours, 0.003125),
|
|
|
|
('ftx', 0.00025, twentyfive_hours, 0.015625),
|
2021-08-09 09:35:27 +00:00
|
|
|
])
|
|
|
|
def test_interest(exchange, interest_rate, hours, expected):
|
|
|
|
borrowed = Decimal(60.0)
|
2021-08-09 06:00:50 +00:00
|
|
|
|
2021-08-09 09:35:27 +00:00
|
|
|
assert isclose(interest(
|
|
|
|
exchange_name=exchange,
|
|
|
|
borrowed=borrowed,
|
|
|
|
rate=Decimal(interest_rate),
|
|
|
|
hours=hours
|
|
|
|
), expected)
|