Esempio n. 1
0
def get_value_from_dict_or_string(data, is_time_frame=False):
    if isinstance(data, dict):
        if is_time_frame:
            return TimeFrames(data["value"])
        else:
            return data["value"]
    else:
        if is_time_frame:
            if data is None:
                return get_default_time_frame()
            else:
                return TimeFrames(data)
        else:
            return data
 def parse_time_frames(time_frames_string_list):
     result_list = []
     for time_frame_string in time_frames_string_list:
         try:
             result_list.append(TimeFrames(time_frame_string))
         except ValueError:
             get_logger(TimeFrameManager.__name__).error("No time frame available for: '{0}'. Available time "
                                                         "frames are: {1}. '{0}' time frame requirement "
                                                         "ignored.".
                                                         format(time_frame_string,
                                                                [t.value for t in TimeFrames]))
     return result_list
 def find_min_time_frame(time_frames, min_time_frame=None):
     tf_list = time_frames
     if time_frames and isinstance(next(iter(time_frames)), TimeFrames):
         tf_list = [t.value for t in time_frames]
     min_index = 0
     if min_time_frame:
         min_index = TimeFrameManager.TimeFramesRank.index(min_time_frame)
     # TimeFramesRank is the ordered list of timeframes
     for index, tf in enumerate(TimeFrameManager.TimeFramesRank):
         tf_val = tf.value
         if index >= min_index and tf_val in tf_list:
             try:
                 return TimeFrames(tf_val)
             except ValueError:
                 pass
     return min_time_frame
 def __init__(self):
     super().__init__()
     self.time_frame = TimeFrames(self.get_specific_config()[STRATEGIES_REQUIRED_TIME_FRAME][0])
Esempio n. 5
0
def init_config_time_frame_for_tests(config):
    result = []
    for time_frame in config[CONFIG_TIME_FRAME]:
        result.append(TimeFrames(time_frame))
    config[CONFIG_TIME_FRAME] = result
Esempio n. 6
0
 def _convert_time_frame(str_time_frame):
     return TimeFrames(str_time_frame)