mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-13 19:31:15 +00:00
feat: don't fill up missing funding-fees after merge
This commit is contained in:
@@ -3808,8 +3808,16 @@ class Exchange:
|
||||
combined = mark_rates.merge(
|
||||
funding_rates, on="date", how="left", suffixes=["_mark", "_fund"]
|
||||
)
|
||||
combined["open_fund"] = combined["open_fund"].fillna(futures_funding_rate)
|
||||
return combined[relevant_cols]
|
||||
# Fill only leading missing funding rates so gaps stay untouched
|
||||
first_valid_idx = combined["open_fund"].first_valid_index()
|
||||
if first_valid_idx is None:
|
||||
combined["open_fund"] = futures_funding_rate
|
||||
else:
|
||||
is_leading_na = (combined.index <= first_valid_idx) & combined[
|
||||
"open_fund"
|
||||
].isna()
|
||||
combined.loc[is_leading_na, "open_fund"] = futures_funding_rate
|
||||
return combined[relevant_cols].dropna()
|
||||
|
||||
def calculate_funding_fees(
|
||||
self,
|
||||
|
||||
@@ -5350,11 +5350,12 @@ def test_combine_funding_and_mark(
|
||||
df = exchange.combine_funding_and_mark(funding_rates, mark_rates, futures_funding_rate)
|
||||
|
||||
if futures_funding_rate is not None:
|
||||
assert len(df) == 3
|
||||
assert len(df) == 2
|
||||
assert df.iloc[0]["open_fund"] == funding_rate
|
||||
assert df.iloc[1]["open_fund"] == futures_funding_rate
|
||||
assert df.iloc[2]["open_fund"] == funding_rate
|
||||
assert df["date"].to_list() == [prior2_date, prior_date, trade_date]
|
||||
# assert df.iloc[1]["open_fund"] == futures_funding_rate
|
||||
assert df.iloc[-1]["open_fund"] == funding_rate
|
||||
# Mid-candle is dropped ...
|
||||
assert df["date"].to_list() == [prior2_date, trade_date]
|
||||
else:
|
||||
assert len(df) == 2
|
||||
assert df["date"].to_list() == [prior2_date, trade_date]
|
||||
|
||||
Reference in New Issue
Block a user