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
Exchange | Market_Segment_id (script file) | Market_Segment_id (for websocket) |
---|---|---|
NSE Cash | 1 | 1 |
NSE Derivatives | 2 | 2 |
BSE Cash | 3 | 4 |
MCX Futures | 5 | 5 |
MCX Spot | 6 | 5 |
NSECDS Futures | 13 | 3 |
NSECDS SPOT | 14 | 3 |
1.2 Request/Response codes
MODE | Code |
---|---|
LTP | 61 |
QUOTE | 62 |
FULL | 63 |
IDXLTP | 64 |
IDXQUOTE | 65 |
IDXFULL | 66 |
MKT_STATUS | 29 |
SubcribeFeedDisconnect | 11 |
SubcribeLTPAddStock | 71 |
SubcribeQUOTEAddStock | 72 |
SubcribeFULLAddStock | 73 |
SubcribeIDXLTPAddStock | 74 |
SubcribeIDXQUOTEAddStock | 75 |
SubcribeIDXFULLAddStock | 76 |
HeartBeat | 14 |
SubcribeLtpDelStock | 81 |
SubcribeQuotedelStock | 82 |
SubcribeFullDelStock | 83 |
SubcribeIdxLtpDelStock | 84 |
SubcribeIdxQuoteDelStock | 85 |
SubcribeIdxFullDelStock | 86 |
1.3 Request Structures
LayoutKind.Sequential, Pack = 1 Length=83 INT_MKTDATA_REQ_HEADER | |
---|---|
Structure | Offset |
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 | |
---|---|
Structure | Offset |
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 | |
---|---|
Structure | Offset |
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 | |
---|---|
Structure | Offset |
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 | |
---|---|
Structure | Offset |
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 Quantity | 40-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 | |
---|---|
Structure | Offset |
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 | |
---|---|
Structure | Offset |
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 | |
---|---|
Structure | Offset |
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 | |
---|---|
Structure | Offset |
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 | |
---|---|
Structure | Offset |
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_type | Type |
---|---|
Normal | 1 |
Oddlot | 2 |
Spot | 3 |
Aution | 4 |
CallAution1 | 5 |
CallAution2 | 6 |
Possible Market_Status | Type |
---|---|
Pre-open start | 1 |
Pre-Open End | 2 |
Open | 3 |
Close | 4 |
Postclosestart | 5 |
PostCloseEnd | 6 |
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 MODE | Description |
---|---|
LTP | Last Trade Price |
LTT | Last Trade time |
fchange | Change od price |
fperChange | Change 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 MODE | Description |
---|---|
LTP | Last trade of stock |
LTQ | Last traded quantity |
APT | Average traded price |
Vtraded | Volume traded |
TotalBuyQ | Total buy quantity |
Total sell | Total sell quantity |
fOpen | Open price |
fClose | Close price |
fHigh | High price |
fLow | Low price |
fperChange | Change percentage price |
fchange | Change price |
f52WKHigh | 52 week high |
f52WKLow | 52 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 MODE | Description |
---|---|
float LTP | Last Trade Price |
int LTT | Last Trade time |
int LTQ | Last Trade quantity |
Average traded price | Average traded price |
Volume traded | volume traded |
Total buy Quantity | Total buy Quantity |
float fOpen | Open price |
float fClose | float fClose |
float fHigh | high price |
float fLow | low price |
float fchange | change price |
float f52WKHigh | 52 week high |
float f52WKLow | 52 week low |
int OI | OI |
int OIChange | OI 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 MODE | Description |
---|---|
float LTP | Last trade of stock |
float fOpen | Open price |
float fClose | Close price |
float fHigh | High price |
float fLow | Low price |
float fperChange | Change percentage price |
float fchange; | Change price |
float f52WKHigh | 52 week high |
float f52WKLow | 52 week low |
uint iBuyqty | Bid quantity |
uint iSellqty | Ask quantity |
ushort iBuyordno | Number of buy orders |
ushort iSellordno | Number of sell orders |
float fBuyprice | Bid price |
float fSellprice | Ask 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 MODE | Description |
---|---|
float LTP | Last Trade Price |
int LTT | Last Trade time |
int LTQ | Last traded quantity |
average traded price | Average traded price |
Volume traded | Volume traded |
Total buy Quantity | Total buy Quantity |
float fOpen | open price |
float fClose | float fClose |
float fHigh | high price |
float fLow | low price |
float fchange | change price |
float f52WKHigh | 52 week high |
float f52WKLow | 52 week low |
int OI | OI |
int OIChange | OIChange |
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