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=api_key&ACCESS_TOKEN=jwtToken

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 parameters

  • Available Actions (action) : 1 = subscribe , 0 = unsubscribe, mode
  • Available Values (mode): 1 = LTP, 2 = Quote, 3 = Snap Quote
  • Available Exchange Types (exchangeType): 1 = NSECM, 2 = NSEFO, 3 = BSECM, 4 = BSEFO, 13 = NSECD

Samples :

{
    "correlationID": "Optional Field",
    "action": 1,
    "params": {
        "mode": 3,
        "tokenList": [
            {
                "exchangeType": 1,
                "tokens": [
                    "22",
                    "1333"
                ]
            }
        ]
    }
}

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 byte [byte] are for number of packets in the message.
  • The next two bytes [byte] 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 | [long]: 8 Bytes | [double]: 8 Bytes

Quote Packet Structure: (379 bytes)

Field Type Bytes
Subscription Mode [byte[1]] 0 - 1
Exchange Type [byte[1]] 1 - 2
Token [byte[25]] 2 - 27
Sequence Number [long] 27 - 35
Exchange Timestamp [long] 35 - 43
LTP [long] 43 - 51
Last Traded Qty [long] 51 - 59
Average Traded Price [long] 59 - 67
Volume Traded Today [long] 67 - 75
Total Buy Qty [double] 75 - 83
Total Sell Qty [double] 83 - 91
Open [long] 91 - 99
High [long] 99 - 107
Low [long] 107 - 115
Close [long] 115 - 123
Last Traded Timestamp [long] 123 - 131
Open Interest [long] 131 - 139
Open Interest Percent [long] 139 - 147
Market Depth [byte[200]] 147 - 347
Upper Circuit Limit [long] 347 - 355
Lower Circuit Limit [long] 355 - 363
52 Week High [long] 363 - 371
52 Week Low [long] 371 - 379

Market Depth Structure: (200 Bytes)

Field Type Bytes
Buy/Sell Flag 1 short 147 - 149
Bid Qty 1 long 149 - 157
Bid Price 1 long 157 - 165
Bid Number Of Orders 1 short 165 - 167
Buy/Sell Flag 2 short 167 - 169
Bid Qty 2 long 169 - 177
Bid Price 2 long 177 - 185
Bid Number Of Orders 2 short 185 - 187
Buy/Sell Flag 3 short 187 - 189
Bid Qty 3 long 189 - 197
Bid Price 3 long 197 - 205
Bid Number Of Orders 3 short 205 - 207
Buy/Sell Flag 4 short 207 - 209
Bid Qty 4 long 209 - 217
Bid Price 4 long 217 - 225
Bid Number Of Orders 4 short 225 - 227
Buy/Sell Flag 5 short 227 - 229
Bid Qty 5 long 229 - 237
Bid Price 5 long 237 - 245
Bid Number Of Orders 5 short 245 - 247
Buy/Sell Flag 1 short 247 - 249
Ask Qty 1 long 249 - 257
Ask Price 1 long 257 - 265
Ask Number Of Orders 1 short 265 - 267
Buy/Sell Flag 2 short 267 - 269
Ask Qty 2 long 269 - 277
Ask Price 2 long 277 - 285
Ask Number Of Orders 2 short 285 - 287
Buy/Sell Flag 3 short 287 - 289
Ask Qty 3 long 289 - 297
Ask Price 3 long 297 - 305
Ask Number Of Orders 3 short 305 - 307
Buy/Sell Flag 4 short 307 - 309
Ask Qty 4 long 309 - 317
Ask Price 4 long 317 - 325
Ask Number Of Orders 4 short 325 - 327
Buy/Sell Flag 5 short 327 - 329
Ask Qty 5 long 329 - 337
Ask Price 5 long 337 - 345
Ask Number Of Orders 5 short 345 - 347