Skip to content

Market Data

Establishing Connection

To establish connection with Mirae WebSocket for Market Feed, you can to the below endpoint using WebSocket library.

wss://ws.mstock.trade?API_KEY=KEY&ACCESS_TOKEN=ACXX

Auth

  1. Authentication is done based on the Access Token generated in Login
  2. The Access Token is then passed in Query Paramater of the WebSocket URL
    1. Sample: ws://192.168.0.1:8003?ACCESS_TOKEN= abcxxx
    2. The IP:Port will be replaced with UAT and PROD urls.
  3. If the Access Token is not authenticated, the connection will not be made.
  4. Once the connection is successful, LOGIN:AccessToken has to be sent on the WebSocket connection to maintain the connection.
    1. If not sent, the connection will be auto disconnected in 10 seconds
    2. Sample: LOGIN:abcxxx

Request Structure -

Requests are simple JSON messages with two parameters, a (action) and v (value).

  • Available Actions (a) : subscribe, unsubscribe, mode
  • Available Values (v): These represents array of tokens in case of subscribe and unsubscribe. In case of mode, the available mode values are expected here.
  • Available Modes: ltp, quote, full

Subscribe :

{
    "a": "subscribe",
    "v": [
        55256,
        55412
    ]
}

unsubscribe :

{
    "a": "unsubscribe",
    "v": [
        55256,
        55412
    ]
}

mode :

{
    "a": "mode",
    "v": [
        "ltp"
    ]
}

Response Structure -

Quotes delivered via the API are always binary messages. These have to be read as bytes and then type-casted into appropriate quote data structures.

Each binary message consists of Header and the actual Quote Packet. The structure is as follows,

  • The first two bytes [short] are for number of packets in the message.
  • The next two bytes [short] are for number of total bytes in the quote packet.
  • The remaining bytes are for quote packet

Note

Please Note : 1. [short]: 2 Bytes | [int]: 4 Bytes

Quote Packet Structure: (64 Bytes + Market Depth)

Field Type Bytes
Token [int] 0 - 4
LTP [int] 4 - 8
Last Traded Qty [int] 8 - 12
Average Traded Price [int] 12 - 16
Volume Traded Today [int] 16 - 20
Total Buy Qty [int] 20 - 24
Total Sell Qty [int] 24 - 28
Open [int] 28 - 32
High [int] 32 - 36
Low [int] 36 - 40
Close [int] 40 - 44
Last Traded Timestamp [int] 44 - 48
Open Interest [int] 48 - 52
Open Interest High [int] 52 - 56
Open Interest Low [int] 56 - 60
Exchange Timestamp [int] 60 - 64
Market Depth [byte[]] 64 -184

Market Depth Structure: (120 Bytes)

Field Type Bytes
Bid Qty 1 [int] 64 - 68
Bid Price 1 [int] 68 - 72
Bid Number Of Orders 1 [short] 72 - 74
Padding [short] 74 - 76
Bid Qty 2 [int] 76 - 80
Bid Price 2 [int] 80 - 84
Bid Number Of Orders 2 [short] 84 - 86
Padding [short] 86 - 88
Bid Qty 3 [int] 88 - 92
Bid Price 3 [int] 92 - 96
Bid Number Of Orders 3 [short] 96 - 98
Padding [short] 98 - 100
Bid Qty 4 [int] 100 - 104
Bid Price 4 [int] 104 - 108
Bid Number Of Orders 4 [short] 108 - 110
Padding [short] 110 - 112
Bid Qty 5 [int] 112 - 116
Bid Price 5 [int] 116 - 120
Bid Number Of Orders 5 [short] 120 - 122
Padding [short] 122 - 124
Ask Qty 1 [int] 124 - 128
Ask Price 1 [int] 128 - 132
Ask Number Of Orders 1 [short] 132 - 134
Padding [short] 134 - 136
Ask Qty 2 [int] 136 - 140
Ask Price 2 [int] 140 - 144
Ask Number Of Orders 2 [short] 144 - 146
Padding [short] 146 - 148
Ask Qty 3 [int] 148 - 152
Ask Price 3 [int] 152 - 156
Ask Number Of Orders 3 [short] 156 - 158
Padding [short] 158 - 160
Ask Qty 4 [int] 160 - 164
Ask Price 4 [int] 164 - 168
Ask Number Of Orders 4 [short] 168 - 170
Padding [short] 170 - 172
Ask Qty 5 [int] 172 - 176
Ask Price 5 [int] 176 - 180
Ask Number Of Orders 5 [short] 180 - 182
Padding [short] 182 - 184

Index Packet Structure: (32 Bytes)

Specifically created for non tradable Index Tokens (Mentioned below)

Field Type Bytes
Token [int] 0 - 4
Last traded price [int] 4 - 8
High of the day [int] 8 - 12
Low of the day [int] 12 - 16
Open of the day [int] 16 - 20
Close of the day [int] 20 - 24
Price change [int] 24 - 28
Exchange timestamp [int] 28 - 32