Websocket

To receive quotes for instruments across all exchanges during live market hours,the websocket API is the best to use in terms of speed, latency, resource consumption and bandwidth. A quote consists of fields such as open, high, low, close, last traded price, 5 levels of bid/offer market depth data etc.

Connecting to the Websocket endpoint:
WebsocketConnect(ws://Domain:Port?api_key=<API_KEY>&request_token=<REQUEST_TOKEN>)

To establish a connection, you have to pass two query parameters, api_key and Request _token

For Example:

ws://inmob.stoxkart.com:7763/?api_key=H0qppb0kyqLfUPIg&request_token=26dbbc62c663a2d3c0bc2e6c267cc82a88aa15c85f8eb2c274bd579fa4d2145c

Following are the various type of requests which can be sent . Every packet received will have a header to identify the packet followed by structure to be received.

For Example:- If in response header the “MsgCode” field contains 61 which means it is trade response then refer “LTP_struct” response structure.

1.1 Exchange segment wise codes

ExchangeMarket_Segment_id (script file)Market_Segment_id (for websocket)
NSE Cash11
NSE Derivatives22
BSE Cash34
MCX Futures55
MCX Spot65
NSECDS Futures133
NSECDS SPOT143

1.2 Request/Response codes

MODECode
LTP61
QUOTE62
FULL63
IDXLTP64
IDXQUOTE65
IDXFULL66
MKT_STATUS29
SubcribeFeedDisconnect11
SubcribeLTPAddStock71
SubcribeQUOTEAddStock72
SubcribeFULLAddStock73
SubcribeIDXLTPAddStock74
SubcribeIDXQUOTEAddStock75
SubcribeIDXFULLAddStock76
HeartBeat14
SubcribeLtpDelStock81
SubcribeQuotedelStock82
SubcribeFullDelStock83
SubcribeIdxLtpDelStock84
SubcribeIdxQuoteDelStock85
SubcribeIdxFullDelStock86

1.3 Request Structures

LayoutKind.Sequential, Pack = 1 Length=83
INT_MKTDATA_REQ_HEADER
StructureOffset
public byte iRequestCode;
-Request code as per request. Codes mentioned in request code section
0-1
public ushort iMsgLength;
- Total length of packet which is to sent
1-3
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)] public string sClientId;
- Client id with which user is logging in application
- Format : CLIENTID-SOURCE-BROKERID
-Source : Website – W mWeb – M Android – N iOS – I Admin
– A TWS – R OWS – O
3-33
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 50)] public string sAuthToken;
-Authentication token where auth is mandatory else blank
33-83
LayoutKind.Sequential, Pack = 1 Length=129
INT_WATCHADDDELSTK_REQ_SINGLE
StructureOffset
public INT_MKTDATA_REQ_HEADER bHeader;
- Header sub structure
0-83
public byte ExchSeg;
-Exch Segid for which request in sent. ExchSeg code is mention in table above
83-84
public int secIdxCode;
-Default value -1 kept for future use
84-88
public byte ScripCount;
-Default value 1
88-89
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] public string WName;
-Watchlist name
89-109
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public SCRIPID scripId;
- scrip id to subscribe/unsubscribe
109-129

1.4 Response Structure

