MCPcopy Create free account
hub / github.com/Drakkar-Software/OctoBot / _apply_time_frames_limits

Function _apply_time_frames_limits

octobot/limits.py:80–129  ·  view source on GitHub ↗
(full_config, logger, limit)

Source from the content-addressed store, hash-verified

78
79
80def _apply_time_frames_limits(full_config, logger, limit):
81 tentacles_setup_config = full_config.get_active_tentacles_setup_config()
82 has_disabled_time_frames = False
83 all_enabled_time_frames = []
84 # patch time frames config
85 for strategy_class in evaluators_api.get_activated_strategies_classes(tentacles_setup_config):
86 config_time_frames = evaluators_api.get_time_frames_from_strategy(
87 strategy_class, full_config.config, tentacles_setup_config
88 )
89 combined_time_frames = set(all_enabled_time_frames + config_time_frames)
90 if len(combined_time_frames) < limit:
91 all_enabled_time_frames = time_frame_manager.sort_time_frames(list(combined_time_frames))
92 elif len(combined_time_frames) > limit:
93 has_disabled_time_frames = True
94 if len(all_enabled_time_frames) == limit:
95 # no timeframe to add
96 pass
97 else:
98 # disable shortest timeframes first
99 missing_tf = time_frame_manager.sort_time_frames([
100 tf
101 for tf in config_time_frames
102 if tf not in all_enabled_time_frames
103 ])
104 added_time_frames = missing_tf[limit-len(all_enabled_time_frames):]
105 all_enabled_time_frames = time_frame_manager.sort_time_frames(
106 list(all_enabled_time_frames) + added_time_frames
107 )
108 else:
109 all_enabled_time_frames = list(combined_time_frames)
110 if has_disabled_time_frames:
111 should_update_config = False
112 strategy_enabled_time_frames = [
113 tf
114 for tf in config_time_frames
115 if tf in all_enabled_time_frames
116 ]
117 for time_frame in config_time_frames:
118 if time_frame not in strategy_enabled_time_frames:
119 should_update_config = True
120 logger.error(f"Disabled {time_frame.value} time frame for {strategy_class.get_name()}")
121 if should_update_config:
122 evaluators_api.update_time_frames_config(
123 strategy_class, tentacles_setup_config, strategy_enabled_time_frames
124 )
125 if has_disabled_time_frames:
126 return f"Reached maximum allowed simultaneous time frames for this plan, maximum is {limit}. " \
127 f"Your OctoBot will trade using following time frames: " \
128 f"{', '.join([tf.value for tf in all_enabled_time_frames])}."
129 return ""
130
131
132def apply_config_limits(configuration) -> list:

Callers 1

apply_config_limitsFunction · 0.85

Calls 4

errorMethod · 0.45
get_nameMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected