Live Order Update
Realtime order updates of all your orders can be received directly via WebSocket in your system. Once you connect to the WebSocket and authorise, all order updates in your acount will get reflected real time via the stream.
With this update stream, you can know about status, traded price, quantity and other details about your orders.
The messages sent over this WebSocket will be JSON.
Establishing Connection
To establish connection with DhanHQ Live Order Update, you can connect to the below endpoint using WebSocket library.
wss://api-order-update.dhan.co
While establishing connection, you need to send Authorisation Message for connection.
For Individual
You can receive order updates for all orders placed via your account, irrespective of the platform via which it was placed.
Authorisation message structure
{
"LoginReq":{
"MsgCode": "42",
"ClientId":"1000000001",
"Token":"JWT"
},
"UserType: "SELF"
}
Parameters
Field | Type | Description |
LoginReq required |
{}, string | JSON for adding Client ID and Access Token |
MsgCode required |
int | Message Code for getting Order Updates42 by default
|
ClientId required |
string | User specific identification generated by Dhan |
Token required |
string | Access Token generated for user |
UserType required |
string | SELF for individual users |
For Partners
Platforms can receive order updates originating for all users connected to their platform/app for which Partner Login module needs to be used.
Authorisation message structure
{
"LoginReq":{
"MsgCode": "42",
"ClientId":"1000000001",
"Token":"partner_id"
},
"UserType: "PARTNER",
"Secret": "partner_secret"
}
Parameters
Field | Type | Description |
LoginReq required |
{}, string | JSON for adding Client ID and Access Token |
MsgCode required |
int | Message Code for getting Order Updates42 by default
|
ClientId required |
string | User specific identification generated by Dhan |
Token required |
string | partner_id generated for the partner |
UserType required |
string | PARTNER for partner platforms |
Secret required |
string | partner_secret generated for the partner |
Order Update
Order Update messages are sent via WebSocket in below structure.
Structure
{
"Data": {
"series": "EQ",
"goodTillDaysDate": "2024-09-11",
"instrumentType": "EQ",
"refLtp": 13.21,
"tickSize": 0.01,
"algoId": "0",
"multiplier": 1
"Exchange": "NSE",
"Segment": "E",
"Source": "N",
"SecurityId": "14366",
"ClientId": "1000000001",
"ExchOrderNo": "1400000000404591",
"OrderNo": "1124091136546",
"Product": "C",
"TxnType": "B",
"OrderType": "LMT",
"Validity": "DAY",
"DiscQuantity": 1,
"DiscQtyRem": 1,
"RemainingQuantity": 1,
"Quantity": 1,
"TradedQty": 0,
"Price": 13,
"TriggerPrice": 0,
"TradedPrice": 0,
"AvgTradedPrice": 0,
"AlgoOrdNo": ,
"OffMktFlag": "0",
"OrderDateTime": "2024-09-11 14:39:29",
"ExchOrderTime": "2024-09-11 14:39:29",
"LastUpdatedTime": "2024-09-11 14:39:29",
"Remarks": "NR",
"MktType": "NL",
"ReasonDescription": "CONFIRMED",
"LegNo": 1,
"Instrument": "EQUITY",
"Symbol": "IDEA",
"ProductName": "CNC",
"Status": "Cancelled",
"LotSize": 1,
"StrikePrice": ,
"ExpiryDate": "0001-01-01 00:00:00",
"OptType": "XX",
"DisplayName": "Vodafone Idea",
"Isin": "INE669E01016",
"Series": "EQ",
"GoodTillDaysDate": "2024-09-11",
"RefLtp": 13.21,
"TickSize": 0.01,
"AlgoId": "0",
"Multiplier": 1
},
"Type": "order_alert"
}
Parameters
Field | Type | Description |
Exchange | string | Exchange in which order is placed |
Segment | string | Segment for which order is placed |
Source | string | Platform via which order is placed - P for API Orders
|
SecurityId | string | Exchange standard ID for each scrip. Refer here |
ClientId | string | User specific identification generated by Dhan |
ExchOrderNo | string | Order specific identification generated by Exchange |
OrderNo | string | Order specific identification generated by Dhan |
Product | enum string | Product type of tradeC for CNC, I for INTRADAY, M for MARGIN, F for MTF , V for CO, B for BO |
TxnType | enum string | The trading side of transaction B for Buy S for Sell |
OrderType | enum string | Order TypeLMT for Limit MKT for Market SL for Stop Loss SLM for Stop Loss |
Validity | enum string | Validity of OrderDAY
IOC |
DiscQuantity | int | Number of shares visible |
DiscQtyRem | int | Disclosed quantity pending for execution |
RemainingQuantity | int | Quantity pending for execution |
Quantity | int | Total order quantity placed |
TradedQty | int | Actual quantity executed on exchange |
Price | float | Price at which order is placed |
TriggerPrice | float | Price at which order is triggered, for SL-M, SL-L, CO & BO |
TradedPrice | float | Price at which trade of an order is executed |
AvgTradedPrice | float | Average trade price of an order (this will be different from `Traded Price` in case of partial execution) |
AlgoOrdNo | float | Entry leg order number to track Target and Stop Loss leg (in case of BO and CO ) |
OffMktFlag | string | `1` in case of AMO order else `0` |
OrderDateTime | string | Time at which the order is received by Dhan |
ExchOrderTime | string | Time at which order is placed on Exchange |
LastUpdatedTime | string | Last update time of any order modification or trade |
Remarks | string | Additional remarks sent along while placing order |
MktType | string | NL for Normal MarketAU , A1 and A2 for Auction Market |
ReasonDescription | string | Order rejection reason |
LegNo | int | 1 for Entry Leg2 for Stop Loss Leg3 for Target Leg |
Instrument | string | Instrument in which order is placed - here |
Symbol | string | Symbol in which order is placed - Refer here |
ProductName | string | Product type of the order placed - here |
Status | enum string | Last updated status of the order TRANSIT
PENDING
REJECTED
CANCELLED
TRADED
EXPIRED |
LotSize | int | Lot Size in case of Derivatives |
StrikePrice | float | Strike Price in which order is placed in Option contract |
ExpiryDate | string | Expiry Date of the contract in which order is placed |
OptType | string | `CE` or `PE` in case of Option contract |
DisplayName | string | Name of instrument in which order is placed - Refer here |
Isin | string | ISIN of the instrument in which order is placed |
Series | string | Exchange series of the instrument |
GoodTillDaysDate | string | Order validity in case of Forever Order |
RefLtp | float | LTP at time of order update |
TickSize | float | Tick size of the instrument |
AlgoId | string | Exchange ID for special order types |
Multiplier | int | In case of commodity and currency contracts |
Note: For description of enum values, refer Annexure