2. Market Indexes

Display VN-Index, HNX-Index and get detailed summary for each index

Objective

Display market indexes (VN-Index, HNX-Index...) on a dashboard, filter by exchange, and get detailed summaries.

Flow

UI Dashboard → Market Data API (Index) → Cache State
  1. Call get_indexes() to get all indexes
  2. API returns index list with current price data
  3. Filter by exchange using get_indexes_by_board(Board.HOSE)
  4. Get detailed summary using get_index_summary("VNINDEX")

Sample Code — Sync

python/sample_02_index_list.py
from ssi_sdk import Auth, Data, Config
from ssi_sdk.enums import Board
from auth_helper import ensure_auth

config = Config(
    client_id="<your_client_id>",
    api_key="<your_api_key>",
    api_secret="<your_api_secret>",
    private_key="<your_private_key>",
)

with Auth(config) as auth:
    ensure_auth(auth)

    with Data(auth) as data:
        # Step 1: Get all indexes
        all_indexes = data.market_data.get_indexes()
        print(f"Total indexes: {len(all_indexes)}")

        # Step 2: Filter HOSE indexes
        hose_indexes = data.market_data.get_indexes_by_board(Board.HOSE)
        for idx in hose_indexes:
            print(f"  {idx.index:<15} | {idx.index_name}")

        # Step 3: Get VN-Index summary
        summary = data.market_data.get_index_summary("VNINDEX")
        if summary:
            print(f"  Value  : {summary.index_value}")
            print(f"  Change : {summary.index_change} ({summary.index_change_percent}%)")
            print(f"  Volume : {summary.total_match}")

Sample Code — Async

python/sample_02_index_list_async.py
import asyncio
from ssi_sdk import AsyncAuth, AsyncData, Config
from ssi_sdk.enums import Board
from auth_helper import ensure_auth_async

config = Config(...)  # Same config as above

async def main():
    async with AsyncAuth(config) as auth:
        await ensure_auth_async(auth)
        async with AsyncData(auth) as data:
            all_indexes = await data.market_data.get_indexes()
            hose_indexes = await data.market_data.get_indexes_by_board(Board.HOSE)
            summary = await data.market_data.get_index_summary("VNINDEX")

asyncio.run(main())

API Methods

MethodDescription
get_indexes()Get all market indexes
get_indexes_by_board(board)Filter indexes by exchange (HOSE, HNX, UPCOM)
get_index_summary(index_code)Get detailed summary for a specific index

On this page