Skip to content

Notification API 参考

模块路径: FQBase.Core.notification源码: [notification.py](file:///Users/A.D.189/FQuant/FQuant.Server/FQBase/FQBase/Core/notification.py)


一、NotificationHandler 基类

python
class NotificationHandler:
    """通知处理器基类"""
    def send(self, content: str, **kwargs) -> bool:
        """发送通知"""
        raise NotImplementedError

二、WecomHandler

企业微信通知处理器。

WecomHandler.__init__(channel: str = 'DEFAULT')

参数类型默认值说明
channelstr'DEFAULT'渠道标识

WecomHandler.send(content: str, **kwargs) -> bool

发送企业微信消息。

返回值: 是否发送成功


三、ServerChanHandler

Server 酱通知处理器。

ServerChanHandler.__init__(serverchan_key: str = None)

参数类型默认值说明
serverchan_keystrNoneServer 酱 Key

ServerChanHandler.send(content: str, **kwargs) -> bool

发送 Server 酱消息。

ServerChanHandler.post(title: str, body: str = '')

发送 POST 格式消息。


四、PushBearHandler

PushBear 通知处理器。

PushBearHandler.__init__(send_key: str = None)

参数类型默认值说明
send_keystrNonePushBear Key

PushBearHandler.send(content: str, **kwargs) -> bool

发送 PushBear 消息。

PushBearHandler.post(title: str, body: str = '')

发送 POST 格式消息。


五、NotificationManager

统一通知管理器。

NotificationManager.register(name: str, handler: NotificationHandler)

注册通知处理器。

参数类型说明
namestr处理器名称
handlerNotificationHandler处理器实例

NotificationManager.send(content: str, channel: str = 'DEFAULT') -> bool

发送通知。

参数类型默认值说明
contentstr-消息内容
channelstr'DEFAULT'渠道标识

渠道列表: DEFAULT, BOND, VOL_PRICE, HIGH, LIMIT, INS, SYSTEM

返回值: 是否发送成功

NotificationManager.send_all(content: str) -> Dict[str, bool]

向所有已注册渠道发送通知。

参数类型说明
contentstr消息内容

返回值: 各渠道发送结果

NotificationManager.get_handler(name: str) -> Optional[NotificationHandler]

获取指定名称的处理器。

参数类型说明
namestr处理器名称

返回值: 处理器实例或 None


六、便捷函数

sendWechat(content: str, channel: str = 'DEFAULT') -> bool

发送企业微信消息(兼容旧接口)。

参数类型默认值说明
contentstr-消息内容
channelstr'DEFAULT'渠道标识

sendMessage2ServerChan(title: str, body: str)

发送 Server 酱消息。

sendMessagetoAll(title: str, body: str)

发送 PushBear 消息。


七、兼容类

ServerChan

Server 酱接口(兼容旧接口)。

python
class ServerChan:
    def __init__(self, serverchan_key: str = None)
    def send(self, title: str, body: str = '')
    def post(self, title: str, body: str = '')

PushBear

PushBear 接口(兼容旧接口)。

python
class PushBear:
    def __init__(self, send_key: str = None)
    def send(self, title: str, body: str = '')
    def post(self, title: str, body: str = '')

八、环境变量

企业微信

变量名说明
WECOM_CORPID企业 ID
WECOM_SECRET_DEFAULT默认渠道 Secret
WECOM_AGENTID_DEFAULT默认渠道 AgentID
WECOM_SECRET_BOND债券渠道 Secret
WECOM_AGENTID_BOND债券渠道 AgentID

Server 酱

变量名说明
SERVERCHAN_KEYServer 酱 Key

PushBear

变量名说明
PUSHBEAR_KEYPushBear Key

九、相关文档

文档说明
framework.md框架概述
architecture.md架构设计
design.md设计决策
usage.md使用指南
best-practices.md最佳实践
NotificationTemplate API通知模板 API