Skip to content

New market analysis SSE subscription

Connection URL: https://stream.valuescan.ai/stream/market/analysis/subscribe


1. Overview

Market-wide analysis is ValueAgent's synthesized view of BTC/ETH/SOL markets using multi-dimensional data. This API is the new-enum SSE subscription. A new analysis result is generated every 5 minutes and then pushed. The signal field uses international trading terms (LONG / SHORT / SIDEWAYS), and includes intraday signal distribution (h24Summary) and signal validation (verdict).

Differences from legacy /stream/market/subscribe:

ComparisonLegacy market analysis subscriptionNew market analysis SSE subscription (this API)
Subscription URL/stream/market/subscribe/stream/market/analysis/subscribe
Event namemarketmarket-analysis
contentPlain-text market analysisStructured JSON string that requires a second parse
signalNot returned separatelyLONG / SHORT / SIDEWAYS
Extended fieldsNo structured extended fieldsReturns h24Summary, verdict, verdictDesc, and other fields
Update modePushed when market conditions changePushed after a new analysis result is generated every 5 minutes

signal represents the direction determined in the current 5-minute analysis cycle. Each cycle directly returns LONG, SHORT, or SIDEWAYS. If the direction is the same as the previous cycle, the same base enum value is still returned; LONG_CONTINUE, SHORT_CONTINUE, and SIDEWAYS_CONTINUE are not used.


2. Subscription URL

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

Authentication parameters (query string):

ParameterTypeRequiredDescription
apiKeystringYesValueScan Access Key
signstringYesHMAC-SHA256 signature
timestamplongYesUnix timestamp in milliseconds
noncestringYesRandom string (replay protection)

Signing algorithm:

sign = HMAC-SHA256(SK, timestampMs + nonce)

Credits

  • Cost: 50 credits every 30 minutes

3. SSE event format

Connected

event: connected
data: subscribed

Heartbeat (keep-alive)

: heartbeat

event: heartbeat
data: ping

The server sends a heartbeat every 20 seconds.

Market analysis push

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 event payload fields:

FieldTypeDescription
tslongPush time (millisecond timestamp)
uniqueIdstringUnique id (for deduplication)
contentstringMarket analysis detail JSON string; parse again

Fields after parsing content:

FieldTypeDescription
vsTokenIdstringToken ID
symbolstringToken symbol (such as BTC, ETH)
iconstringToken icon URL
pricestringPrice at the time of analysis
signalstringAI composite signal for the current 5-minute analysis cycle: LONG (bullish) / SHORT (bearish) / SIDEWAYS (sideways)
klineDiffstringK-line change rate (decimal)
supportsarray<string>List of support prices
resistancesarray<string>List of resistance prices
analysisstringAI analysis conclusion in the requested language
analysisTimelongAnalysis time (millisecond timestamp)
verdictintegerSignal validation: 0=pending, 1=match, 2=mismatch
verdictDescstringSignal validation description
h24SummaryobjectIntraday signal distribution summary
h24Summary.buyCountintegerBullish count
h24Summary.sellCountintegerBearish count
h24Summary.holdCountintegerSideways count
h24Summary.totalintegerTotal count
h24Summary.buyRationumberBullish ratio (%)
h24Summary.sellRationumberBearish ratio (%)
h24Summary.holdRationumberSideways ratio (%)
h24Summary.conclusionstringIntraday composite conclusion: LONG (bullish market) / SHORT (bearish market) / SIDEWAYS (sideways) / LONG_BIASED_SIDEWAYS (sideways bullish) / SHORT_BIASED_SIDEWAYS (sideways bearish)

4. Legacy vs new enum mapping

Legacy value (old SSE)New value (this API)Meaning
BUYLONGBullish
SELLSHORTBearish
HOLDSIDEWAYSSideways
BULLISHLONGBullish market
BEARISHSHORTBearish market
OSCILLATESIDEWAYSSideways
OSCILLATE_BULLISHLONG_BIASED_SIDEWAYSSideways bullish
OSCILLATE_BEARISHSHORT_BIASED_SIDEWAYSSideways bearish

5. Subscription examples

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("♥ heartbeat")
            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"[connected] {data_str}")
    elif event_name == "market-analysis":
        payload = json.loads(data_str)
        content = json.loads(payload["content"])
        print(f"[market analysis] {content['symbol']} signal={content['signal']} "
              f"price={content['price']} conclusion={content['h24Summary']['conclusion']}")

cURL (quick check)

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'\")
'"

6. Reconnection

Same as the legacy market subscription: use exponential backoff:

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("Interrupted by user, exiting.")
            break
        except Exception as e:
            retries += 1
            wait = min(2 ** retries, 60)
            print(f"Disconnected ({e}), retrying in {wait}s (attempt {retries})...")
            time.sleep(wait)
    else:
        print("Max retries reached, exiting.")

7. Error codes

During connection setup, auth, parameter, and quota errors may return HTTP 200 with a business JSON body. The code field indicates the actual error.

Example:

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

Common error codes:

codeDescription
20001API Key missing
20002API Key invalid, disabled, expired, or not approved
20010Timestamp missing
20011Invalid timestamp format
20012Timestamp expired
20020Signature missing
20021Signature verification failed
40001Required parameter missing
40002Invalid parameter format or value
60001Rate limit exceeded
70001Insufficient OpenApi credits

After the connection is established, if credits are insufficient you receive a credit-exhausted event and the connection closes:

event: credit-exhausted
data: {"message":"额度已耗尽,请充值"}