Improve rpc typing

This commit is contained in:
Matthias 2023-12-21 18:14:43 +01:00
parent 1272a15c35
commit 9ec23a0292
2 changed files with 9 additions and 6 deletions

View File

@ -33,8 +33,8 @@ from freqtrade.plugins.protectionmanager import ProtectionManager
from freqtrade.resolvers import ExchangeResolver, StrategyResolver
from freqtrade.rpc import RPCManager
from freqtrade.rpc.external_message_consumer import ExternalMessageConsumer
from freqtrade.rpc.rpc_types import (RPCCancelMsg, RPCEntryMsg, RPCExitCancelMsg, RPCExitMsg,
RPCProtectionMsg)
from freqtrade.rpc.rpc_types import (ProfitLossStr, RPCCancelMsg, RPCEntryMsg, RPCExitCancelMsg,
RPCExitMsg, RPCProtectionMsg)
from freqtrade.strategy.interface import IStrategy
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
from freqtrade.util import FtPrecise
@ -1792,7 +1792,7 @@ class FreqtradeBot(LoggingMixin):
order_rate = trade.safe_close_rate
profit = trade.calculate_profit(rate=order_rate)
amount = trade.amount
gain = "profit" if profit.profit_ratio > 0 else "loss"
gain: ProfitLossStr = "profit" if profit.profit_ratio > 0 else "loss"
msg: RPCExitMsg = {
'type': (RPCMessageType.EXIT_FILL if fill
@ -1846,7 +1846,7 @@ class FreqtradeBot(LoggingMixin):
profit = trade.calculate_profit(rate=profit_rate)
current_rate = self.exchange.get_rate(
trade.pair, side='exit', is_short=trade.is_short, refresh=False)
gain = "profit" if profit.profit_ratio > 0 else "loss"
gain: ProfitLossStr = "profit" if profit.profit_ratio > 0 else "loss"
msg: RPCExitCancelMsg = {
'type': RPCMessageType.EXIT_CANCEL,

View File

@ -5,6 +5,9 @@ from freqtrade.constants import PairWithTimeframe
from freqtrade.enums import RPCMessageType
ProfitLossStr = Literal["profit", "loss"]
class RPCSendMsgBase(TypedDict):
pass
# ty1pe: Literal[RPCMessageType]
@ -74,7 +77,7 @@ class RPCCancelMsg(__RPCEntryExitMsgBase):
class RPCExitMsg(__RPCEntryExitMsgBase):
type: Literal[RPCMessageType.EXIT, RPCMessageType.EXIT_FILL]
cumulative_profit: float
gain: str # Literal["profit", "loss"]
gain: ProfitLossStr
close_rate: float
profit_amount: float
profit_ratio: float
@ -88,7 +91,7 @@ class RPCExitMsg(__RPCEntryExitMsgBase):
class RPCExitCancelMsg(__RPCEntryExitMsgBase):
type: Literal[RPCMessageType.EXIT_CANCEL]
reason: str
gain: str # Literal["profit", "loss"]
gain: ProfitLossStr
profit_amount: float
profit_ratio: float
sell_reason: Optional[str]