refactor: Update to StrEnum where possible

This commit is contained in:
Matthias
2026-02-10 07:14:16 +01:00
parent 51431d9533
commit 812f357d7e
10 changed files with 22 additions and 39 deletions

View File

@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum
class CandleType(str, Enum):
class CandleType(StrEnum):
"""Enum to distinguish candle types"""
SPOT = "spot"
@@ -14,9 +14,6 @@ class CandleType(str, Enum):
FUNDING_RATE = "funding_rate"
# BORROW_RATE = "borrow_rate" # * unimplemented
def __str__(self):
return f"{self.name.lower()}"
@staticmethod
def from_string(value: str) -> "CandleType":
if not value:

View File

@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum
class MarginMode(str, Enum):
class MarginMode(StrEnum):
"""
Enum to distinguish between
cross margin/futures margin_mode and
@@ -11,6 +11,3 @@ class MarginMode(str, Enum):
CROSS = "cross"
ISOLATED = "isolated"
NONE = ""
def __str__(self):
return f"{self.value.lower()}"

View File

@@ -1,6 +1,6 @@
from enum import Enum
from enum import StrEnum
class OrderTypeValues(str, Enum):
class OrderTypeValues(StrEnum):
limit = "limit"
market = "market"

View File

@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum
class PriceType(str, Enum):
class PriceType(StrEnum):
"""Enum to distinguish possible trigger prices for stoplosses"""
LAST = "last"

View File

@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum
class RPCMessageType(str, Enum):
class RPCMessageType(StrEnum):
STATUS = "status"
WARNING = "warning"
EXCEPTION = "exception"
@@ -25,21 +25,16 @@ class RPCMessageType(str, Enum):
NEW_CANDLE = "new_candle"
def __repr__(self):
return self.value
def __str__(self):
# TODO: do we still need to overwrite __repr__? Impact needs to be looked at in detail
return self.value
# Enum for parsing requests from ws consumers
class RPCRequestType(str, Enum):
class RPCRequestType(StrEnum):
SUBSCRIBE = "subscribe"
WHITELIST = "whitelist"
ANALYZED_DF = "analyzed_df"
def __str__(self):
return self.value
NO_ECHO_MESSAGES = (RPCMessageType.ANALYZED_DF, RPCMessageType.WHITELIST, RPCMessageType.NEW_CANDLE)

View File

@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum
class RunMode(str, Enum):
class RunMode(StrEnum):
"""
Bot running mode (backtest, hyperopt, ...)
can be "live", "dry-run", "backtest", "hyperopt".

View File

@@ -1,4 +1,4 @@
from enum import Enum
from enum import Enum, StrEnum
class SignalType(Enum):
@@ -27,9 +27,6 @@ class SignalTagType(Enum):
return f"{self.name.lower()}"
class SignalDirection(str, Enum):
class SignalDirection(StrEnum):
LONG = "long"
SHORT = "short"
def __str__(self):
return f"{self.name.lower()}"

View File

@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum
class TradingMode(str, Enum):
class TradingMode(StrEnum):
"""
Enum to distinguish between
spot, margin, futures or any other trading method
@@ -10,6 +10,3 @@ class TradingMode(str, Enum):
SPOT = "spot"
MARGIN = "margin"
FUTURES = "futures"
def __str__(self):
return f"{self.name.lower()}"

View File

@@ -1,5 +1,5 @@
from datetime import UTC, datetime
from enum import Enum
from enum import StrEnum
from typing import ClassVar, Literal
from sqlalchemy import String
@@ -11,7 +11,7 @@ from freqtrade.persistence.base import ModelBase, SessionType
ValueTypes = str | datetime | float | int
class ValueTypesEnum(str, Enum):
class ValueTypesEnum(StrEnum):
STRING = "str"
DATETIME = "datetime"
FLOAT = "float"

View File

@@ -5,7 +5,7 @@ PairList Handler base class
import logging
from abc import ABC, abstractmethod
from copy import deepcopy
from enum import Enum
from enum import StrEnum
from typing import Any, Literal, TypedDict
from freqtrade.constants import Config
@@ -58,7 +58,7 @@ PairlistParameter = (
)
class SupportsBacktesting(str, Enum):
class SupportsBacktesting(StrEnum):
"""
Enum to indicate if a Pairlist Handler supports backtesting.
"""