2022-09-20 17:51:42 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from typing import Optional, TypedDict, Union
|
|
|
|
|
|
|
|
from freqtrade.enums import RPCMessageType
|
|
|
|
|
|
|
|
|
|
|
|
class RPCSendMsgBase(TypedDict):
|
|
|
|
type: RPCMessageType
|
|
|
|
|
|
|
|
|
|
|
|
class RPCStatusMsg(RPCSendMsgBase):
|
|
|
|
"""Used for Status, Startup and Warning messages"""
|
|
|
|
status: str
|
|
|
|
|
|
|
|
|
|
|
|
class RPCProtectionMsg(RPCSendMsgBase):
|
|
|
|
id: int
|
|
|
|
pair: str
|
|
|
|
base_currency: Optional[str]
|
|
|
|
lock_time: str
|
|
|
|
lock_timestamp: int
|
|
|
|
lock_end_time: str
|
|
|
|
lock_end_timestamp: int
|
|
|
|
reason: str
|
|
|
|
side: str
|
|
|
|
active: bool
|
|
|
|
|
|
|
|
|
|
|
|
class RPCBuyMsg(RPCSendMsgBase):
|
2023-03-06 18:23:05 +00:00
|
|
|
trade_id: int
|
|
|
|
buy_tag: Optional[str]
|
|
|
|
enter_tag: Optional[str]
|
2022-09-20 17:51:42 +00:00
|
|
|
exchange: str
|
|
|
|
pair: str
|
2023-03-06 18:23:05 +00:00
|
|
|
leverage: Optional[float]
|
2022-09-20 17:51:42 +00:00
|
|
|
direction: str
|
|
|
|
limit: float
|
|
|
|
open_rate: float
|
|
|
|
order_type: Optional[str] # TODO: why optional??
|
|
|
|
stake_amount: float
|
|
|
|
stake_currency: str
|
|
|
|
fiat_currency: Optional[str]
|
|
|
|
amount: float
|
|
|
|
open_date: datetime
|
2023-03-06 18:23:05 +00:00
|
|
|
current_rate: Optional[float]
|
2022-09-20 17:51:42 +00:00
|
|
|
sub_trade: bool
|
|
|
|
|
|
|
|
|
|
|
|
class RPCCancelMsg(RPCBuyMsg):
|
|
|
|
reason: str
|
|
|
|
|
|
|
|
|
|
|
|
class RPCSellMsg(RPCBuyMsg):
|
|
|
|
cumulative_profit: float
|
|
|
|
gain: str # Literal["profit", "loss"]
|
|
|
|
close_rate: float
|
|
|
|
profit_amount: float
|
|
|
|
profit_ratio: float
|
2023-03-06 18:23:05 +00:00
|
|
|
sell_reason: Optional[str]
|
|
|
|
exit_reason: Optional[str]
|
2022-09-20 17:51:42 +00:00
|
|
|
close_date: datetime
|
2023-03-06 18:23:05 +00:00
|
|
|
# current_rate: Optional[float]
|
|
|
|
order_rate: Optional[float]
|
2022-09-20 17:51:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RPCSellCancelMsg(RPCBuyMsg):
|
|
|
|
reason: str
|
|
|
|
gain: str # Literal["profit", "loss"]
|
|
|
|
profit_amount: float
|
|
|
|
profit_ratio: float
|
2023-03-06 18:23:05 +00:00
|
|
|
sell_reason: Optional[str]
|
|
|
|
exit_reason: Optional[str]
|
2022-09-20 17:51:42 +00:00
|
|
|
close_date: datetime
|
|
|
|
|
|
|
|
|
|
|
|
RPCSendMsg = Union[
|
|
|
|
RPCStatusMsg,
|
|
|
|
RPCProtectionMsg,
|
|
|
|
RPCBuyMsg,
|
|
|
|
RPCCancelMsg,
|
|
|
|
RPCSellMsg,
|
|
|
|
RPCSellCancelMsg
|
|
|
|
]
|