Skip to content

新大盤分析 SSE 訂閱

連線位址:https://stream.valuescan.ai/stream/market/analysis/subscribe


一、概述

大盤分析是 ValueAgent 透過多維度資料,對 BTC/ETH/SOL 的行情進行綜合分析的輸出結果。本介面為新列舉版 SSE 訂閱,每 5 分鐘生成新的分析結果後進行推送。signal 使用國際通用交易術語(LONG / SHORT / SIDEWAYS),並附帶日內訊號分佈匯總(h24Summary)與訊號驗證結果(verdict)。

與舊版 /stream/market/subscribe 的區別:

對比項原有大盤分析訂閱新大盤分析 SSE 訂閱(本介面)
訂閱位址/stream/market/subscribe/stream/market/analysis/subscribe
事件名marketmarket-analysis
content大盤分析純文字需二次解析的結構化 JSON 字串
signal不單獨返回LONG / SHORT / SIDEWAYS
擴展欄位無結構化擴展欄位返回 h24SummaryverdictverdictDesc 等欄位
更新方式行情變化時推送每 5 分鐘生成新分析結果後推送

signal 表示當前 5 分鐘分析週期得出的方向。每個週期都直接返回 LONGSHORTSIDEWAYS;若方向與上一週期相同,仍返回相同的基礎列舉值,不使用 LONG_CONTINUESHORT_CONTINUESIDEWAYS_CONTINUE


二、訂閱位址

GET https://stream.valuescan.ai/stream/market/analysis/subscribe

鑑權參數(Query String):

參數類型必需說明
apiKeystringValueScan Access Key
signstringHMAC-SHA256 簽名
timestamplong毫秒級 Unix 時間戳
noncestring隨機字串(防重放)

簽名演算法

sign = HMAC-SHA256(SK, timestamp毫秒 + nonce)

點數消耗

  • 消耗點數:每 30 分鐘 50 點數

三、SSE 事件格式

連線成功

event: connected
data: subscribed

心跳(維持連線)

: heartbeat

event: heartbeat
data: ping

服務端每 20 秒發送一次心跳。

大盤分析推送

event: market-analysis
data: {"ts":1775604300144,"uniqueId":"大盘分析_20260408103000","content":"{\"vsTokenId\":\"1\",\"symbol\":\"BTC\",\"signal\":\"SIDEWAYS\",\"price\":\"80573.75\",\"klineDiff\":\"-0.00298373\",\"supports\":[\"80434.275\",\"79980.475\"],\"resistances\":[\"80776.78\",\"81208.86\"],\"analysis\":\"📊 BTC 日內主力资金趋势分析(ValueScan)...\",\"analysisTime\":1778837430000,\"verdict\":0,\"verdictDesc\":\"待驗證\",\"h24Summary\":{\"buyCount\":12,\"sellCount\":5,\"holdCount\":7,\"total\":24,\"buyRatio\":50.0,\"sellRatio\":20.8,\"holdRatio\":29.2,\"conclusion\":\"LONG_BIASED_SIDEWAYS\"}}"}

market-analysis 事件 payload 欄位

欄位類型說明
tslong推送時間(毫秒時間戳)
uniqueIdstring唯一標識(用於去重)
contentstring大盤分析詳情 JSON 字串,需二次解析

content 解析後的欄位結構

欄位類型說明
vsTokenIdstring代幣 ID
symbolstring代幣符號(如 BTC、ETH)
iconstring代幣圖標 URL
pricestring分析時價格
signalstring當前 5 分鐘分析週期的 AI 綜合訊號:LONG(利多)/ SHORT(利空)/ SIDEWAYS(震盪)
klineDiffstringK 線漲跌幅(小數)
supportsarray<string>支撐位價格列表
resistancesarray<string>壓力位價格列表
analysisstringAI 分析結論(請求語言版本)
analysisTimelong分析時間(毫秒時間戳)
verdictinteger訊號驗證結果:0=待驗證,1=相符,2=不符合
verdictDescstring訊號驗證結果描述
h24Summaryobject日內訊號分佈匯總
h24Summary.buyCountinteger利多次數
h24Summary.sellCountinteger利空次數
h24Summary.holdCountinteger震盪次數
h24Summary.totalinteger總計次數
h24Summary.buyRationumber利多佔比(%)
h24Summary.sellRationumber利空佔比(%)
h24Summary.holdRationumber震盪佔比(%)
h24Summary.conclusionstring日內綜合結論:LONG(利多行情)/ SHORT(利空行情)/ SIDEWAYS(震盪)/ LONG_BIASED_SIDEWAYS(震盪偏多)/ SHORT_BIASED_SIDEWAYS(震盪偏空)