LayoutKind.Sequential, Pack = 1 Length=10
BCAST HEADER
StructureOffset
public byte ExchSeg;
-Exch Seg code for which broadcast is received.
Mentioned in exch seg code table above
0
public int MsgLength;
-Length of packet to be received
1-4
public byte MsgCode;
-Msg code to identify what type of packet has arrived. Refer to response code table
5-6
public uint ScripId;
-Security for which broadcast is received
7-10
LayoutKind.Sequential, Pack = 1 Length=32
LTP_struct
StructureOffset
public BCAST_HEADER bHeader;0-9
public float LTP;
-Last Trade Price
10-13
public int LTT;
-Last Trade time
14-17
public uint iSecId;
- Security for which broadcast is received
18-21
public byte traded;
-1 for traded
22
public byte mode;
-msgcode of LTP
23
public float fchange;
-Change of price
24-27
public float fperChange;
-change percentage price
28-31
LayoutKind.Sequential, Pack = 1 Length=76
QUOTE MODE
StructureOffset
public BCAST_HEADER bHeader;0-9
public float LTP;
-Last trade of stock
10-13
public int LTT;
-Last Trade time
14-17
public uint iSecId;
- Security for which broadcast is received
18-21
public byte traded;
-1 for traded
22
public byte mode;
-msgcode of Quote
23
Public int LTQ
-Last traded quantity
24-27
public float APT;
-Average traded price
28-31
public float Vtraded;
-volume traded
32-35
Public uint TotalBuyQ;
-Total buy Quantity
36-39
Public uint TotalSellQ Total sell Quantity40-43
public float fOpen;
-open price
44-47
public float fClose;
-close price
48-51
public float fHigh;
-high price
52-55
public float fLow;
-low price
56-59
public float fperChange;
-change percentage price
60-63
public float fchange;
-Change price
64-67
public float f52WKHigh;
-52 week high
68-71
public float f52WKLow;
-52 week low
72-75
LayoutKind.Sequential, Pack = 1 Length=52
INDEX QUOTE MODE
StructureOffset
public BCAST_HEADER bHeader;0-9
public float LTP;
-Last trade of stock
10-13
public uint iSecId;
- Security for which broadcast is received
14-17
public byte traded;
-0 for nontraded
18
public byte mode;
-msgcode of index quote
19
public float fOpen;
-open price
20-23
public float fClose;
-close price
24-27
public float fHigh;
-high price
28-31
public float fLow;
-low price
32-35
public float fperChange;
-change percentage price
36-39
public float fchange;
-Change price
40-43
public float f52WKHigh;
-52 week high
44-47
public float f52WKLow;
-52 week low
48-51
LayoutKind.Sequential, Pack = 1 Length=20
MBP_ROW_STRUCT
StructureOffset
public uint iBuyqty;
-Bid quantity
0-3
public uint iSellqty;
-Ask quantity
4-7
public ushort iBuyordno;
-Number of buy orders
8-9
public ushort iSellordno;
-Number of Sell orders
10-11
public ushort fBuyprice;
-Bid price
12-15
public float fSellprice;
-Ask price
16-19
LayoutKind.Sequential, Pack = 1 Length=184
Full MODE
StructureOffset
public BCAST_HEADER bHeader;0-9
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
public MBP_ROW_STRUCT[] submbp;
10-109
public float LTP;
-Last Trade Price
110-113
public int LTT;
-Last Trade time
114-117
public uint iSecId;
- Security for which broadcast is received
118-121
public byte traded;
-1 for traded
122
public byte mode;
-msgcode of fullmode
123
Public int LTQ
-Last traded quantity
124-127
public float APT;
-Average traded price
128-131
public float Vtraded;
-volume traded
132-135
Public uint TotalBuyQ
-Total buy Quantity
136-139
Public uint TotalSellQ
-Total sell Quantity
140-143
public float fOpen;
-open price
144-147
public float fClose;
-close price
148-151
public float fHigh;
-high price
152-155
public float fLow;
-low price
156-159
public float fperChange;
-Change percentage price
160-163
public float fchange;
-Change price
164-167
public float f52WKHigh;
-52 week high
168-171
public float f52WKLow;
-52 week low
172-175
public int OI
-OI
176-179
public int OIChange
-OI change
180-183
LayoutKind.Sequential, Pack = 1 Length=184
INDEX Full MODE
StructureOffset
public BCAST_HEADER bHeader;0-9
public float LTP;
-Last trade of stock
10-13
public uint iSecId;
- Security for which broadcast is received
14-17
public byte traded;
-0 for NonTrade
18
public byte mode;
-Mode(Full)
19
public float fOpen;
-open price
20-23
public float fClose;
-close price
24-27
public float fHigh;
-high price
28-31
public float fLow;
-low price
32-35
public float fperChange;
-change percentage price
36-39
public float fchange;
-Change price
40-43
public int LTT;
-we don’t pass any value in this tag but still you need to add this in your structure
44-47
LayoutKind.Sequential, Pack = 1 Length=17
Market_Status
StructureOffset
public BCAST_HEADER bHeader;0-9
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 3)]
public string Mkt_Type;
10-13
public float Mkt_Status;14-17
Possible Market_typeType
Normal1
Oddlot2
Spot3
Aution4
CallAution15
CallAution26
Possible Market_StatusType
Pre-open start1
Pre-Open End2
Open3
Close4
Postclosestart5
PostCloseEnd6

