Handle NaN funding fees

closes #9831
This commit is contained in:
Matthias
2024-02-29 07:22:40 +01:00
parent d1028b8ca2
commit e988995d71
2 changed files with 5 additions and 2 deletions

View File

@@ -8,7 +8,7 @@ import logging
import signal import signal
from copy import deepcopy from copy import deepcopy
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from math import floor from math import floor, isnan
from threading import Lock from threading import Lock
from typing import Any, Coroutine, Dict, List, Literal, Optional, Tuple, Union from typing import Any, Coroutine, Dict, List, Literal, Optional, Tuple, Union
@@ -2916,7 +2916,8 @@ class Exchange:
if not df.empty: if not df.empty:
df1 = df[(df['date'] >= open_date) & (df['date'] <= close_date)] df1 = df[(df['date'] >= open_date) & (df['date'] <= close_date)]
fees = sum(df1['open_fund'] * df1['open_mark'] * amount) fees = sum(df1['open_fund'] * df1['open_mark'] * amount)
if isnan(fees):
fees = 0.0
# Negate fees for longs as funding_fees expects it this way based on live endpoints. # Negate fees for longs as funding_fees expects it this way based on live endpoints.
return fees if is_short else -fees return fees if is_short else -fees

View File

@@ -7,6 +7,7 @@ from unittest.mock import MagicMock, Mock, PropertyMock, patch
import ccxt import ccxt
import pytest import pytest
from numpy import NaN
from pandas import DataFrame from pandas import DataFrame
from freqtrade.enums import CandleType, MarginMode, RunMode, TradingMode from freqtrade.enums import CandleType, MarginMode, RunMode, TradingMode
@@ -4203,6 +4204,7 @@ def test_get_max_leverage_from_margin(default_conf, mocker, pair, nominal_value,
(10, 0.0001, 2.0, 1.0, 0.002, 0.002), (10, 0.0001, 2.0, 1.0, 0.002, 0.002),
(10, 0.0002, 2.0, 0.01, 0.004, 0.00004), (10, 0.0002, 2.0, 0.01, 0.004, 0.00004),
(10, 0.0002, 2.5, None, 0.005, None), (10, 0.0002, 2.5, None, 0.005, None),
(10, 0.0002, NaN, None, 0.0, None),
]) ])
def test_calculate_funding_fees( def test_calculate_funding_fees(
default_conf, default_conf,