Skip to content

Commit 2d4b02f

Browse files
committed
refactor: align wording from category to space
1 parent c5a339e commit 2d4b02f

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

freqtrade/strategy/hyper.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ def __init__(self, config: Config, *args, **kwargs):
4141
self._ft_params_from_file = params
4242
# Init/loading of parameters is done as part of ft_bot_start().
4343

44-
def enumerate_parameters(
45-
self, category: str | None = None
46-
) -> Iterator[tuple[str, BaseParameter]]:
44+
def enumerate_parameters(self, space: str | None = None) -> Iterator[tuple[str, BaseParameter]]:
4745
"""
4846
Find all optimizable parameters and return (name, attr) iterator.
49-
:param category:
47+
:param space: parameter space to filter for, or None for all spaces.
5048
:return:
5149
"""
52-
for category in [c for c in self._ft_hyper_params if category is None or c == category]:
53-
for par in self._ft_hyper_params[category].values():
50+
for space in [c for c in self._ft_hyper_params if space is None or c == space]:
51+
for par in self._ft_hyper_params[space].values():
5452
yield par.name, par
5553

5654
def ft_load_params_from_file(self) -> None:
@@ -132,8 +130,8 @@ def _ft_load_params(
132130

133131
for param_name, param in params.items():
134132
param.in_space = hyperopt and HyperoptTools.has_space(self.config, space)
135-
if not param.category:
136-
param.category = space
133+
if not param.space:
134+
param.space = space
137135

138136
if param_values and param_name in param_values:
139137
if param.load:
@@ -153,8 +151,8 @@ def get_no_optimize_params(self) -> dict[str, dict]:
153151
"""
154152
params: dict[str, dict] = defaultdict(dict)
155153
for name, p in self.enumerate_parameters():
156-
if p.category and (not p.optimize or not p.in_space):
157-
params[p.category][name] = p.value
154+
if p.space and (not p.optimize or not p.in_space):
155+
params[p.space][name] = p.value
158156
return params
159157

160158

@@ -174,19 +172,19 @@ def detect_all_parameters(
174172
attr = getattr(obj, attr_name)
175173
if not issubclass(attr.__class__, BaseParameter):
176174
continue
177-
if not attr.category:
178-
# Category auto detection
179-
for category in auto_categories:
180-
if attr_name.startswith(category + "_"):
181-
attr.category = category
175+
if not attr.space:
176+
# space auto detection
177+
for space in auto_categories:
178+
if attr_name.startswith(space + "_"):
179+
attr.space = space
182180
break
183-
if attr.category is None:
181+
if attr.space is None:
184182
raise OperationalException(f"Cannot determine parameter space for {attr_name}.")
185183

186-
if attr.category in ("all", "default") or attr.category.isidentifier() is False:
184+
if attr.space in ("all", "default") or attr.space.isidentifier() is False:
187185
raise OperationalException(
188-
f"'{attr.category}' is not a valid space. Parameter: {attr_name}."
186+
f"'{attr.space}' is not a valid space. Parameter: {attr_name}."
189187
)
190188
attr.name = attr_name
191-
result[attr.category][attr_name] = attr
189+
result[attr.space][attr_name] = attr
192190
return result

freqtrade/strategy/parameters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class BaseParameter(ABC):
3232
Defines a parameter that can be optimized by hyperopt.
3333
"""
3434

35-
category: str | None
35+
space: str | None
3636
default: Any
3737
value: Any
3838
in_space: bool = False
@@ -61,7 +61,7 @@ def __init__(
6161
raise OperationalException(
6262
"Name is determined by parameter field name and can not be specified manually."
6363
)
64-
self.category = space
64+
self.space = space
6565
self._space_params = kwargs
6666
self.value = default
6767
self.optimize = optimize

0 commit comments

Comments
 (0)