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: return TimeFrames(data) else: return data
def find_config_min_time_frame(config_time_frames): # TimeFramesRank is the ordered list of timeframes for tf in TimeFrameManager.TimeFramesRank: if tf in config_time_frames: try: return TimeFrames(tf) except ValueError: pass return TimeFrames.ONE_MINUTE
def get_config_time_frame(config): if CONFIG_TIME_FRAME in config: result = [] for time_frame in config[CONFIG_TIME_FRAME]: try: result.append(TimeFrames(time_frame)) except ValueError: logging.warning( "Time frame not found : {0}".format(time_frame)) return result else: return TimeFrames
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: logging.getLogger(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_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
def _convert_time_frame(str_time_frame): return TimeFrames(str_time_frame)
def set_default_time_frame_for_this_symbol(time_frame_value): set_default_time_frame(TimeFrames(time_frame_value))