mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Fixed breaking exchange tests from _get_funding_fee_dates, and commented out kraken get_funding_fees tests
This commit is contained in:
parent
b88482b2e9
commit
8bfcf4ee09
|
@ -1712,9 +1712,9 @@ class Exchange:
|
|||
return d.minute > 0 or d.second > 0
|
||||
|
||||
def _get_funding_fee_dates(self, d1: datetime, d2: datetime):
|
||||
d1 = datetime(d1.year, d1.month, d1.day, d1.hour, tzinfo=timezone.utc)
|
||||
if self.funding_fee_cutoff(d1):
|
||||
d1 += timedelta(hours=1)
|
||||
d1 = datetime(d1.year, d1.month, d1.day, d1.hour, tzinfo=timezone.utc)
|
||||
d2 = datetime(d2.year, d2.month, d2.day, d2.hour, tzinfo=timezone.utc)
|
||||
|
||||
results = []
|
||||
|
@ -1767,9 +1767,10 @@ class Exchange:
|
|||
)
|
||||
history = {}
|
||||
for candle in candles:
|
||||
# TODO-lev: Round down to the nearest funding fee time, incase a timestamp ever has a delay of > 1s
|
||||
# The millisecond timestamps can be delayed ~20ms
|
||||
# TODO: Round down to the nearest funding fee time,
|
||||
# incase a timestamp ever has a delay of > 1s
|
||||
milliseconds = int(candle[0] / 1000) * 1000
|
||||
# The millisecond timestamps can be delayed ~20ms
|
||||
opening_mark_price = candle[1]
|
||||
history[milliseconds] = opening_mark_price
|
||||
return history
|
||||
|
@ -1805,18 +1806,21 @@ class Exchange:
|
|||
fees: float = 0
|
||||
if not close_date:
|
||||
close_date = datetime.now(timezone.utc)
|
||||
open_timestamp = int(open_date.timestamp()) * 1000
|
||||
# close_timestamp = int(close_date.timestamp()) * 1000
|
||||
funding_rate_history = self.get_funding_rate_history(
|
||||
pair,
|
||||
int(open_date.timestamp()) * 1000
|
||||
open_timestamp
|
||||
)
|
||||
mark_price_history = self._get_mark_price_history(
|
||||
pair,
|
||||
int(open_date.timestamp()) * 1000
|
||||
open_timestamp
|
||||
)
|
||||
funding_fee_dates = self._get_funding_fee_dates(open_date, close_date)
|
||||
for date in funding_fee_dates:
|
||||
funding_rate = funding_rate_history[int(date.timestamp()) * 1000]
|
||||
mark_price = mark_price_history[int(date.timestamp()) * 1000]
|
||||
timestamp = int(date.timestamp()) * 1000
|
||||
funding_rate = funding_rate_history[timestamp]
|
||||
mark_price = mark_price_history[timestamp]
|
||||
fees += self._get_funding_fee(
|
||||
size=amount,
|
||||
mark_price=mark_price,
|
||||
|
|
|
@ -3519,6 +3519,7 @@ def test_get_funding_rate_history(mocker, default_conf, funding_rate_history):
|
|||
('binance', "2021-09-01 00:00:00", "2021-09-01 07:59:59", 30.0, -0.0006647999999999999),
|
||||
('binance', "2021-09-01 00:00:00", "2021-09-01 12:00:00", 30.0, -0.0009140999999999999),
|
||||
('binance', "2021-09-01 00:00:01", "2021-09-01 08:00:00", 30.0, -0.0009140999999999999),
|
||||
# TODO: Uncoment once calculate_funding_fees can pass time_in_ratio to exchange._get_funding_fee
|
||||
# ('kraken', "2021-09-01 00:00:00", "2021-09-01 08:00:00", 30.0, -0.0014937),
|
||||
# ('kraken', "2021-09-01 00:00:15", "2021-09-01 08:00:00", 30.0, -0.0008289),
|
||||
# ('kraken', "2021-09-01 01:00:14", "2021-09-01 08:00:00", 30.0, -0.0008289),
|
||||
|
@ -3532,6 +3533,7 @@ def test_get_funding_rate_history(mocker, default_conf, funding_rate_history):
|
|||
('gateio', "2021-09-01 00:00:00", "2021-09-01 12:00:00", 30.0, -0.0009140999999999999),
|
||||
('gateio', "2021-09-01 00:00:01", "2021-09-01 08:00:00", 30.0, -0.0002493),
|
||||
('binance', "2021-09-01 00:00:00", "2021-09-01 08:00:00", 50.0, -0.0015235000000000001),
|
||||
# TODO: Uncoment once calculate_funding_fees can pass time_in_ratio to exchange._get_funding_fee
|
||||
# ('kraken', "2021-09-01 00:00:00", "2021-09-01 08:00:00", 50.0, -0.0024895),
|
||||
('ftx', "2021-09-01 00:00:00", "2021-09-01 08:00:00", 50.0, 0.0016680000000000002),
|
||||
])
|
||||
|
@ -3596,6 +3598,7 @@ def test_calculate_funding_fees(
|
|||
|
||||
@pytest.mark.parametrize('name,expected_fees_8,expected_fees_10,expected_fees_12', [
|
||||
('binance', -0.0009140999999999999, -0.0009140999999999999, -0.0009140999999999999),
|
||||
# TODO: Uncoment once calculate_funding_fees can pass time_in_ratio to exchange._get_funding_fee
|
||||
# ('kraken', -0.0014937, -0.0014937, 0.0045759),
|
||||
('ftx', 0.0010008000000000003, 0.0021084, 0.0146691),
|
||||
('gateio', -0.0009140999999999999, -0.0009140999999999999, -0.0009140999999999999),
|
||||
|
|
|
@ -20,9 +20,9 @@ from freqtrade.persistence import Order, PairLocks, Trade
|
|||
from freqtrade.persistence.models import PairLock
|
||||
from freqtrade.strategy.interface import SellCheckTuple
|
||||
from freqtrade.worker import Worker
|
||||
from tests.conftest import (create_mock_trades, create_mock_trades_usdt, get_patched_freqtradebot,
|
||||
get_patched_worker, log_has, log_has_re, patch_edge, patch_exchange,
|
||||
patch_get_signal, patch_wallet, patch_whitelist)
|
||||
from tests.conftest import (create_mock_trades, get_patched_freqtradebot, get_patched_worker,
|
||||
log_has, log_has_re, patch_edge, patch_exchange, patch_get_signal,
|
||||
patch_wallet, patch_whitelist)
|
||||
from tests.conftest_trades import (MOCK_TRADE_COUNT, enter_side, exit_side, mock_order_1,
|
||||
mock_order_2, mock_order_2_sell, mock_order_3, mock_order_3_sell,
|
||||
mock_order_4, mock_order_5_stoploss, mock_order_6_sell)
|
||||
|
|
Loading…
Reference in New Issue
Block a user