reduce number of pair_dict lookups, remove coin_first

This commit is contained in:
robcaulk 2022-07-26 15:58:40 +02:00
parent fb4e8430cd
commit ad25a4cb56
3 changed files with 15 additions and 17 deletions

View File

@ -166,7 +166,7 @@ class FreqaiDataDrawer:
if isinstance(object, np.generic): if isinstance(object, np.generic):
return object.item() return object.item()
def get_pair_dict_info(self, pair: str) -> Tuple[str, int, bool, bool]: def get_pair_dict_info(self, pair: str) -> Tuple[str, int, bool]:
""" """
Locate and load existing model metadata from persistent storage. If not located, Locate and load existing model metadata from persistent storage. If not located,
create a new one and append the current pair to it and prepare it for its first create a new one and append the current pair to it and prepare it for its first
@ -175,23 +175,20 @@ class FreqaiDataDrawer:
:return: :return:
model_filename: str = unique filename used for loading persistent objects from disk model_filename: str = unique filename used for loading persistent objects from disk
trained_timestamp: int = the last time the coin was trained trained_timestamp: int = the last time the coin was trained
coin_first: bool = If the coin is fresh without metadata
return_null_array: bool = Follower could not find pair metadata return_null_array: bool = Follower could not find pair metadata
""" """
pair_in_dict = self.pair_dict.get(pair) pair_dict = self.pair_dict.get(pair)
data_path_set = self.pair_dict.get(pair, {}).get("data_path", None) data_path_set = self.pair_dict.get(pair, {}).get("data_path", None)
return_null_array = False return_null_array = False
if pair_in_dict: if pair_dict:
model_filename = self.pair_dict[pair]["model_filename"] model_filename = pair_dict["model_filename"]
trained_timestamp = self.pair_dict[pair]["trained_timestamp"] trained_timestamp = pair_dict["trained_timestamp"]
coin_first = self.pair_dict[pair]["first"]
elif not self.follow_mode: elif not self.follow_mode:
self.pair_dict[pair] = {} pair_dict = self.pair_dict[pair] = {}
model_filename = self.pair_dict[pair]["model_filename"] = "" model_filename = pair_dict["model_filename"] = ""
coin_first = self.pair_dict[pair]["first"] = True trained_timestamp = pair_dict["trained_timestamp"] = 0
trained_timestamp = self.pair_dict[pair]["trained_timestamp"] = 0 pair_dict["priority"] = len(self.pair_dict)
self.pair_dict[pair]["priority"] = len(self.pair_dict)
if not data_path_set and self.follow_mode: if not data_path_set and self.follow_mode:
logger.warning( logger.warning(
@ -199,9 +196,11 @@ class FreqaiDataDrawer:
f"pair_dictionary at path {self.full_path}, sending null values " f"pair_dictionary at path {self.full_path}, sending null values "
"back to strategy." "back to strategy."
) )
trained_timestamp = 0
model_filename = ''
return_null_array = True return_null_array = True
return model_filename, trained_timestamp, coin_first, return_null_array return model_filename, trained_timestamp, return_null_array
def set_pair_dict_info(self, metadata: dict) -> None: def set_pair_dict_info(self, metadata: dict) -> None:
pair_in_dict = self.pair_dict.get(metadata["pair"]) pair_in_dict = self.pair_dict.get(metadata["pair"])

View File

@ -134,7 +134,7 @@ class IFreqaiModel(ABC):
time.sleep(1) time.sleep(1)
for pair in self.config.get("exchange", {}).get("pair_whitelist"): for pair in self.config.get("exchange", {}).get("pair_whitelist"):
(_, trained_timestamp, _, _) = self.dd.get_pair_dict_info(pair) (_, trained_timestamp, _) = self.dd.get_pair_dict_info(pair)
if self.dd.pair_dict[pair]["priority"] != 1: if self.dd.pair_dict[pair]["priority"] != 1:
continue continue
@ -177,7 +177,7 @@ class IFreqaiModel(ABC):
# following tr_train. Both of these windows slide through the # following tr_train. Both of these windows slide through the
# entire backtest # entire backtest
for tr_train, tr_backtest in zip(dk.training_timeranges, dk.backtesting_timeranges): for tr_train, tr_backtest in zip(dk.training_timeranges, dk.backtesting_timeranges):
(_, _, _, _) = self.dd.get_pair_dict_info(metadata["pair"]) (_, _, _) = self.dd.get_pair_dict_info(metadata["pair"])
train_it += 1 train_it += 1
total_trains = len(dk.backtesting_timeranges) total_trains = len(dk.backtesting_timeranges)
gc.collect() gc.collect()
@ -250,7 +250,7 @@ class IFreqaiModel(ABC):
self.dd.update_follower_metadata() self.dd.update_follower_metadata()
# get the model metadata associated with the current pair # get the model metadata associated with the current pair
(_, trained_timestamp, _, return_null_array) = self.dd.get_pair_dict_info(metadata["pair"]) (_, trained_timestamp, return_null_array) = self.dd.get_pair_dict_info(metadata["pair"])
# if the metadata doesnt exist, the follower returns null arrays to strategy # if the metadata doesnt exist, the follower returns null arrays to strategy
if self.follow_mode and return_null_array: if self.follow_mode and return_null_array:

View File

@ -4,7 +4,6 @@ from pathlib import Path
from freqtrade.configuration import TimeRange from freqtrade.configuration import TimeRange
from freqtrade.data.dataprovider import DataProvider from freqtrade.data.dataprovider import DataProvider
# from freqtrade.freqai.data_drawer import FreqaiDataDrawer
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
from tests.conftest import get_patched_exchange from tests.conftest import get_patched_exchange
from tests.freqai.conftest import get_patched_freqai_strategy from tests.freqai.conftest import get_patched_freqai_strategy