vnstock-js

vnstock-js

Tài LiệuVí DụBài ViếtTài Chính
k

© Copyright 2026

Giới Thiệu
Danh Sách Hàm
Cài Đặt
Kiến Trúc
Hướng Dẫn Sử Dụng Nhanh
CLI
Lịch Sử Phiên Bản
Câu Hỏi Thường Gặp
Cơ Bản
QuoteHistory
PriceBoardItem
TopStock
CompanyProfile
ScreenResult
RealtimeQuote
ExchangeRate
  1. Tài Liệu
  2. Getting Started
  3. Architecture

Kiến Trúc

Kiến trúc Pipeline của vnstock-js v1.0

Tổng Quan

vnstock-js v1.0 sử dụng Pipeline Architecture - mọi request đi qua 2 giai đoạn xử lý:

Request Pipeline → Transform Pipeline → Output (Array of Objects)

Request Pipeline

API Call
  │
  ▼
┌──────────┐
│  Fetch   │  ← HTTP client (axios), GET/POST/GraphQL
└────┬─────┘
     ▼
┌──────────┐
│  Retry   │  ← 2 lần retry, exponential backoff (5xx, timeout)
└────┬─────┘
     ▼
Raw Response

Transform Pipeline

Dữ liệu thô từ API đi qua 5 bước chuẩn hóa:

Raw Response
  │
  ▼
┌──────────┐
│ 1. Parse │  ← Xử lý JSON, edge cases (empty, malformed)
└────┬─────┘
     ▼
┌──────────┐
│ 2. Clean │  ← Loại bỏ null/undefined, fields thừa
└────┬─────┘
     ▼
┌──────────┐
│ 3.Rename │  ← Map field names → camelCase tiếng Anh
└────┬─────┘
     ▼
┌───────────┐
│ 4.Normalize│ ← Chuẩn hóa nghiệp vụ VN
│  (VN Biz) │    - Giá ÷ 1000 (đơn vị: nghìn VND)
│           │    - Timestamp → "2024-01-15"
│           │    - Percentage → decimal (0.15)
└────┬──────┘
     ▼
┌──────────┐
│ 5. Shape │  ← Chuyển thành Array of Objects
└────┬─────┘
     ▼
QuoteHistory[] | PriceBoardItem[] | ...

Cấu trúc thư mục

src/
├── core/               # Business logic
│   ├── stock/          # Quote, Trading, Company, Financial, Listing, Screening
│   ├── commodity/      # Gold, Exchange rates
│   └── realtime.ts     # WebSocket
├── indicators/         # SMA, EMA, RSI (pure functions)
├── pipeline/           # Request + Transform pipeline
│   ├── fetch.ts        # HTTP client with retry
│   ├── transform.ts    # applyTransform()
│   └── transform/configs/  # Per-module transform rules
├── models/             # TypeScript interfaces
├── shared/             # Constants, utilities
├── simple.ts           # Simplified API wrapper
├── runtime.ts          # Vnstock class
└── index.ts            # Main exports

Nguồn dữ liệu

Loại dữ liệuNguồnGiao thức
Giá lịch sửVietCapREST
Bảng giáVietCapREST
Công ty, Tài chínhVietCapGraphQL
Niêm yếtVietCapREST + GraphQL
RealtimeSSIWebSocket
VàngBTMC, SJC, GiaVang.netREST
Tỷ giáVietcombankREST (JSON API)
PreviousCài Đặt
NextHướng Dẫn Sử Dụng Nhanh

Nội Dung

Tổng QuanRequest PipelineTransform PipelineCấu trúc thư mụcNguồn dữ liệu