WebSocket

Sub/Unsub Trading Data

Subscribe and unsubscribe to trading data via FastConnect WebSocket — including regular orders, order matches, portfolio updates, and conditional orders (FCO).

Overview

The TRADING channel allows clients to receive real-time trading events: order status, order matches, portfolio changes, and conditional order (FCO) events.

Clients must subscribe by account number (accountNo) to receive events. Each topic corresponds to a specific group of events.

Topic pattern

order.[accountNo/*]
portfolio.[accountNo-accountNo/*]
TopicDescriptionExample
order.<accountNo>Order events (place/modify/cancel/match) and conditional order (FCO) events for a specific accountorder.1231991
order.<accountNo1>-<accountNo2>Order events for several specific accountsorder.1231996-1231998
order.*Order and FCO events for all accounts within scopeorder.*
portfolio.<accountNo>Portfolio updates (assets, positions) for a specific accountportfolio.1231991
portfolio.<accountNo1>-<accountNo2>Portfolio updates for several specific accountsportfolio.1231996-1231998
portfolio.*Portfolio updates for all accounts within scopeportfolio.*

Note: Conditional order (FCO) events are delivered on the same order channel — no separate topic subscription is needed.

Note: Subscribing to the portfolio topic is currently only supported for accounts ending in 8 (derivative accounts). Cash accounts (ending in 1) and margin accounts (ending in 6) are not yet supported.

Subscribe

Send a message with method: "SUBSCRIBE" and channel: "TRADING":

{
  "method": "SUBSCRIBE",
  "channel": "TRADING",
  "topics": [
    "order.1231991",
    "order.1231996-1231998",
    "order.*",
    "portfolio.0901351"
  ]
}

Subscribe rules

  • Multiple topics can be included in a single message.
  • Subscribing to order.* receives order events from all accounts (including FCO events).
  • Subscribing to portfolio.* receives portfolio events from all accounts.
  • Subscribing to the same topic multiple times does not cause an error — the server ignores already-subscribed topics.
  • After reconnecting, the client must re-subscribe to all required topics.

Unsubscribe

Send a message with method: "UNSUBSCRIBE" and channel: "TRADING":

{
  "method": "UNSUBSCRIBE",
  "channel": "TRADING",
  "topics": ["order.0901351", "portfolio.0901351"]
}

Unsubscribe rules

  • Only unsubscribe from topics that were previously subscribed.
  • Unsubscribing from a topic that was not subscribed does not cause an error — the server ignores it.
  • Unsubscribing does not affect other currently subscribed topics.
  • To check which topics are currently subscribed, use LIST_SUBSCRIPTION.

Check current subscriptions

{
  "method": "LIST_SUBSCRIPTION"
}

The response returns scopes by group:

{
  "trading": "order.0901351;portfolio.0901351",
  "data": ""
}

Event types

After a successful subscription, the client will receive the following events in real time.

Binding events in the SDK

client.bind(client.events.onOrderEvent, function (e, data) {
  console.log(e + ": ");
  console.log(JSON.stringify(data));
});

client.bind(client.events.onOrderMatchEvent, function (e, data) {
  console.log(e + ": ");
  console.log(JSON.stringify(data));
});

client.bind(client.events.onClientPortfolioEvent, function (e, data) {
  console.log(e + ": ");
  console.log(JSON.stringify(data));
});

Conditional order (FCO) events are delivered via the same onClientPortfolioEvent binding.


Order Event

Order status event — triggered when an order is placed, modified, canceled, or changes status.

{
  "eventType": "orderEvent",
  "notifyId": 123456789,
  "connectionId": "conn-001",
  "clientRequestId": "req-20240226-001",
  "orderId": "ORD123456",
  "symbol": "VNM",
  "side": "B",
  "orderType": "LO",
  "accountNo": "0901351",
  "price": "72000",
  "quantity": 1000,
  "cancelQty": 0,
  "osQty": 1000,
  "filledQty": 0,
  "inputTime": "2026/03/01 14:20:55",
  "modifiedTime": "2026/03/01 14:20:55",
  "orderStatus": "PD",
  "rejectReason": "",
  "errorCode": "",
  "errorMessage": ""
}
FieldTypeDescription
eventTypestringEvent type: "orderEvent"
notifyIdLongSerial number of the event message
connectionIdstringClient stream connection session identifier
clientRequestIdstringOrder identifier for the day, auto-generated if not supplied. Used to match against the client's original order
orderIdstringOrder identifier recorded in the trading system
symbolstringSecurities symbol
sidestringOrder side (B → BUY / S → SELL)
orderTypestringOrder type (LO, ATO, ATC,...)
accountNostringTrading account number
pricestringPrice
quantitynumberQuantity
cancelQtynumberCanceled quantity
osQtynumberOutstanding (unmatched) quantity
filledQtynumberFilled/matched quantity
inputTimestringTime the order was received (standard format)
modifiedTimestringTime the order status was modified/updated (standard format)
orderStatusstringOrder status, refer to the order status table
rejectReasonstringRejection reason
errorCodestringOrder error code
errorMessagestringOrder error information

Order Match Event

Order match event — triggered when an order is matched (partially or fully).

{
  "eventType": "orderMatchEvent",
  "notifyId": 1061597,
  "connectionId": "connection_id_value",
  "clientRequestId": "91530521",
  "orderId": "26022601219922",
  "symbol": "MSR",
  "side": "S",
  "accountNo": "Q276811",
  "matchPrice": "43100.0",
  "matchQty": 500,
  "matchTime": "2026/03/01 14:20:55"
}
FieldTypeDescription
eventTypestringEvent type: "orderMatchEvent"
notifyIdLongSerial number of the event message
connectionIdstringClient stream connection session identifier
clientRequestIdstringOrder identifier for the day, auto-generated if not supplied. Used to match against the client's original order
orderIdstringOrder identifier recorded in the trading system
symbolstringSecurities symbol
sidestringOrder side (B → BUY / S → SELL)
accountNostringTrading account number
matchPricestringMatched price
matchQtynumberMatched quantity
matchTimestringMatch time (standard format)

Client Portfolio Event

Portfolio update event — triggered when account balance or assets change.

{
  "eventType": "clientPortfolioEvent",
  "notifyId": 1023456,
  "connectionId": "CONN-8899-XYZZ",
  "symbol": "VND",
  "accountNo": "0123456789",
  "longQty": 1500,
  "shortQty": 500,
  "net": 1000,
  "bidAvgPrice": "12.35",
  "askAvgPrice": "12.40",
  "tradePrice": "12.38",
  "marketPrice": "12.45",
  "floatingPL": "1500.75",
  "tradingPL": "2500.50"
}
FieldTypeDescription
eventTypestringEvent type: "clientPortfolioEvent"
notifyIdLongSerial number of the event message
connectionIdstringClient stream connection session identifier
symbolstringSecurities symbol
accountNostringAccount number
longQtynumberLong position
shortQtynumberShort position
netnumberNet position (long - short)
bidAvgPricestringAverage buy price
askAvgPricestringAverage sell price
tradePricestringMatched price
marketPricestringMarket price
floatingPLstringUnrealized profit/loss
tradingPLstringRealized profit/loss

FCO Event (Conditional Order)

Conditional order event (FCO — FastConnect Conditional Order) — triggered when a conditional order changes status (initialized, activated, matched, canceled, etc.).

FCO Events are delivered on the same order streaming channel — the client receives them via the onClientPortfolioEvent binding.

client.bind(client.events.onClientPortfolioEvent, function (e, data) {
  // Handle FCO event
  console.log(e + ": ");
  console.log(JSON.stringify(data));
});

Example FCO Event Response:

{
  "type": "fcoEvent",
  "data": {
    "fcoId": "7528ac20-a340-4233-8bb7-a2379fc3c638",
    "notifyID": 1249008,
    "processStatus": "INIT",
    "matchedQuantity": 0,
    "isPlaceOrder": false,
    "instrumentID": "ssi",
    "quantity": 4000,
    "price": "MP",
    "account": "1231496",
    "updatedTime": "1751966448000",
    "status": "200",
    "message": "Success",
    "username": "123149"
  }
}
FieldTypeDescriptionValid Values / Format
typestringEvent type"fcoEvent"
dataobjectEvent detail payload—
data.fcoIdstringConditional order IDUUID
data.notifyIDnumberNotification ID—
data.processStatusstringConditional order processing statusSee FCO Reference
data.matchedQuantitynumberMatched quantity—
data.isPlaceOrderbooleanWhether a child order has been placedtrue: A real order was placed (appears in Orderbook). false: No real order placed yet
data.instrumentIDstringSecurities symbol. For derivatives, use generic or specific codes: 1M, 2M, 1Q, 2Q, VN30FYYMM—
data.quantitynumberDesired order quantity—
data.pricestringOrder price (in VND)Numeric (e.g., "23500") or "MP", "MOK", "MTL"
data.accountstringSub-account for the order (e.g., account ending in 8 or 6)—
data.updatedTimestringUpdate time (Unix timestamp in milliseconds)"1751966448000"
data.statusstringStatus codeSee Error Codes
data.messagestringResult or error message—
data.usernamestringSSI user ID—

See also

On this page