四、新舊列舉對照

舊值(舊 SSE)新值(本介面)含義
BUYLONG利多
SELLSHORT利空
HOLDSIDEWAYS震盪
BULLISHLONG利多行情
BEARISHSHORT利空行情
OSCILLATESIDEWAYS震盪
OSCILLATE_BULLISHLONG_BIASED_SIDEWAYS震盪偏多
OSCILLATE_BEARISHSHORT_BIASED_SIDEWAYS震盪偏空

五、訂閱範例

Python

python
import hashlib
import hmac
import json
import time
import uuid
import urllib.request
from urllib.parse import urlencode

AK = "your-access-key"
SK = "your-secret-key"

ts = int(time.time() * 1000)
nonce = uuid.uuid4().hex
sign = hmac.new(
    SK.encode(),
    (str(ts) + nonce).encode(),
    hashlib.sha256,
).hexdigest()

params = urlencode({
    "apiKey": AK,
    "sign": sign,
    "timestamp": ts,
    "nonce": nonce,
})

url = f"https://stream.valuescan.ai/stream/market/analysis/subscribe?{params}"
req = urllib.request.Request(url, headers={"Accept": "text/event-stream"})

with urllib.request.urlopen(req, timeout=300) as resp:
    event_name = ""
    data_str = ""
    for raw in resp:
        line = raw.decode("utf-8").rstrip("\r\n")

        if line.startswith(":"):
            print("♥ 心跳")
            continue

        if line == "":
            if data_str:
                handle_event(event_name, data_str)
            event_name = ""
            data_str = ""
        elif line.startswith("event:"):
            event_name = line[6:].strip()
        elif line.startswith("data:"):
            data_str = line[5:].strip()


def handle_event(event_name: str, data_str: str) -> None:
    if event_name == "connected":
        print(f"[連線] {data_str}")
    elif event_name == "market-analysis":
        payload = json.loads(data_str)
        content = json.loads(payload["content"])
        print(f"[大盤分析] {content['symbol']} signal={content['signal']} "
              f"price={content['price']} conclusion={content['h24Summary']['conclusion']}")

cURL(快速驗證)

bash
python3 -c "
import hashlib, hmac, time, uuid, urllib.parse
SK='your-secret-key'
ts=int(time.time()*1000)
nonce=uuid.uuid4().hex
sign=hmac.new(SK.encode(), (str(ts)+nonce).encode(), hashlib.sha256).hexdigest()
params=urllib.parse.urlencode({'apiKey':'your-access-key','sign':sign,'timestamp':ts,'nonce':nonce})
print(f\"curl -N 'https://stream.valuescan.ai/stream/market/analysis/subscribe?{params}' -H 'Accept: text/event-stream'\")
'"

六、斷線重連

與舊版大盤訂閱一致,建議實現指數退避重連:

python
def listen_with_retry(url: str, max_retries: int = 10) -> None:
    retries = 0
    while retries <= max_retries:
        try:
            req = urllib.request.Request(url, headers={"Accept": "text/event-stream"})
            with urllib.request.urlopen(req, timeout=300) as resp:
                _read_sse(resp)
                break
        except KeyboardInterrupt:
            print("用戶中斷,退出。")
            break
        except Exception as e:
            retries += 1
            wait = min(2 ** retries, 60)
            print(f"連線斷開({e}),{wait}s 後第 {retries} 次重連...")
            time.sleep(wait)
    else:
        print("重試次數耗盡,退出。")

七、錯誤碼

建連階段的鑑權、參數、額度類業務錯誤會以 HTTP 200 返回業務 JSON,回應體中的 code 表示實際錯誤原因。

範例:

json
{
    "code": 20021,
    "message": "Signature verification failed",
    "data": null,
    "requestId": "a7d7ce3053e140dca91d93df173648f8"
}

常見錯誤碼:

code說明
20001API Key 缺失
20002API Key 無效、已禁用、已過期或未審核通過
20010時間戳缺失
20011時間戳格式錯誤
20012時間戳過期
20020簽名缺失
20021簽名驗證失敗
40001必填參數缺失
40002參數格式或取值不合法
60001觸發限流
70001OpenApi 點數不足

連線建立後,如果點數不足,會收到 credit-exhausted 事件,隨後連線關閉:

event: credit-exhausted
data: {"message":"額度已耗盡,請充值"}