Các lời gọi cơ bản của vnstock-js 2.x với đầu ra mẫu.
import { vn } from "vnstock-js";
vn là client mặc định, dùng được ngay. Mọi số tiền tính bằng đồng.
const quote = await vn.stock("FPT").price();
{
"symbol": "FPT", "name": "Công ty Cổ phần FPT", "exchange": "HOSE",
"price": 57500, "change": 400, "changePct": 0.701,
"ref": 57100, "ceiling": 61000, "floor": 53200, "high": 57800, "low": 56800,
"volume": 3259200, "value": 186521720000, "matchVolume": 133100,
"foreignBuyVolume": 512856, "foreignSellVolume": 807002,
"bids": [{ "price": 57500, "volume": 1000 }], "asks": [{ "price": 57600, "volume": 40600 }]
}
Xem đủ các trường ở Quote.
const bars = await vn.stock("FPT").history("6mo");
[{ "time": "2026-10-20", "open": 57000, "high": 57800, "low": 56800, "close": 57600, "volume": 3259200, "value": 186521720000 }]
Range: 1d 5d 1mo 3mo 6mo ytd 1y 2y 5y max, hoặc { from, to, interval }. Xem Lịch sử giá.
const vnindex = await vn.index("VNINDEX").history("1mo"); // điểm, ví dụ close: 1689.12
const quotes = await vn.prices(["FPT", "VCB", "HPG"]);
const vn30 = await vn.prices({ group: "VN30" });
const m = await vn.market({ exchange: "HOSE" });
console.log(m.index.close, m.liquidity.value, m.breadth.advancing, m.foreign.netValue);
const { gainers, losers } = await vn.topMovers({ limit: 10 });
const fpt = vn.stock("FPT");
const profile = await fpt.company(); // ngành, số cổ phiếu
const holders = await fpt.shareholders();
const events = await fpt.events(); // cổ tức, phát hành, đại hội
const gold = await vn.gold(); // đồng/lượng
const usd = (await vn.fx()).find((r) => r.currencyCode === "USD");
const news = await vn.news({ query: "lãi suất" });
try {
await vn.stock("FTP").price();
} catch (e) {
console.log(e.code, e.hint); // INVALID_SYMBOL, Did you mean "FPT"?
}