From ad58bac810bf5cfd2fbcd9556a192f0b1dc0d429 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 24 Mar 2023 20:54:28 +0100 Subject: [PATCH] Type WS messagetypes --- freqtrade/data/dataprovider.py | 6 +++--- freqtrade/rpc/rpc_types.py | 25 +++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/freqtrade/data/dataprovider.py b/freqtrade/data/dataprovider.py index 3991432a4..d05ee5db7 100644 --- a/freqtrade/data/dataprovider.py +++ b/freqtrade/data/dataprovider.py @@ -21,6 +21,7 @@ from freqtrade.exchange import Exchange, timeframe_to_seconds from freqtrade.exchange.types import OrderBook from freqtrade.misc import append_candles_to_dataframe from freqtrade.rpc import RPCManager +from freqtrade.rpc.rpc_types import RPCAnalyzedDFMsg from freqtrade.util import PeriodicCache @@ -118,8 +119,7 @@ class DataProvider: :param new_candle: This is a new candle """ if self.__rpc: - self.__rpc.send_msg( - { + msg: RPCAnalyzedDFMsg = { 'type': RPCMessageType.ANALYZED_DF, 'data': { 'key': pair_key, @@ -127,7 +127,7 @@ class DataProvider: 'la': datetime.now(timezone.utc) } } - ) + self.__rpc.send_msg(msg) if new_candle: self.__rpc.send_msg({ 'type': RPCMessageType.NEW_CANDLE, diff --git a/freqtrade/rpc/rpc_types.py b/freqtrade/rpc/rpc_types.py index 5a3549aa7..a290ee78c 100644 --- a/freqtrade/rpc/rpc_types.py +++ b/freqtrade/rpc/rpc_types.py @@ -1,6 +1,7 @@ from datetime import datetime -from typing import List, Literal, Optional, TypedDict, Union +from typing import Any, List, Literal, Optional, TypedDict, Union +from freqtrade.constants import PairWithTimeframe from freqtrade.enums import RPCMessageType @@ -95,6 +96,24 @@ class RPCSellCancelMsg(__RPCBuyMsgBase): close_date: datetime +class __AnalyzedDFData(TypedDict): + key: PairWithTimeframe + df: Any + la: datetime + + +class RPCAnalyzedDFMsg(RPCSendMsgBase): + """New Analyzed dataframe message""" + type: Literal[RPCMessageType.ANALYZED_DF] + data: __AnalyzedDFData + + +class RPCNewCandleMsg(RPCSendMsgBase): + """New candle ping message, issued once per new candle/pair""" + type: Literal[RPCMessageType.NEW_CANDLE] + data: PairWithTimeframe + + RPCSendMsg = Union[ RPCStatusMsg, RPCStrategyMsg, @@ -103,5 +122,7 @@ RPCSendMsg = Union[ RPCBuyMsg, RPCCancelMsg, RPCSellMsg, - RPCSellCancelMsg + RPCSellCancelMsg, + RPCAnalyzedDFMsg, + RPCNewCandleMsg ]