Fix fee test

This commit is contained in:
Matthias 2022-01-18 07:40:09 +01:00
parent a0c0c4dcbe
commit d3713cf245
2 changed files with 11 additions and 8 deletions

View File

@ -280,7 +280,8 @@ class TestCCXTExchange():
pair = EXCHANGES[exchangename].get('futures_pair', EXCHANGES[exchangename]['pair']) pair = EXCHANGES[exchangename].get('futures_pair', EXCHANGES[exchangename]['pair'])
since = datetime.now(timezone.utc) - timedelta(days=5) since = datetime.now(timezone.utc) - timedelta(days=5)
funding_fee = exchange._fetch_and_calculate_funding_fees(pair, 20, open_date=since) funding_fee = exchange._fetch_and_calculate_funding_fees(
pair, 20, is_short=False, open_date=since)
assert isinstance(funding_fee, float) assert isinstance(funding_fee, float)
# assert funding_fee > 0 # assert funding_fee > 0

View File

@ -4901,17 +4901,17 @@ def test_update_funding_fees(
freqtrade = get_patched_freqtradebot(mocker, default_conf) freqtrade = get_patched_freqtradebot(mocker, default_conf)
# initial funding fees, # initial funding fees,
freqtrade.execute_entry('ETH/BTC', 123) freqtrade.execute_entry('ETH/BTC', 123, is_short=is_short)
freqtrade.execute_entry('LTC/BTC', 2.0) freqtrade.execute_entry('LTC/BTC', 2.0, is_short=is_short)
freqtrade.execute_entry('XRP/BTC', 123) freqtrade.execute_entry('XRP/BTC', 123, is_short=is_short)
multipl = 1 if is_short else -1
trades = Trade.get_open_trades() trades = Trade.get_open_trades()
assert len(trades) == 3 assert len(trades) == 3
for trade in trades: for trade in trades:
assert pytest.approx(trade.funding_fees) == ( assert pytest.approx(trade.funding_fees) == (
trade.amount * trade.amount *
mark_prices[trade.pair].iloc[0]['open'] * mark_prices[trade.pair].iloc[0]['open'] *
funding_rates[trade.pair].iloc[0]['open'] funding_rates[trade.pair].iloc[0]['open'] * multipl
) )
mocker.patch('freqtrade.exchange.Exchange.create_order', return_value=open_exit_order) mocker.patch('freqtrade.exchange.Exchange.create_order', return_value=open_exit_order)
time_machine.move_to("2021-09-01 08:00:00 +00:00") time_machine.move_to("2021-09-01 08:00:00 +00:00")
@ -4926,7 +4926,7 @@ def test_update_funding_fees(
assert trade.funding_fees == pytest.approx(sum( assert trade.funding_fees == pytest.approx(sum(
trade.amount * trade.amount *
mark_prices[trade.pair].iloc[0:2]['open'] * mark_prices[trade.pair].iloc[0:2]['open'] *
funding_rates[trade.pair].iloc[0:2]['open'] funding_rates[trade.pair].iloc[0:2]['open'] * multipl
)) ))
else: else:
@ -4936,7 +4936,9 @@ def test_update_funding_fees(
for trade in trades: for trade in trades:
assert trade.funding_fees == pytest.approx(sum( assert trade.funding_fees == pytest.approx(sum(
trade.amount * trade.amount *
mark_prices[trade.pair].iloc[0:2]['open'] * funding_rates[trade.pair].iloc[0:2]['open'] mark_prices[trade.pair].iloc[0:2]['open'] *
funding_rates[trade.pair].iloc[0:2]['open'] *
multipl
)) ))