Thị trường
Mục lục
Trang này viết cho vnstock v6.0.0rc3, bản thử nghiệm. Tên hàm, tham số và cột dữ liệu có thể còn đổi trước ngày phát hành; khi cài, ghi rõ số phiên bản như ở trang Cài đặt. Bản đang phát hành chính thức là v5.0.1, xem tài liệu bản đó.
Chọn nguồn bạn có khoá, mã trên trang sẽ điền theo. Chưa chọn thì mã giữ chỗ trống <nguồn>. Nguồn xếp theo bảng chữ cái, không phải khuyến nghị.
Market dùng để truy xuất nến, khớp lệnh, bảng giá, sổ lệnh, dữ liệu khối ngoại và tự doanh, cùng dữ
liệu tiền mã hoá, ngoại hối, hàng hoá và quỹ mở.
Cách gọi
from vnstock import Market
Market("<nguồn>").equity("FPT").ohlcv(start="2026-10-01", end="2026-10-30", interval="1D")
Market().equity("FPT").ohlcv(source="<nguồn>", length=100) # cách gọi thế hệ 5Mỗi hàm có bộ nguồn riêng, ghi ở cột "Nguồn" của bảng dưới. Khớp lệnh:
Market("<nguồn>").equity("FPT").trades()Khối ngoại của chỉ số:
Market("<nguồn>").index("VNINDEX").foreign_flow(start="2026-10-01")Tiền mã hoá:
Market("<nguồn>").crypto("BTCUSDT").ohlcv(interval="1H")Hợp đồng tương lai:
Market("<nguồn>").futures("VN30F1M").ohlcv(length=100)Thứ tự gọi là Market(nguồn) → nhóm tài sản kèm mã → hàm. Nếu không nêu nguồn, vnstock dùng quy tắc đã đặt bằng
vnstock.sources (Chọn nguồn).
Tham số chung
| Tham số | Kiểu | Mặc định | Ý nghĩa |
|---|---|---|---|
start, end | str, date, datetime | end là hôm nay; start là 30 ngày trước end với nến | YYYY-MM-DD, YYYY-MM, YYYY (ngày đầu), hoặc chuỗi ISO có giờ |
interval | str | "1D" | 1m 3m 5m 15m 30m 1H 4H 1D 1W 1M; mỗi nguồn hỗ trợ một phần |
length | int, str | 100 hay "100b": 100 nến gần nhất; "3M", "1Y", "10d", "2W": khoảng thời gian tính lùi từ end | |
count_back | int | Chỉ giữ N nến gần nhất | |
limit | int | Số bản ghi tối đa xin nguồn, khi nguồn hỗ trợ | |
floating | int | 2 | Số chữ số thập phân của cột giá; None giữ nguyên |
source | str | Nguồn cho lời gọi này | |
compat | str | "v5" | "v5": tên, thứ tự, đơn vị như thế hệ 5; "v6": chuẩn đồng nhất, xem Bộ cột và chuẩn hoá |
columns | str | "standard" | "common" hoặc "all", xem Bộ cột và chuẩn hoá |
Mỗi hàm chỉ nhận tham số ghi ở cột "Tham số" trong bảng dưới, cộng các tham số chung source,
floating, compat, columns. Truyền tham số khác thì báo VNSTOCK_INPUT_PARAM.
Đơn vị giá như thế hệ 5: nến và khớp lệnh tính bằng nghìn đồng; bảng giá, sổ lệnh, thoả thuận, khớp theo bước giá,
trade_history(), session_stats() tính bằng đồng. Chỉ số và hợp đồng tương lai chỉ số tính bằng điểm. Tiền mã
hoá, ngoại hối, hàng hoá tính theo đồng định giá của cặp, thời gian theo UTC. Hồ sơ v6 đưa mọi giá cổ phiếu về
nghìn đồng.
Nến ngày mang mốc 07:00+07:00 (00:00 UTC của phiên) như thế hệ 5. Ở hồ sơ v5, foreign_flow(),
proprietary_flow(), trade_history() xếp phiên mới nhất trước, mốc ngày 00:00+07:00. Ở hồ sơ v6, các hàm này
tăng dần theo thời gian, cùng mốc với nến, xem
Bộ cột và chuẩn hoá.
Gọi nến trong giờ giao dịch thì nến cuối là của phiên chưa kết thúc: giá đóng cửa và khối lượng của nó còn đổi.
df.attrs["last_bar_partial"] là True trong trường hợp này (nến tuần, tháng cũng vậy khi tuần, tháng chưa hết). Bỏ
nến cuối nếu bạn chỉ cần phiên đã đóng:
df = Market("<nguồn>").equity("FPT").ohlcv(start="2026-10-01")
if df.attrs.get("last_bar_partial"):
df = df.iloc[:-1]Hàm theo nhóm tài sản
Bảng sinh từ thư viện bản 6.0.0.dev0, hồ sơ v5 (mặc định). "Tên khác" là tên của thế hệ 5 cho cùng dữ liệu.
Danh sách đầy đủ trên máy bạn: vnstock tools, hoặc show_api() trong Python.
Cổ phiếu (equity)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
active_flow() | interval | fhsc | |
block_trades() | put_through | exchange, date | tcbs |
expected_price() | start, end, board | dnse | |
foreign_flow() | start, end, interval, length, limit | dnse, fhsc, ssi | |
foreign_room() | group | dnse, fhsc, ssi | |
insider_deal() | start, end | fhsc | |
ohlcv() | history | start, end, interval, length, count_back, limit | dnse, fhsc, ssi, tcbs |
order_book() | price_depth | board | dnse, fhsc, tcbs |
proprietary_flow() | start, end, length, limit | fhsc | |
quote() | price_board | board | fhsc, tcbs |
session_stats() | trading_stats | start, end, length, limit | ssi |
summary() | fhsc | ||
trade_history() | start, end, length, limit | ssi | |
trades() | intraday | start, end, limit, board | dnse, tcbs |
volume_profile() | matched_by_price | date | dnse, tcbs |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
active_flow() | time, active_buy_volume, active_sell_volume, active_buy_percent, active_sell_percent, active_buy_sell_ratio |
block_trades() | symbol, match_price, match_volume, match_value, accumulated_value, time |
expected_price() | time, expected_price, expected_volume |
foreign_flow() | time, buy_vol, buy_val, sell_vol, sell_val, net_vol, net_val |
foreign_room() | symbol, time, foreign_room, foreign_room_total, foreign_buy_volume, foreign_sell_volume, foreign_owned_volume, foreign_room_limit_percent |
insider_deal() | id, symbol, person_name, position, transaction_type, registered_volume, traded_volume, start_date, end_date, status, shares_before, shares_after, ownership_percent_before, ownership_percent_after, relation_type, related_person_name |
ohlcv() | time, open, high, low, close, volume |
order_book() | bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, time, total_bid_volume, total_ask_volume |
proprietary_flow() | time, buy_vol, buy_val, sell_vol, sell_val, net_vol, net_val |
quote() | symbol, exchange, reference_price, ceiling_price, floor_price, open_price, high_price, low_price, close_price, bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, foreign_buy_volume, foreign_sell_volume, time, price_change, price_change_percent, average_price, total_volume, total_value, foreign_room, next_reference_price, next_ceiling_price, next_floor_price, last_volume |
session_stats() | symbol, time, average_match_volume, average_match_value, average_deal_volume, average_deal_value, average_volume, average_value, total_match_volume, total_match_value, total_deal_volume, total_deal_value, total_volume, total_value, fr_buy_volume_total, fr_buy_value_total, fr_sell_volume_total, fr_sell_value_total, fr_net_volume_total, fr_net_value_total, fr_buy_volume_total_avg, fr_buy_value_total_avg, fr_sell_volume_total_avg, fr_sell_value_total_avg, fr_net_volume_total_avg, fr_net_value_total_avg, total_buy_trade_volume, total_sell_trade_volume, total_buy_trade_volume_avg, total_sell_trade_volume_avg, total_buy_trade, total_sell_trade, total_buy_trade_avg, total_sell_trade_avg, total_net_trade_volume, total_net_trade_volume_avg, average_buy_volume_per_trade, average_sell_volume_per_trade, close_price, reference_price |
summary() | eps, pe, pb, roe, dividend_yield, symbol, roa, ev_ebitda, gross_margin, nim, industry_pe, industry_pb, industry_ev_ebitda |
trade_history() | trading_date, reference_price, open, close, price_change, percent_price_change, high, low, average_price, matched_volume, matched_value, deal_volume, deal_value, total_volume, total_value, total_buy_trade, total_buy_trade_volume, total_sell_trade, total_sell_trade_volume, symbol, foreign_buy_volume, foreign_buy_value, foreign_sell_volume, foreign_sell_value, foreign_net_volume, foreign_net_value |
trades() | time, price, volume, match_type, id, accumulated_volume |
volume_profile() | price, buy_volume, sell_volume, unknown_volume, total_volume |
Chứng chỉ quỹ ETF (etf)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
block_trades() | put_through | exchange, date | tcbs |
foreign_flow() | start, end, interval, length, limit | dnse, fhsc, ssi | |
ohlcv() | history | start, end, interval, length, count_back, limit | dnse, fhsc, ssi, tcbs |
order_book() | price_depth | board | dnse, fhsc, tcbs |
proprietary_flow() | start, end, length, limit | fhsc | |
quote() | price_board | board | fhsc, tcbs |
session_stats() | trading_stats | start, end, length, limit | ssi |
summary() | fhsc | ||
trade_history() | start, end, length, limit | ssi | |
trades() | intraday | start, end, limit, board | dnse, tcbs |
volume_profile() | matched_by_price | date | dnse, tcbs |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
block_trades() | symbol, match_price, match_volume, match_value, accumulated_value, time |
foreign_flow() | time, buy_vol, buy_val, sell_vol, sell_val, net_vol, net_val |
ohlcv() | time, open, high, low, close, volume |
order_book() | bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, time, total_bid_volume, total_ask_volume |
proprietary_flow() | time, buy_vol, buy_val, sell_vol, sell_val, net_vol, net_val |
quote() | symbol, exchange, reference_price, ceiling_price, floor_price, open_price, high_price, low_price, close_price, bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, foreign_buy_volume, foreign_sell_volume, time, price_change, price_change_percent, average_price, total_volume, total_value, foreign_room, next_reference_price, next_ceiling_price, next_floor_price, last_volume |
session_stats() | symbol, time, average_match_volume, average_match_value, average_deal_volume, average_deal_value, average_volume, average_value, total_match_volume, total_match_value, total_deal_volume, total_deal_value, total_volume, total_value, fr_buy_volume_total, fr_buy_value_total, fr_sell_volume_total, fr_sell_value_total, fr_net_volume_total, fr_net_value_total, fr_buy_volume_total_avg, fr_buy_value_total_avg, fr_sell_volume_total_avg, fr_sell_value_total_avg, fr_net_volume_total_avg, fr_net_value_total_avg, total_buy_trade_volume, total_sell_trade_volume, total_buy_trade_volume_avg, total_sell_trade_volume_avg, total_buy_trade, total_sell_trade, total_buy_trade_avg, total_sell_trade_avg, total_net_trade_volume, total_net_trade_volume_avg, average_buy_volume_per_trade, average_sell_volume_per_trade, close_price, reference_price |
summary() | eps, pe, pb, roe, dividend_yield, symbol, roa, ev_ebitda, gross_margin, nim, industry_pe, industry_pb, industry_ev_ebitda |
trade_history() | trading_date, reference_price, open, close, price_change, percent_price_change, high, low, average_price, matched_volume, matched_value, deal_volume, deal_value, total_volume, total_value, total_buy_trade, total_buy_trade_volume, total_sell_trade, total_sell_trade_volume, symbol, foreign_buy_volume, foreign_buy_value, foreign_sell_volume, foreign_sell_value, foreign_net_volume, foreign_net_value |
trades() | time, price, volume, match_type, id, accumulated_volume |
volume_profile() | price, buy_volume, sell_volume, unknown_volume, total_volume |
Trái phiếu (bond)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
history() | start, end, interval, length, count_back, limit | dnse, fhsc, ssi, tcbs | |
intraday() | start, end, limit, board | dnse, tcbs | |
price_board() | board | fhsc, tcbs | |
price_depth() | board | dnse, fhsc, tcbs |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
history() | time, open, high, low, close, volume |
intraday() | time, price, volume, match_type, id, accumulated_volume |
price_board() | symbol, exchange, reference_price, ceiling_price, floor_price, open_price, high_price, low_price, close_price, bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, foreign_buy_volume, foreign_sell_volume, time, price_change, price_change_percent, average_price, total_volume, total_value, foreign_room, next_reference_price, next_ceiling_price, next_floor_price, last_volume |
price_depth() | bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, time, total_bid_volume, total_ask_volume |
Chỉ số (index)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
foreign_flow() | start, end, length, limit | fhsc, ssi | |
ohlcv() | history | start, end, interval, length, count_back, limit | dnse, fhsc, ssi, tcbs |
proprietary_flow() | start, end, length, limit | ssi | |
quote() | price_board, summary | start, end | dnse, ssi |
trade_history() | start, end, length, limit | ssi |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
foreign_flow() | time, foreign_buy_volume, foreign_buy_value, foreign_sell_volume, foreign_sell_value, foreign_net_volume, foreign_net_value |
ohlcv() | time, open, high, low, close, volume |
proprietary_flow() | time, proprietary_buy_volume, proprietary_buy_value, proprietary_sell_volume, proprietary_sell_value, proprietary_net_volume, proprietary_net_value |
quote() | symbol, reference_price, high_price, low_price, close_price, total_volume, time, price_change, percent_change, advances, declines, no_change, accumulated_volume, accumulated_value, put_through_volume, put_through_value, ceiling_count, floor_count, advance_volume, decline_volume, unchanged_volume |
trade_history() | trading_date, price_change, percent_price_change, reference_price, close, matched_volume, matched_value, deal_volume, deal_value, total_volume, total_value, total_stock_up_price, total_stock_down_price, total_stock_no_change_price, total_stock_ceiling, total_stock_floor |
Chỉ số quốc tế (index(..., scope="global"))
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
ohlcv() | history | start, end, interval, limit | fhsc, fmp |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
ohlcv() | time, open, high, low, close, volume |
Hợp đồng tương lai (futures)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
ohlcv() | history | start, end, interval, length, count_back, limit | dnse, ssi |
order_book() | price_depth | dnse, tcbs | |
quote() | price_board, summary | dnse, tcbs | |
trades() | intraday | start, end, limit, board | dnse |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
ohlcv() | time, open, high, low, close, volume |
order_book() | bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, time, total_bid_volume, total_ask_volume |
quote() | symbol, exchange, reference_price, ceiling_price, floor_price, open_price, high_price, low_price, close_price, total_volume, bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, basis, open_interest, foreign_buy_volume, foreign_sell_volume, last_trading_date, time, price_change, price_change_percent, average_price |
trades() | time, price, volume, match_type, id, accumulated_volume |
Chứng quyền (warrant)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
ohlcv() | history | start, end, interval, length, count_back, limit | tcbs |
order_book() | price_depth | dnse | |
quote() | price_board, summary | tcbs | |
trades() | intraday | start, end, limit | dnse |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
ohlcv() | time, open, high, low, close, volume |
order_book() | bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, time |
quote() | symbol, exchange, reference_price, ceiling_price, floor_price, open_price, high_price, low_price, close_price, bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, foreign_buy_volume, foreign_sell_volume, break_even_point, underlying_price, time, price_change, price_change_percent, total_volume, exercise_price, conversion_ratio, maturity_date, issuer, underlying_symbol, next_reference_price, next_ceiling_price, next_floor_price, last_volume |
trades() | time, price, volume, match_type, id, accumulated_volume |
Tiền mã hoá (crypto)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
daily_stats() | summary | binance | |
last_price() | binance, fhsc | ||
ohlcv() | history | start, end, interval, limit | binance, fhsc, fmp |
order_book() | price_depth | limit | binance |
quote() | price_board | binance, fhsc | |
reference_price() | fhsc | ||
rolling_stats() | binance | ||
trades() | intraday, trade_history | limit | binance |
vwap() | binance |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
daily_stats() | symbol, price_change, price_change_percent, weighted_avg_price, open_price, high_price, low_price, last_price, volume, quote_volume, open_time, close_time, first_id, last_id, count |
last_price() | symbol, price |
ohlcv() | time, open, high, low, close, volume, quote_volume, trade_count |
order_book() | bid_price_1, bid_vol_1, bid_price_2, bid_vol_2, bid_price_3, bid_vol_3, bid_price_4, bid_vol_4, bid_price_5, bid_vol_5, bid_price_6, bid_vol_6, bid_price_7, bid_vol_7, bid_price_8, bid_vol_8, bid_price_9, bid_vol_9, bid_price_10, bid_vol_10, ask_price_1, ask_vol_1, ask_price_2, ask_vol_2, ask_price_3, ask_vol_3, ask_price_4, ask_vol_4, ask_price_5, ask_vol_5, ask_price_6, ask_vol_6, ask_price_7, ask_vol_7, ask_price_8, ask_vol_8, ask_price_9, ask_vol_9, ask_price_10, ask_vol_10, time |
quote() | symbol, reference_price, open_price, high_price, low_price, close_price, bid_price_1, bid_vol_1, ask_price_1, ask_vol_1, time, price_change, price_change_percent, base_volume, quote_volume, average_price, trade_count |
reference_price() | symbol, reference_price, timestamp |
rolling_stats() | symbol, price_change, price_change_percent, weighted_avg_price, open_price, high_price, low_price, last_price, volume, quote_volume, open_time, close_time, first_id, last_id, count |
trades() | time, price, volume, side, id, quote_volume |
vwap() | mins, price, close_time |
Tỷ giá (forex)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
ohlcv() | history | start, end, interval, limit | fhsc, fmp |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
ohlcv() | time, open, high, low, close, volume |
Hàng hoá (commodity)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
ohlcv() | history | start, end, interval, limit | fhsc, fmp |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
ohlcv() | time, open, high, low, close, volume |
Quỹ mở (fund)
| Hàm | Tên khác | Tham số | Nguồn (source=) |
|---|---|---|---|
history() | nav, ohlcv | start, end | fhsc |
performance() | fhsc |
Cột trả về (hồ sơ v5, mặc định)
| Hàm | Cột |
|---|---|
history() | time, nav |
performance() | period, period_label, nav_start, nav_end, return_percent, annualized |
Khớp lệnh cả phiên
trades() tự đọc lần lượt các trang trong khoảng thời gian được yêu cầu. Với dnse, nếu không nêu ngày,
thư viện lấy phiên gần nhất; vào cuối tuần, đó là phiên thứ Sáu. Số bản ghi trong mỗi request do nguồn
quy định (dnse tối đa 1.000, tcbs tối đa 100), nên mã có nhiều lệnh khớp sẽ cần nhiều request. Với
dnse, thư viện dừng sau 500 trang (500.000 lệnh) và ghi cảnh báo vào log. Khi gặp cảnh báo, hãy chia
nhỏ khoảng thời gian rồi gọi lại.
Chưa hỗ trợ
Hàm thế hệ 5 chưa có nguồn đọc được ở thế hệ 6 vẫn gọi được bằng tên cũ, nhưng báo
CompatibilityWarning rồi UnsupportedError mã VNSTOCK_ROUTE_UNSUPPORTED, không trả bảng rỗng.
dir(Market("<nguồn>").equity("FPT")) liệt kê mọi hàm của nhóm; vnstock tools Market --all liệt kê cả hàm chưa có
nguồn.
Các tên thế hệ 5 gọi thẳng trên Market() vẫn chạy và trả cùng bảng với hàm của nhóm cổ phiếu:
Market("<nguồn>").quote("FPT,VNM") là Market("<nguồn>").equity.quote("FPT,VNM"), put_through() là
equity.block_trades(). Market().future(...) là Market().futures(...).
Chỉ số quốc tế
Market("<nguồn>").index("^GSPC", scope="global").ohlcv(start="2026-10-01")Cách gọi giữ như thế hệ 5. Chỉ có nến (ohlcv, tên khác history); giờ UTC. Ký hiệu chỉ số viết theo nguồn bạn chọn:
fmp dùng dấu mũ (^GSPC, ^DJI, ^IXIC).
