Vnstock Logo

Thị trường

Thử nghiệm

Mục lục

Bản thử nghiệm, chưa phát hành chính thứ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 đó.

Nguồn của 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

Python
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ệ 5

Mỗi hàm có bộ nguồn riêng, ghi ở cột "Nguồn" của bảng dưới. Khớp lệnh:

Python
Market("<nguồn>").equity("FPT").trades()

Khối ngoại của chỉ số:

Python
Market("<nguồn>").index("VNINDEX").foreign_flow(start="2026-10-01")

Tiền mã hoá:

Python
Market("<nguồn>").crypto("BTCUSDT").ohlcv(interval="1H")

Hợp đồng tương lai:

Python
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ểuMặc địnhÝ nghĩa
start, endstr, date, datetimeend là hôm nay; start là 30 ngày trước end với nếnYYYY-MM-DD, YYYY-MM, YYYY (ngày đầu), hoặc chuỗi ISO có giờ
intervalstr"1D"1m 3m 5m 15m 30m 1H 4H 1D 1W 1M; mỗi nguồn hỗ trợ một phần
lengthint, str100 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_backintChỉ giữ N nến gần nhất
limitintSố bản ghi tối đa xin nguồn, khi nguồn hỗ trợ
floatingint2Số chữ số thập phân của cột giá; None giữ nguyên
sourcestrNguồn cho lời gọi này
compatstr"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á
columnsstr"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:

Python
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àmTên khácTham sốNguồn (source=)
active_flow()intervalfhsc
block_trades()put_throughexchange, datetcbs
expected_price()start, end, boarddnse
foreign_flow()start, end, interval, length, limitdnse, fhsc, ssi
foreign_room()groupdnse, fhsc, ssi
insider_deal()start, endfhsc
ohlcv()historystart, end, interval, length, count_back, limitdnse, fhsc, ssi, tcbs
order_book()price_depthboarddnse, fhsc, tcbs
proprietary_flow()start, end, length, limitfhsc
quote()price_boardboardfhsc, tcbs
session_stats()trading_statsstart, end, length, limitssi
summary()fhsc
trade_history()start, end, length, limitssi
trades()intradaystart, end, limit, boarddnse, tcbs
volume_profile()matched_by_pricedatednse, tcbs
Cột trả về (hồ sơ v5, mặc định)
HàmCộ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àmTên khácTham sốNguồn (source=)
block_trades()put_throughexchange, datetcbs
foreign_flow()start, end, interval, length, limitdnse, fhsc, ssi
ohlcv()historystart, end, interval, length, count_back, limitdnse, fhsc, ssi, tcbs
order_book()price_depthboarddnse, fhsc, tcbs
proprietary_flow()start, end, length, limitfhsc
quote()price_boardboardfhsc, tcbs
session_stats()trading_statsstart, end, length, limitssi
summary()fhsc
trade_history()start, end, length, limitssi
trades()intradaystart, end, limit, boarddnse, tcbs
volume_profile()matched_by_pricedatednse, tcbs
Cột trả về (hồ sơ v5, mặc định)
HàmCộ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àmTên khácTham sốNguồn (source=)
history()start, end, interval, length, count_back, limitdnse, fhsc, ssi, tcbs
intraday()start, end, limit, boarddnse, tcbs
price_board()boardfhsc, tcbs
price_depth()boarddnse, fhsc, tcbs
Cột trả về (hồ sơ v5, mặc định)
HàmCộ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àmTên khácTham sốNguồn (source=)
foreign_flow()start, end, length, limitfhsc, ssi
ohlcv()historystart, end, interval, length, count_back, limitdnse, fhsc, ssi, tcbs
proprietary_flow()start, end, length, limitssi
quote()price_board, summarystart, enddnse, ssi
trade_history()start, end, length, limitssi
Cột trả về (hồ sơ v5, mặc định)
HàmCộ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àmTên khácTham sốNguồn (source=)
ohlcv()historystart, end, interval, limitfhsc, fmp
Cột trả về (hồ sơ v5, mặc định)
HàmCột
ohlcv()time, open, high, low, close, volume

Hợp đồng tương lai (futures)

HàmTên khácTham sốNguồn (source=)
ohlcv()historystart, end, interval, length, count_back, limitdnse, ssi
order_book()price_depthdnse, tcbs
quote()price_board, summarydnse, tcbs
trades()intradaystart, end, limit, boarddnse
Cột trả về (hồ sơ v5, mặc định)
HàmCộ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àmTên khácTham sốNguồn (source=)
ohlcv()historystart, end, interval, length, count_back, limittcbs
order_book()price_depthdnse
quote()price_board, summarytcbs
trades()intradaystart, end, limitdnse
Cột trả về (hồ sơ v5, mặc định)
HàmCộ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àmTên khácTham sốNguồn (source=)
daily_stats()summarybinance
last_price()binance, fhsc
ohlcv()historystart, end, interval, limitbinance, fhsc, fmp
order_book()price_depthlimitbinance
quote()price_boardbinance, fhsc
reference_price()fhsc
rolling_stats()binance
trades()intraday, trade_historylimitbinance
vwap()binance
Cột trả về (hồ sơ v5, mặc định)
HàmCộ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àmTên khácTham sốNguồn (source=)
ohlcv()historystart, end, interval, limitfhsc, fmp
Cột trả về (hồ sơ v5, mặc định)
HàmCột
ohlcv()time, open, high, low, close, volume

Hàng hoá (commodity)

HàmTên khácTham sốNguồn (source=)
ohlcv()historystart, end, interval, limitfhsc, fmp
Cột trả về (hồ sơ v5, mặc định)
HàmCột
ohlcv()time, open, high, low, close, volume

Quỹ mở (fund)

HàmTên khácTham sốNguồn (source=)
history()nav, ohlcvstart, endfhsc
performance()fhsc
Cột trả về (hồ sơ v5, mặc định)
HàmCộ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ế

Python
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).