mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-14 03:41:14 +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(
|
combined = mark_rates.merge(
|
||||||
funding_rates, on="date", how="left", suffixes=["_mark", "_fund"]
|
funding_rates, on="date", how="left", suffixes=["_mark", "_fund"]
|
||||||
)
|
)
|
||||||
combined["open_fund"] = combined["open_fund"].fillna(futures_funding_rate)
|
# Fill only leading missing funding rates so gaps stay untouched
|
||||||
return combined[relevant_cols]
|
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(
|
def calculate_funding_fees(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -5350,11 +5350,12 @@ def test_combine_funding_and_mark(
|
|||||||
df = exchange.combine_funding_and_mark(funding_rates, mark_rates, futures_funding_rate)
|
df = exchange.combine_funding_and_mark(funding_rates, mark_rates, futures_funding_rate)
|
||||||
|
|
||||||
if futures_funding_rate is not None:
|
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[0]["open_fund"] == funding_rate
|
||||||
assert df.iloc[1]["open_fund"] == futures_funding_rate
|
# assert df.iloc[1]["open_fund"] == futures_funding_rate
|
||||||
assert df.iloc[2]["open_fund"] == funding_rate
|
assert df.iloc[-1]["open_fund"] == funding_rate
|
||||||
assert df["date"].to_list() == [prior2_date, prior_date, trade_date]
|
# Mid-candle is dropped ...
|
||||||
|
assert df["date"].to_list() == [prior2_date, trade_date]
|
||||||
else:
|
else:
|
||||||
assert len(df) == 2
|
assert len(df) == 2
|
||||||
assert df["date"].to_list() == [prior2_date, trade_date]
|
assert df["date"].to_list() == [prior2_date, trade_date]
|
||||||
|
|||||||
Reference in New Issue
Block a user