aiContext() trả structured JSON, toAIPrompt() trả plain-text cho Claude/GPT/Gemini
Từ v1.4, vnstock-js cung cấp 2 helper để build bối cảnh phân tích kỹ thuật pre-computed cho AI/LLM reasoning — không phải dump raw OHLCV.
import vnstock from 'vnstock-js';
stock.aiContext(symbol, options?)Trả về structured JSON gồm:
const ctx = await vnstock.stock.aiContext('VCB');
console.log(ctx.trend);
// { direction: "bullish", strength: 0.72, rationale: "EMA20 > EMA50 > EMA200, slope EMA20 dương 5 phiên" }
console.log(ctx.indicators.rsi14); // 62.3
console.log(ctx.indicators.macd); // { line, signal, histogram, crossover }
console.log(ctx.levels.support); // [56.5, 54.2, 52.0]
console.log(ctx.levels.resistance); // [60.0, 62.5, 64.0]
console.log(ctx.volume.signal); // "above_average"
console.log(ctx.performance); // { change1d: 0.0017, change30d: 0.058, ... }
await vnstock.stock.aiContext('VCB', { lookback: 200 }); // default 200 phiên
stock.toAIPrompt(symbol, options?)Trả về plain-text format optimize cho LLM context window. Dùng khi user export sang GPT/Gemini bên ngoài.
const text = await vnstock.stock.toAIPrompt('VCB', { lang: 'vi' });
console.log(text);
Output:
=== VCB — 2026-05-22 ===
Trend: bullish (strength 72%) — EMA20 > EMA50 > EMA200, slope EMA20 dương 5 phiên
RSI(14): 62.3
MACD: line 0.420, signal 0.310, histogram 0.110, crossover: bullish
SMA: 20=58.40, 50=56.10, 200=52.80
EMA: 20=58.90, 50=56.50, 200=52.60
Bollinger %B: 0.62 (upper=61.20, lower=55.60)
ATR(14): 1.340
Volume: 5,550,000 (avg 4,120,000, z-score 1.85, above_average)
Support: 56.50 / 54.20 / 52.00
Resistance: 60.00 / 62.50 / 64.00
Change: 1d +0.17% · 7d +2.34% · 30d +5.80% · 90d +14.20%
await vnstock.stock.toAIPrompt('VCB', { lang: 'en' }); // English version
await vnstock.stock.toAIPrompt('VCB', { lookback: 100 });
import vnstock from 'vnstock-js';
import { Anthropic } from '@anthropic-ai/sdk';
const text = await vnstock.stock.toAIPrompt('VCB');
const client = new Anthropic();
const response = await client.messages.create({
model: 'claude-opus-4-7',
max_tokens: 1024,
messages: [
{
role: 'user',
content: `Phân tích VCB dựa trên context sau và đưa ra nhận định kỹ thuật:\n\n${text}`,
},
],
});
Note:
Không phải lời khuyên đầu tư. Output là pre-computed indicators + rules-based classifier. LLM reasoning trên context vẫn cần user judgment.
Note:
Trend classifier hiện tại rules-based (EMA chain + slope), không phải ML. Có thể mis-classify trong sideway market. neutral là fallback safe.