A beginner-friendly yet powerful Python toolkit for financial analysis and automation — built to make modern investing accessible to everyone
The Vnstock class is the primary entry point for accessing Vietnamese financial market data. It provides a unified interface to create specialized component objects for different asset types and data sources.
Central orchestrator that returns specialized component objects for accessing different types of financial data. Supports multiple data sources with automatic provider selection and validation.
class Vnstock:
"""
Main VNStock client for accessing Vietnamese financial market data.
Attributes:
SUPPORTED_SOURCES (list): Available data sources ["VCI", "TCBS", "MSN"]
msn_symbol_map (dict): Symbol mappings for MSN data source
"""
def __init__(self, symbol: str = None, source: str = "VCI", show_log: bool = True):
"""
Initialize VNStock client.
Args:
symbol (str, optional): Default symbol for operations
source (str): Default data source, defaults to "VCI"
show_log (bool): Enable logging, defaults to True
"""Access Vietnamese stock market data including individual stocks and market indices.
def stock(self, symbol: Optional[str] = None, source: Optional[str] = None) -> StockComponents:
"""
Get stock market data components.
Args:
symbol (str, optional): Stock symbol (e.g., "TCB", "VCB")
source (str, optional): Data source ("VCI", "TCBS", "MSN")
Returns:
StockComponents: Object containing quote, company, finance components
"""import vnstock
from vnstock import Vnstock
# Initialize client
stock = Vnstock()
# Get stock components for TCB
tcb = stock.stock(symbol="TCB", source="VCI")
# Access different data types
price_data = tcb.quote.history(start="2023-01-01", end="2023-12-31")
company_info = tcb.company.overview()
financials = tcb.finance.balance_sheet(period="quarter")Access global foreign exchange data through MSN data source.
def fx(self, symbol: Optional[str] = 'EURUSD', source: Optional[str] = "MSN") -> MSNComponents:
"""
Get foreign exchange data components.
Args:
symbol (str): Currency pair symbol, defaults to "EURUSD"
source (str): Data source, defaults to "MSN"
Returns:
MSNComponents: Object containing FX data components
"""# Get EUR/USD data
eurusd = stock.fx(symbol="EURUSD")
fx_history = eurusd.quote.history(start="2023-01-01", end="2023-12-31")
# Get USD/VND data
usdvnd = stock.fx(symbol="USDVND")
vnd_data = usdvnd.quote.history()Access cryptocurrency data through MSN data source.
def crypto(self, symbol: Optional[str] = 'BTC', source: Optional[str] = "MSN") -> MSNComponents:
"""
Get cryptocurrency data components.
Args:
symbol (str): Crypto symbol, defaults to "BTC"
source (str): Data source, defaults to "MSN"
Returns:
MSNComponents: Object containing crypto data components
"""# Get Bitcoin data
btc = stock.crypto(symbol="BTC")
btc_history = btc.quote.history(start="2023-01-01", end="2023-12-31")
# Get Ethereum data
eth = stock.crypto(symbol="ETH")
eth_data = eth.quote.history()Access global stock market indices through MSN data source.
def world_index(self, symbol: Optional[str] = 'DJI', source: Optional[str] = "MSN") -> MSNComponents:
"""
Get global stock index data components.
Args:
symbol (str): Index symbol, defaults to "DJI" (Dow Jones)
source (str): Data source, defaults to "MSN"
Returns:
MSNComponents: Object containing index data components
"""# Get S&P 500 data
sp500 = stock.world_index(symbol="SPX")
sp500_history = sp500.quote.history(start="2023-01-01", end="2023-12-31")
# Get Nikkei 225 data
nikkei = stock.world_index(symbol="N225")
nikkei_data = nikkei.quote.history()Access Vietnamese mutual fund data through specialized Fund component.
def fund(self, source: Optional[str] = "FMARKET") -> Fund:
"""
Get mutual fund data components.
Args:
source (str): Data source, defaults to "FMARKET"
Returns:
Fund: Fund data component with listing and analysis capabilities
"""# Get fund component
funds = stock.fund()
# List all available funds
all_funds = funds.listing()
# Get specific fund details
fund_holdings = funds.top_holding(fundId=23)
fund_nav = funds.nav_report(fundId=23)Install with Tessl CLI
npx tessl i tessl/pypi-vnstock