All funding fee test_exchange tests pass
This commit is contained in:
parent
863e0bf837
commit
3de42da29a
@ -1743,6 +1743,7 @@ class Exchange:
|
|||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
|
@retrier
|
||||||
def _get_mark_price_history(
|
def _get_mark_price_history(
|
||||||
self,
|
self,
|
||||||
pair: str,
|
pair: str,
|
||||||
@ -1784,7 +1785,7 @@ class Exchange:
|
|||||||
pair: str,
|
pair: str,
|
||||||
amount: float,
|
amount: float,
|
||||||
open_date: datetime,
|
open_date: datetime,
|
||||||
close_date: Optional[datetime]
|
close_date: Optional[datetime] = None
|
||||||
) -> float:
|
) -> float:
|
||||||
"""
|
"""
|
||||||
calculates the sum of all funding fees that occurred for a pair during a futures trade
|
calculates the sum of all funding fees that occurred for a pair during a futures trade
|
||||||
@ -1816,6 +1817,7 @@ class Exchange:
|
|||||||
|
|
||||||
return fees
|
return fees
|
||||||
|
|
||||||
|
@retrier
|
||||||
def get_funding_rate_history(
|
def get_funding_rate_history(
|
||||||
self,
|
self,
|
||||||
pair: str,
|
pair: str,
|
||||||
|
@ -3583,21 +3583,38 @@ def test_calculate_funding_fees(
|
|||||||
assert funding_fees == expected_fees
|
assert funding_fees == expected_fees
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('name,expected_fees_8,expected_fees_10,expected_fees_12', [
|
||||||
|
('binance', -0.0009140999999999999, -0.0009140999999999999, -0.0009140999999999999),
|
||||||
|
('kraken', -0.0014937, -0.0014937, 0.0045759),
|
||||||
|
('ftx', 0.0010008000000000003, 0.0021084, 0.0146691),
|
||||||
|
('gateio', -0.0009140999999999999, -0.0009140999999999999, -0.0009140999999999999),
|
||||||
|
])
|
||||||
def test_calculate_funding_fees_datetime_called(
|
def test_calculate_funding_fees_datetime_called(
|
||||||
mocker,
|
mocker,
|
||||||
default_conf,
|
default_conf,
|
||||||
funding_rate_history,
|
funding_rate_history,
|
||||||
mark_ohlcv
|
mark_ohlcv,
|
||||||
|
name,
|
||||||
|
time_machine,
|
||||||
|
expected_fees_8,
|
||||||
|
expected_fees_10,
|
||||||
|
expected_fees_12
|
||||||
):
|
):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.fetch_ohlcv = MagicMock(return_value=mark_ohlcv)
|
api_mock.fetch_ohlcv = MagicMock(return_value=mark_ohlcv)
|
||||||
api_mock.fetch_funding_rate_history = MagicMock(return_value=funding_rate_history)
|
api_mock.fetch_funding_rate_history = MagicMock(return_value=funding_rate_history)
|
||||||
datetime = MagicMock()
|
|
||||||
datetime.now = MagicMock()
|
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchOHLCV': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchOHLCV': True})
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchFundingRateHistory': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchFundingRateHistory': True})
|
||||||
|
|
||||||
# TODO-lev: Add datetime MagicMock
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=name)
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
d1 = datetime.strptime("2021-09-01 00:00:00 +0000", '%Y-%m-%d %H:%M:%S %z')
|
||||||
exchange.calculate_funding_fees('ADA/USDT', 30.0, datetime("2021-09-01 00:00:00"))
|
|
||||||
assert datetime.now.call_count == 1
|
time_machine.move_to("2021-09-01 08:00:00 +00:00")
|
||||||
|
funding_fees = exchange.calculate_funding_fees('ADA/USDT', 30.0, d1)
|
||||||
|
assert funding_fees == expected_fees_8
|
||||||
|
time_machine.move_to("2021-09-01 10:00:00 +00:00")
|
||||||
|
funding_fees = exchange.calculate_funding_fees('ADA/USDT', 30.0, d1)
|
||||||
|
assert funding_fees == expected_fees_10
|
||||||
|
time_machine.move_to("2021-09-01 12:00:00 +00:00")
|
||||||
|
funding_fees = exchange.calculate_funding_fees('ADA/USDT', 30.0, d1)
|
||||||
|
assert funding_fees == expected_fees_12
|
||||||
|
Loading…
Reference in New Issue
Block a user