2022-09-07 21:08:01 +00:00
|
|
|
from datetime import datetime
|
2024-10-04 05:06:27 +00:00
|
|
|
from typing import Any, Optional, TypedDict
|
2022-09-07 21:08:01 +00:00
|
|
|
|
|
|
|
from pandas import DataFrame
|
2023-08-18 08:55:05 +00:00
|
|
|
from pydantic import BaseModel, ConfigDict
|
2022-09-07 21:08:01 +00:00
|
|
|
|
|
|
|
from freqtrade.constants import PairWithTimeframe
|
2023-09-10 16:10:38 +00:00
|
|
|
from freqtrade.enums import RPCMessageType, RPCRequestType
|
2022-09-07 21:08:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BaseArbitraryModel(BaseModel):
|
2023-07-18 04:43:36 +00:00
|
|
|
model_config = ConfigDict(arbitrary_types_allowed=True)
|
2022-09-07 21:08:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WSRequestSchema(BaseArbitraryModel):
|
|
|
|
type: RPCRequestType
|
|
|
|
data: Optional[Any] = None
|
|
|
|
|
|
|
|
|
2022-10-25 17:36:40 +00:00
|
|
|
class WSMessageSchemaType(TypedDict):
|
|
|
|
# Type for typing to avoid doing pydantic typechecks.
|
|
|
|
type: RPCMessageType
|
2024-10-04 05:06:27 +00:00
|
|
|
data: Optional[dict[str, Any]]
|
2022-10-25 17:36:40 +00:00
|
|
|
|
|
|
|
|
2022-09-07 21:08:01 +00:00
|
|
|
class WSMessageSchema(BaseArbitraryModel):
|
|
|
|
type: RPCMessageType
|
|
|
|
data: Optional[Any] = None
|
2024-05-12 14:51:11 +00:00
|
|
|
model_config = ConfigDict(extra="allow")
|
2022-09-07 21:08:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------ REQUEST SCHEMAS ----------------------------
|
|
|
|
|
|
|
|
|
|
|
|
class WSSubscribeRequest(WSRequestSchema):
|
|
|
|
type: RPCRequestType = RPCRequestType.SUBSCRIBE
|
2024-10-04 05:06:27 +00:00
|
|
|
data: list[RPCMessageType]
|
2022-09-07 21:08:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WSWhitelistRequest(WSRequestSchema):
|
|
|
|
type: RPCRequestType = RPCRequestType.WHITELIST
|
|
|
|
data: None = None
|
|
|
|
|
|
|
|
|
|
|
|
class WSAnalyzedDFRequest(WSRequestSchema):
|
|
|
|
type: RPCRequestType = RPCRequestType.ANALYZED_DF
|
2024-10-04 05:06:27 +00:00
|
|
|
data: dict[str, Any] = {"limit": 1500, "pair": None}
|
2022-09-07 21:08:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------ MESSAGE SCHEMAS ----------------------------
|
|
|
|
|
2024-05-12 14:51:11 +00:00
|
|
|
|
2022-09-07 21:08:01 +00:00
|
|
|
class WSWhitelistMessage(WSMessageSchema):
|
|
|
|
type: RPCMessageType = RPCMessageType.WHITELIST
|
2024-10-04 05:06:27 +00:00
|
|
|
data: list[str]
|
2022-09-07 21:08:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WSAnalyzedDFMessage(WSMessageSchema):
|
|
|
|
class AnalyzedDFData(BaseArbitraryModel):
|
|
|
|
key: PairWithTimeframe
|
|
|
|
df: DataFrame
|
|
|
|
la: datetime
|
|
|
|
|
|
|
|
type: RPCMessageType = RPCMessageType.ANALYZED_DF
|
|
|
|
data: AnalyzedDFData
|
|
|
|
|
2023-06-24 18:20:54 +00:00
|
|
|
|
|
|
|
class WSErrorMessage(WSMessageSchema):
|
|
|
|
type: RPCMessageType = RPCMessageType.EXCEPTION
|
|
|
|
data: str
|
|
|
|
|
2024-05-12 14:51:11 +00:00
|
|
|
|
2022-09-07 21:08:01 +00:00
|
|
|
# --------------------------------------------------------------------------
|