Merge pull request #7975 from freqtrade/improve-freqai-gap-handling

handle data gaps between FreqAI and DP better
This commit is contained in:
Matthias 2023-02-26 15:26:46 +01:00 committed by GitHub
commit 66c2e145cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -570,12 +570,12 @@ class FreqaiDataDrawer:
for pair in dk.all_pairs: for pair in dk.all_pairs:
for tf in feat_params.get("include_timeframes"): for tf in feat_params.get("include_timeframes"):
hist_df = history_data[pair][tf]
# check if newest candle is already appended # check if newest candle is already appended
df_dp = strategy.dp.get_pair_dataframe(pair, tf) df_dp = strategy.dp.get_pair_dataframe(pair, tf)
if len(df_dp.index) == 0: if len(df_dp.index) == 0:
continue continue
if str(history_data[pair][tf].iloc[-1]["date"]) == str( if str(hist_df.iloc[-1]["date"]) == str(
df_dp.iloc[-1:]["date"].iloc[-1] df_dp.iloc[-1:]["date"].iloc[-1]
): ):
continue continue
@ -583,21 +583,30 @@ class FreqaiDataDrawer:
try: try:
index = ( index = (
df_dp.loc[ df_dp.loc[
df_dp["date"] == history_data[pair][tf].iloc[-1]["date"] df_dp["date"] == hist_df.iloc[-1]["date"]
].index[0] ].index[0]
+ 1 + 1
) )
except IndexError: except IndexError:
logger.warning( if hist_df.iloc[-1]['date'] < df_dp['date'].iloc[0]:
f"Unable to update pair history for {pair}. " raise OperationalException("In memory historical data is older than "
"If this does not resolve itself after 1 additional candle, " f"oldest DataProvider candle for {pair} on "
"please report the error to #freqai discord channel" f"timeframe {tf}")
) else:
return index = -1
logger.warning(
f"No common dates in historical data and dataprovider for {pair}. "
f"Appending latest dataprovider candle to historical data "
"but please be aware that there is likely a gap in the historical "
"data. \n"
f"Historical data ends at {hist_df.iloc[-1]['date']} "
f"while dataprovider starts at {df_dp['date'].iloc[0]} and"
f"ends at {df_dp['date'].iloc[0]}."
)
history_data[pair][tf] = pd.concat( history_data[pair][tf] = pd.concat(
[ [
history_data[pair][tf], hist_df,
df_dp.iloc[index:], df_dp.iloc[index:],
], ],
ignore_index=True, ignore_index=True,