reduce number of pair_dict lookups, remove coin_first
This commit is contained in:
parent
fb4e8430cd
commit
ad25a4cb56
@ -166,7 +166,7 @@ class FreqaiDataDrawer:
|
||||
if isinstance(object, np.generic):
|
||||
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,
|
||||
create a new one and append the current pair to it and prepare it for its first
|
||||
@ -175,23 +175,20 @@ class FreqaiDataDrawer:
|
||||
:return:
|
||||
model_filename: str = unique filename used for loading persistent objects from disk
|
||||
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
|
||||
"""
|
||||
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)
|
||||
return_null_array = False
|
||||
|
||||
if pair_in_dict:
|
||||
model_filename = self.pair_dict[pair]["model_filename"]
|
||||
trained_timestamp = self.pair_dict[pair]["trained_timestamp"]
|
||||
coin_first = self.pair_dict[pair]["first"]
|
||||
if pair_dict:
|
||||
model_filename = pair_dict["model_filename"]
|
||||
trained_timestamp = pair_dict["trained_timestamp"]
|
||||
elif not self.follow_mode:
|
||||
self.pair_dict[pair] = {}
|
||||
model_filename = self.pair_dict[pair]["model_filename"] = ""
|
||||
coin_first = self.pair_dict[pair]["first"] = True
|
||||
trained_timestamp = self.pair_dict[pair]["trained_timestamp"] = 0
|
||||
self.pair_dict[pair]["priority"] = len(self.pair_dict)
|
||||
pair_dict = self.pair_dict[pair] = {}
|
||||
model_filename = pair_dict["model_filename"] = ""
|
||||
trained_timestamp = pair_dict["trained_timestamp"] = 0
|
||||
pair_dict["priority"] = len(self.pair_dict)
|
||||
|
||||
if not data_path_set and self.follow_mode:
|
||||
logger.warning(
|
||||
@ -199,9 +196,11 @@ class FreqaiDataDrawer:
|
||||
f"pair_dictionary at path {self.full_path}, sending null values "
|
||||
"back to strategy."
|
||||
)
|
||||
trained_timestamp = 0
|
||||
model_filename = ''
|
||||
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:
|
||||
pair_in_dict = self.pair_dict.get(metadata["pair"])
|
||||
|
@ -134,7 +134,7 @@ class IFreqaiModel(ABC):
|
||||
time.sleep(1)
|
||||
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:
|
||||
continue
|
||||
@ -177,7 +177,7 @@ class IFreqaiModel(ABC):
|
||||
# following tr_train. Both of these windows slide through the
|
||||
# entire backtest
|
||||
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
|
||||
total_trains = len(dk.backtesting_timeranges)
|
||||
gc.collect()
|
||||
@ -250,7 +250,7 @@ class IFreqaiModel(ABC):
|
||||
self.dd.update_follower_metadata()
|
||||
|
||||
# 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 self.follow_mode and return_null_array:
|
||||
|
@ -4,7 +4,6 @@ from pathlib import Path
|
||||
|
||||
from freqtrade.configuration import TimeRange
|
||||
from freqtrade.data.dataprovider import DataProvider
|
||||
# from freqtrade.freqai.data_drawer import FreqaiDataDrawer
|
||||
from freqtrade.freqai.data_kitchen import FreqaiDataKitchen
|
||||
from tests.conftest import get_patched_exchange
|
||||
from tests.freqai.conftest import get_patched_freqai_strategy
|
||||
|
Loading…
Reference in New Issue
Block a user