> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vos.verolabs.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming API

> Streaming connection endpoints, subscription channels và message payloads

Streaming API chạy tại `https://streaming-oms.verolabs.co`.
Terminal mở một connection dùng chung, sau đó tạo subscription theo từng channel.

## Connection endpoints

| Transport    | Endpoint                                                   |
| ------------ | ---------------------------------------------------------- |
| WebSocket    | `wss://streaming-oms.verolabs.co/connection/websocket`     |
| HTTP stream  | `https://streaming-oms.verolabs.co/connection/http_stream` |
| SSE fallback | `https://streaming-oms.verolabs.co/connection/sse`         |

Terminal ưu tiên WebSocket, sau đó HTTP stream, cuối cùng là SSE fallback.

## Subscribe request

Sau khi kết nối, subscribe từng channel cần thiết. Mỗi subscription xác định một channel:

```json theme={null}
{
  "channel": "mkt:productInfo:FPT-G1"
}
```

## Message payload

Mỗi channel update chứa message payload.
Payload có thể là JSON value hoặc JSON-encoded string. Parse string trước khi áp dụng channel schema.

```ts theme={null}
type ChannelMessage<T> = {
  channel: string;
  data: T | string;
};
```

## Market channels

| Channel                              | Payload                                              |
| ------------------------------------ | ---------------------------------------------------- |
| `mkt:vnIndex:{indexCode}`            | Index update. Ví dụ: `VN30`, `VNINDEX`, `HNX30`.     |
| `mkt:productInfo:{symbol}-{board}`   | `ProductInfo` quote payload. Board mặc định là `G1`. |
| `mkt:productStat:{symbol}-{board}`   | Product trading statistics.                          |
| `mkt:depth:{symbol}-{board}`         | `Depth` order book payload.                          |
| `mkt:tradeLog:{symbol}-{board}`      | `TradeLog` print payload.                            |
| `mkt:ProductTrend:{symbol}-{board}`  | `TrendMaster` buy/sell pressure payload.             |
| `mkt:OhlcvDTO:{symbol}:{resolution}` | `OhlcvBar` payload. Resolution tính bằng giây.       |

## Trading channels

| Channel                                  | Payload                                          |
| ---------------------------------------- | ------------------------------------------------ |
| `order:OrderExecutionReport:{accountId}` | `OrderExecutionReport` order state change.       |
| `order:Account:{accountId}`              | `AccountCashReport` hoặc `AccountHoldingReport`. |

Client subscribe một channel `order:` cho mỗi account được phép truy cập. Account list và snapshot được load qua authenticated REST API trước khi mở stream subscription.

## ProductInfo

```ts theme={null}
type ProductInfo = {
  id: string;
  seq: number;
  time: number;
  symbol: string;
  boardID: string;
  currFR: number;
  totalFR: number;
  totBuyFR: number;
  totSellFR: number;
  nomiPrc: number;
  ceilPrc: number;
  floorPrc: number;
  lsPrc: number;
  lsVol: number;
  AucEstPrc: number;
  AucEstVol: number;
  isAuction: boolean;
  openPrc: number;
  closePrc: number;
  highPrc: number;
  lowPrc: number;
  vWAP: number;
  totVol: number;
  totVal: number;
  totVolPT: number;
  totValPT: number;
  lsWay: number;
  dynInfo: string;
  marketMakingPossible: string;
  halt: string;
  liquidationTrading: string;
  tradingSession: string;
  boardEventID: string;
  sessionOpenCloseCode: string;
  openInterest: number;
};
```

## Depth

```ts theme={null}
type PriceDepth = {
  prc: number;
  vol: number;
};

type Depth = {
  seq: number;
  time: number;
  symbol: string;
  boardID: string;
  bidPriceDepth: PriceDepth[];
  askPriceDepth: PriceDepth[];
};
```

## TradeLog and OHLCV

```ts theme={null}
type TradeLog = {
  id: string;
  seq: number;
  symbol: string;
  unixTime: number;
  price: number;
  volume: number;
  change: number;
  way: number;
  boardID: string;
};

type OhlcvBar = {
  time: number;
  open: number;
  high: number;
  low: number;
  close: number;
  volume: number;
};
```

## OrderExecutionReport

```ts theme={null}
type OrderExecutionReport = {
  user: string;
  orderID?: string;
  originalReqID: string;
  internalOrderID: string;
  refOrderID: string;
  origClOrdID: string;
  externalOrderID: string;
  externalSecondOrderID: string;
  accountID: string;
  symbol: string;
  marketID?: string;
  orderSide: string;
  orderStatus: string;
  orderType: string;
  originalPrice: number;
  originalQty: number;
  orderCurrentPrice: number;
  orderCurrentQty: number;
  filledQty: number;
  avgFillPrice: number;
  cancelledQty: number;
  orderText: string;
  unixUTCTimeMs: number;
  createunixUTCTimeMs: number;
  persisState: string;
  algoID: string;
  positionID: string;
  parentOrderId: string;
};
```

## AccountStateReport

```ts theme={null}
type AccountCashReport = {
  type: "account";
  account_id: string;
  cash_available: number;
  cash_hold: number;
  bypass_cash: boolean;
  bypass_stock: boolean;
  ts_ns: number;
};

type AccountHoldingReport = {
  type: "holding";
  account_id: string;
  symbol: string;
  sellable_qty: number;
  hold_qty: number;
  avg_price: number;
  ts_ns: number;
};
```
