Further typing ...

This commit is contained in:
Matthias 2023-03-06 19:44:23 +01:00
parent 70ad7b42b1
commit 245ae99273
2 changed files with 25 additions and 7 deletions

View File

@ -30,7 +30,8 @@ from freqtrade.plugins.protectionmanager import ProtectionManager
from freqtrade.resolvers import ExchangeResolver, StrategyResolver from freqtrade.resolvers import ExchangeResolver, StrategyResolver
from freqtrade.rpc import RPCManager from freqtrade.rpc import RPCManager
from freqtrade.rpc.external_message_consumer import ExternalMessageConsumer from freqtrade.rpc.external_message_consumer import ExternalMessageConsumer
from freqtrade.rpc.rpc_types import RPCBuyMsg, RPCCancelMsg, RPCSellCancelMsg, RPCSellMsg from freqtrade.rpc.rpc_types import (RPCBuyMsg, RPCCancelMsg, RPCProtectionMsg, RPCSellCancelMsg,
RPCSellMsg)
from freqtrade.strategy.interface import IStrategy from freqtrade.strategy.interface import IStrategy
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
from freqtrade.util import FtPrecise from freqtrade.util import FtPrecise
@ -1853,14 +1854,18 @@ class FreqtradeBot(LoggingMixin):
self.strategy.lock_pair(pair, datetime.now(timezone.utc), reason='Auto lock') self.strategy.lock_pair(pair, datetime.now(timezone.utc), reason='Auto lock')
prot_trig = self.protections.stop_per_pair(pair, side=side) prot_trig = self.protections.stop_per_pair(pair, side=side)
if prot_trig: if prot_trig:
msg = {'type': RPCMessageType.PROTECTION_TRIGGER, } msg: RPCProtectionMsg = {
msg.update(prot_trig.to_json()) 'type': RPCMessageType.PROTECTION_TRIGGER,
**prot_trig.to_json()
}
self.rpc.send_msg(msg) self.rpc.send_msg(msg)
prot_trig_glb = self.protections.global_stop(side=side) prot_trig_glb = self.protections.global_stop(side=side)
if prot_trig_glb: if prot_trig_glb:
msg = {'type': RPCMessageType.PROTECTION_TRIGGER_GLOBAL, } msg = {
msg.update(prot_trig_glb.to_json()) 'type': RPCMessageType.PROTECTION_TRIGGER_GLOBAL,
**prot_trig_glb.to_json()
}
self.rpc.send_msg(msg) self.rpc.send_msg(msg)
def apply_fee_conditional(self, trade: Trade, trade_base_currency: str, def apply_fee_conditional(self, trade: Trade, trade_base_currency: str,

View File

@ -1,19 +1,22 @@
from datetime import datetime from datetime import datetime
from typing import Optional, TypedDict, Union from typing import List, Literal, Optional, TypedDict, Union
from freqtrade.enums import RPCMessageType from freqtrade.enums import RPCMessageType
class RPCSendMsgBase(TypedDict): class RPCSendMsgBase(TypedDict):
type: RPCMessageType pass
# ty1pe: Literal[RPCMessageType]
class RPCStatusMsg(RPCSendMsgBase): class RPCStatusMsg(RPCSendMsgBase):
"""Used for Status, Startup and Warning messages""" """Used for Status, Startup and Warning messages"""
type: Literal[RPCMessageType.STATUS]
status: str status: str
class RPCProtectionMsg(RPCSendMsgBase): class RPCProtectionMsg(RPCSendMsgBase):
type: Literal[RPCMessageType.PROTECTION_TRIGGER, RPCMessageType.PROTECTION_TRIGGER_GLOBAL]
id: int id: int
pair: str pair: str
base_currency: Optional[str] base_currency: Optional[str]
@ -26,7 +29,13 @@ class RPCProtectionMsg(RPCSendMsgBase):
active: bool active: bool
class RPCWhitelistMsg(RPCSendMsgBase):
type: Literal[RPCMessageType.WHITELIST]
data: List[str]
class RPCBuyMsg(RPCSendMsgBase): class RPCBuyMsg(RPCSendMsgBase):
type: Literal[RPCMessageType.ENTRY, RPCMessageType.ENTRY_FILL]
trade_id: int trade_id: int
buy_tag: Optional[str] buy_tag: Optional[str]
enter_tag: Optional[str] enter_tag: Optional[str]
@ -47,10 +56,12 @@ class RPCBuyMsg(RPCSendMsgBase):
class RPCCancelMsg(RPCBuyMsg): class RPCCancelMsg(RPCBuyMsg):
type: Literal[RPCMessageType.ENTRY_CANCEL]
reason: str reason: str
class RPCSellMsg(RPCBuyMsg): class RPCSellMsg(RPCBuyMsg):
type: Literal[RPCMessageType.EXIT, RPCMessageType.EXIT_FILL]
cumulative_profit: float cumulative_profit: float
gain: str # Literal["profit", "loss"] gain: str # Literal["profit", "loss"]
close_rate: float close_rate: float
@ -64,6 +75,7 @@ class RPCSellMsg(RPCBuyMsg):
class RPCSellCancelMsg(RPCBuyMsg): class RPCSellCancelMsg(RPCBuyMsg):
type: Literal[RPCMessageType.EXIT_CANCEL]
reason: str reason: str
gain: str # Literal["profit", "loss"] gain: str # Literal["profit", "loss"]
profit_amount: float profit_amount: float
@ -76,6 +88,7 @@ class RPCSellCancelMsg(RPCBuyMsg):
RPCSendMsg = Union[ RPCSendMsg = Union[
RPCStatusMsg, RPCStatusMsg,
RPCProtectionMsg, RPCProtectionMsg,
RPCWhitelistMsg,
RPCBuyMsg, RPCBuyMsg,
RPCCancelMsg, RPCCancelMsg,
RPCSellMsg, RPCSellMsg,