1.5 CONNECTION MODES

Add LTP mode

Send this request to subscribe feed for stocks. On sending this request you will start receiving LTP mode Packet

Request Code: 72 Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

LTP MODEDescription
LTPLast Trade Price
LTTLast Trade time
fchangeChange od price
fperChangeChange percentage price

Add Quote mode

Send this request to subscribe feed for stocks. On sending this request you will start receiving QUOTE mode Packet.

Request Code: 72 Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

QUOTE MODEDescription
LTPLast trade of stock
LTQLast traded quantity
APTAverage traded price
VtradedVolume traded
TotalBuyQTotal buy quantity
Total sellTotal sell quantity
fOpenOpen price
fCloseClose price
fHighHigh price
fLowLow price
fperChangeChange percentage price
fchangeChange price
 f52WKHigh52 week high
 f52WKLow52 week low

Add full mode

Send this request to subscribe feed for stocks. On sending this request you will start receiving Full mode Packet.

Request Code: 73 Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

Full MODEDescription
float LTPLast Trade Price
int LTTLast Trade time
int LTQLast Trade quantity
Average traded priceAverage traded price
Volume tradedvolume traded
Total buy QuantityTotal buy Quantity
float fOpenOpen price
float fClosefloat fClose
float fHighhigh price
float fLowlow price
float fchangechange price
float f52WKHigh52 week high
float f52WKLow52 week low
int OIOI
int OIChangeOI change

Add Index LTP mode

Send this request to subscribe feed for stocks. On sending this request you will start receiving Index LTP mode Packet.

Request Code: 74 Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

Add Index Quote mode

Send this request to subscribe feed for stocks. On sending this request you will start receiving Index Quote mode Packet.

Request Code: 75 Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

INDEX QUOTE MODEDescription
float LTPLast trade of stock
float fOpenOpen price
float fCloseClose price
float fHighHigh price
float fLowLow price
float fperChangeChange percentage price
float fchange;Change price
float f52WKHigh52 week high
float f52WKLow52 week low
uint iBuyqtyBid quantity
uint iSellqtyAsk quantity
ushort iBuyordnoNumber of buy orders
ushort iSellordnoNumber of sell orders
float fBuypriceBid price
float fSellpriceAsk price

Add Index Full mode

Send this request to subscribe feed for stocks. On sending this request you will start receiving Index Full mode Packet.

Request Code: 76 Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

Full MODEDescription
float LTPLast Trade Price
int LTTLast Trade time
int LTQLast traded quantity
average traded priceAverage traded price
Volume tradedVolume traded
Total buy QuantityTotal buy Quantity
float fOpenopen price
float fClosefloat fClose
float fHighhigh price
float fLowlow price
float fchangechange price
float f52WKHigh52 week high
float f52WKLow52 week low
int OIOI
int OIChangeOIChange

Delete request for LTP

Send this request to unsubscribe feed for stocks

Request Code: 81
Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

Delete request for Quote

Send this request to unsubscribe feed for stocks

Request Code: 82
Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

Delete request for Full

Send this request to unsubscribe feed for stocks

Request Code: 83
Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

Delete request for Index LTP

Send this request to unsubscribe feed for stocks

Request Code: 84
Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

Delete request for Index Quote

Send this request to unsubscribe feed for stocks

Request Code: 85
Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE

Delete request for Index Full

Send this request to unsubscribe feed for stocks

Request Code: 86
Request Struct: INT_WATCHADDDELSTK_REQ_SINGLE