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:
| Comparison | Legacy market analysis subscription | New market analysis SSE subscription (this API) |
|---|---|---|
| Subscription URL | /stream/market/subscribe | /stream/market/analysis/subscribe |
| Event name | market | market-analysis |
content | Plain-text market analysis | Structured JSON string that requires a second parse |
signal | Not returned separately | LONG / SHORT / SIDEWAYS |
| Extended fields | No structured extended fields | Returns h24Summary, verdict, verdictDesc, and other fields |
| Update mode | Pushed when market conditions change | Pushed after a new analysis result is generated every 5 minutes |
signalrepresents the direction determined in the current 5-minute analysis cycle. Each cycle directly returnsLONG,SHORT, orSIDEWAYS. If the direction is the same as the previous cycle, the same base enum value is still returned;LONG_CONTINUE,SHORT_CONTINUE, andSIDEWAYS_CONTINUEare not used.
2. Subscription URL
GET https://stream.valuescan.ai/stream/market/analysis/subscribeAuthentication parameters (query string):
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | ValueScan Access Key |
sign | string | Yes | HMAC-SHA256 signature |
timestamp | long | Yes | Unix timestamp in milliseconds |
nonce | string | Yes | Random string (replay protection) |
Signing algorithm:
sign = HMAC-SHA256(SK, timestampMs + nonce)Credits
- Cost:
50credits every 30 minutes
3. SSE event format
Connected
event: connected
data: subscribedHeartbeat (keep-alive)
: heartbeat
event: heartbeat
data: pingThe 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:
| Field | Type | Description |
|---|---|---|
ts | long | Push time (millisecond timestamp) |
uniqueId | string | Unique id (for deduplication) |
content | string | Market analysis detail JSON string; parse again |
Fields after parsing content:
| Field | Type | Description |
|---|---|---|
vsTokenId | string | Token ID |
symbol | string | Token symbol (such as BTC, ETH) |
icon | string | Token icon URL |
price | string | Price at the time of analysis |
signal | string | AI composite signal for the current 5-minute analysis cycle: LONG (bullish) / SHORT (bearish) / SIDEWAYS (sideways) |
klineDiff | string | K-line change rate (decimal) |
supports | array<string> | List of support prices |
resistances | array<string> | List of resistance prices |
analysis | string | AI analysis conclusion in the requested language |
analysisTime | long | Analysis time (millisecond timestamp) |
verdict | integer | Signal validation: 0=pending, 1=match, 2=mismatch |
verdictDesc | string | Signal validation description |
h24Summary | object | Intraday signal distribution summary |
h24Summary.buyCount | integer | Bullish count |
h24Summary.sellCount | integer | Bearish count |
h24Summary.holdCount | integer | Sideways count |
h24Summary.total | integer | Total count |
h24Summary.buyRatio | number | Bullish ratio (%) |
h24Summary.sellRatio | number | Bearish ratio (%) |
h24Summary.holdRatio | number | Sideways ratio (%) |
h24Summary.conclusion | string | Intraday 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 |
|---|---|---|
| BUY | LONG | Bullish |
| SELL | SHORT | Bearish |
| HOLD | SIDEWAYS | Sideways |
| BULLISH | LONG | Bullish market |
| BEARISH | SHORT | Bearish market |
| OSCILLATE | SIDEWAYS | Sideways |
| OSCILLATE_BULLISH | LONG_BIASED_SIDEWAYS | Sideways bullish |
| OSCILLATE_BEARISH | SHORT_BIASED_SIDEWAYS | Sideways bearish |
5. Subscription examples
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)
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:
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:
{
"code": 20021,
"message": "Signature verification failed",
"data": null,
"requestId": "a7d7ce3053e140dca91d93df173648f8"
}Common error codes:
| code | Description |
|---|---|
20001 | API Key missing |
20002 | API Key invalid, disabled, expired, or not approved |
20010 | Timestamp missing |
20011 | Invalid timestamp format |
20012 | Timestamp expired |
20020 | Signature missing |
20021 | Signature verification failed |
40001 | Required parameter missing |
40002 | Invalid parameter format or value |
60001 | Rate limit exceeded |
70001 | Insufficient 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":"额度已耗尽,请充值"}