跳转至

Alerts 异动告警流

来源同步:/Users/mac/Projects/chatgpt-codex/doc/wss_MonitorBigdata.md

所属接口集:大单监控推送

请求 URL

wss://stock-data-api.aibot6.cn/ws/monitor/alerts/

认证方式

Bearer Token(详见 认证与签名

接口概述

实时推送股票异动告警、大单监控告警,以及用户自定义监控规则告警。监控范围包括系统候选池股票和用户自选股。连接建立后首先推送历史告警,之后持续检测并推送新增告警。

连接参数

参数 类型 必填 说明
token string API Token
user_id int 用户 ID,提供后同时监控用户自选股
stock_code string 精确 6 位股票代码过滤,仅监控该股票
watchlist_only int 1=关闭系统监控,只推用户自选相关通知;0或不传=保持现状(系统候选池 + 自选)
day string 交易日,格式 YYYYMMDD,默认当天
page int 历史回放分页页码,默认 1
page_size int 历史回放分页大小,默认 30
price_speed_threshold float 价格异动阈值覆盖,默认由服务端配置决定
bigorder_turnover_threshold float 大单换手率阈值覆盖,默认 0.0004

示例连接地址

wss://stock-data-api.aibot6.cn/ws/monitor/alerts/?token=your_token&user_id=1&watchlist_only=1&stock_code=600000&price_speed_threshold=0.03

自定义规则分类(price_track 等)

GET/POST /v1/api/monitor/watchlist 一致。其中价格跟踪 price_track 含:

  • price_break_ma_up / price_break_ma_down:股价突破/跌破均线(ma_period
  • price_new_high / price_new_low:股价创新高/新低(lookback_days
  • price_reach_up / price_reach_down:股价涨到/跌到指定价(target_price,最新价 >= / <= 目标价时命中)

其余 movement_watchtechnical_indicator 规则类型见 盘中监控

消息格式

发送消息(客户端→服务端)

更新阈值

{
  "action": "update_thresholds",
  "price_speed_threshold": 0.03,
  "price_speed_mult": 30.0,
  "bigorder_turnover_threshold": 0.0004
}

服务端回复:

{
  "code": 1,
  "message": "thresholds updated",
  "data": {
    "price_speed_threshold": 0.03,
    "price_speed_mult": 30.0,
    "bigorder_turnover_threshold": 0.0004
  }
}

心跳 ping

{
  "action": "ping"
}

服务端回复:

{
  "code": 1,
  "message": "pong"
}

动态订阅

{
  "action": "subscribe",
  "stock_code": "600000",
  "category": "price_track",
  "watchlist_only": 1,
  "page": 1,
  "page_size": 30
}

字段 类型 必填 说明
action string update_thresholds/ping/subscribe
price_speed_threshold float 价格异动阈值
price_speed_mult float 价格速度乘数
bigorder_turnover_threshold float 大单换手率阈值
stock_code string 订阅时指定股票代码过滤(空字符串清除过滤)
category string 订阅时仅查看某一类自定义监控(当前版本仅作前端透传保留)
watchlist_only int 1=仅推用户自选通知;0=系统候选池 + 自选;切换后会重新推送历史首包
page int 分页页码
page_size int 分页大小

接收消息(服务端→客户端)

历史告警首包

{
  "code": 1,
  "message": "success",
  "data": {
    "type": "monitor_alerts_history",
    "day": "20260801",
    "query": {
      "stock_code": "600000",
      "watchlist_only": 1,
      "page": 1,
      "page_size": 30
    },
    "count": 5,
    "items": [
      {
        "notify_type": "价格跟踪",
        "alert_type": "price_break_ma_up",
        "scope": "watchlist",
        "code": "600000",
        "name": "浦发银行",
        "ts": 1722480600,
        "price": 11.30,
        "category": "price_track",
        "rule_type": "price_break_ma_up",
        "rule_name": "股价突破均线",
        "rule_params": {"ma_period": 20},
        "rule_signature": "a1b2c3",
        "watch_rule_id": 12,
        "ma_value": 11.12,
        "is_history": true
      }
    ]
  }
}

实时告警推送

{
  "code": 1,
  "message": "success",
  "data": {
    "type": "monitor_alerts",
    "day": "20260801",
    "items": [
      {
        "notify_type": "异动盯盘",
        "alert_type": "near_limit_up",
        "scope": "watchlist",
        "code": "600000",
        "name": "浦发银行",
        "ts": 1722480600,
        "price": 11.30,
        "category": "movement_watch",
        "rule_type": "near_limit_up",
        "rule_name": "逼近涨停",
        "rule_params": {"distance_pct": 0.5},
        "rule_signature": "d4e5f6",
        "watch_rule_id": 22,
        "limit_price": 11.35,
        "distance_pct": 0.44,
        "threshold_pct": 0.5
      },
      {
        "notify_type": "大单监控",
        "alert_type": "bigorder_buy",
        "scope": "system",
        "code": "600000",
        "name": "浦发银行",
        "ts": 1722480612,
        "deal_time": "2026-08-01 10:30:12",
        "deal_price": 11.26,
        "deal_vol": 5000,
        "turnover_ratio": 0.0005,
        "current_price": 11.30
      }
    ]
  }
}

字段 类型 说明
data.type string monitor_alerts_history(历史)或 monitor_alerts(实时)
data.day string 交易日
data.query object 分页查询信息(仅历史包含)
data.count int 告警总数(仅历史包含)
data.items array 告警列表
data.items[].notify_type string 通知类型:股票异动大单监控
data.items[].alert_type string 具体告警类型;系统告警为 price_up/price_down/bigorder_buy/bigorder_sell,用户自定义告警为对应规则类型
data.items[].scope string 监控范围:systemwatchlist
data.items[].code string 股票代码
data.items[].name string 股票名称
data.items[].ts int 告警时间(Unix 时间戳,秒)
data.items[].is_history bool 是否历史告警(仅历史包含)
data.items[].category string 自定义规则分类:price_track/movement_watch/technical_indicator
data.items[].rule_type string 自定义规则类型
data.items[].rule_name string 自定义规则名称
data.items[].rule_params object 自定义规则参数
data.items[].rule_signature string 自定义规则签名
data.items[].watch_rule_id int 自定义规则 ID

股票异动告警额外字段: | 字段 | 类型 | 说明 | |------|------|------| | price | float | 当前价格 | | price_speed_ratio | float | 价格速度比率 | | score | float | 异动评分 = price_speed_ratio × price_speed_mult | | turnover_ratio | float | 最近 1 分钟换手率 |

大单监控告警额外字段: | 字段 | 类型 | 说明 | |------|------|------| | deal_time | string | 成交时间 | | deal_price | float | 成交价格 | | deal_vol | int | 成交量(股) | | turnover_ratio | float | 换手率 | | current_price | float | 当前价格 |

心跳机制

支持客户端发送 {"action": "ping"} 消息,服务端回复 {"code": 1, "message": "pong"}。建议客户端以 30 秒间隔发送心跳以保持连接活跃。

接口说明

  • 检测频率:3 秒一次
  • 历史重建:连接建立后首包推送从 Redis 去重标记重建的今日历史告警,分页返回
  • 监控范围:系统候选池(strategy:auction:index:{day})+ 用户自选股(UserStockWatchlist);watchlist_only=1 时仅监控并推送用户自选自定义规则通知
  • 价格异动:当 price_speed_ratio × mult 超过阈值时触发,且仅在方向反转时通知(同方向不重复)
  • 大单监控:检测换手率超过阈值的大单成交记录,已通知的不再重复推送
  • 用户自定义规则:对用户自选股按规则执行价格跟踪、异动盯盘、技术指标监控;同一用户同一股票同一规则仅在状态切换到命中时推送
  • 股价涨到/跌到price_reach_up 在最新价 >= target_price 时触发;price_reach_down 在最新价 <= target_price 时触发
  • 阈值动态调整:支持通过 update_thresholds 消息实时调整告警阈值
  • 仅自选模式:支持连接参数或 subscribe.watchlist_only 关闭系统监控,历史首包与实时推送均不再包含系统候选池告警
  • 股票过滤:可通过 stock_code 参数仅监控单只股票
  • 数据源:Redis HASH/LIST + strategy_signal_snapshot + 去重标记