Skip to content

Forever Order

Users can create and manage Forever Orders or Good Till Triggered orders using this set of APIs.

POST /forever/orders Create Forever Order
PUT /forever/orders/{order-id} Modify existing Forever Order
DELETE /forever/orders/{order-id} Cancel existing Forever Order
GET /forever/orders Retrieve an array of all existing forever orders

Create Forever Order

This API helps you create a new Forever Order.

    curl --request POST \
    --url https://api.dhan.co/v2/forever/orders \
    --header 'Accept: application/json' \
    --header 'Content-Type: application/json' \
    --header 'access-token: ' \
    --data '{Request JSON}'


Request structure

{
    "dhanClientId": "1000000132",
    "correlationId": "",
    "orderFlag": "OCO",
    "transactionType": "BUY",
    "exchangeSegment": "NSE_EQ",
    "productType": "CNC",
    "orderType": "LIMIT"
    "validity": "DAY",
    "securityId": "1333",
    "quantity": 5,
    "disclosedQuantity": 1,
    "price": 1428,
    "triggerPrice": 1427,
    "price1": 1420,
    "triggerPrice1": 1419,
    "quantity1": 10
}


Parameters

Field Type Description
dhanClientId
required
string User specific identification generated by Dhan
correlationId string The user/partner generated id for tracking back
orderFlag
required
string Order Flag OCO for OCO order and SINGLE for Forever Order
SINGLE OCO
transactionType
required
string The trading side of transaction
BUY  SELL
exchangeSegment
required
string Exchange & Segment
NSE_EQ  NSE_FNO   BSE_EQ  NSE_FNO 
productType
required
string Product type
CNC  MTF 
orderType
required
enum string Order Type
LIMIT  MARKET 
validity
required
string Validity of Order for execution
DAY IOC
securityId
required
string Exchange standard ID for each scrip. Refer here
quantity
required
int Number of shares for the order
disclosedQuantity int Number of shares visible (Keep more than 30% of quantity)
price
required
float Price at which order is placed
triggerPrice
required
float Price at which order is to be triggered
price1
conditionally required
float Target price for OCO order
triggerPrice1
conditionally required
float Target trigger price For OCO order
quantity1
conditionally required
integer Target Quantity for OCO order

Response Structure

{
    "orderId": "5132208051112",
    "orderStatus": "PENDING"
}


Parameters

Field Type Description
orderId string Order specific identification generated by Dhan
orderStatus string Order Status
TRANSIT PENDING REJECTED CANCELLED TRADED EXPIRED CONFIRM

Modify Forever Order

Users can take use of this API to make changes to already created forever orders. The variables that can be modified are price, quantity, order type, disclosed quantity, trigger price & validity.

curl --request PUT \
--url https://api.dhan.co/v2/forever/orders/{order-id} \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'access-token: adad' \
--data '{Request JSON}'


Requested Structure

{
    "dhanClientId": "1000000132",
    "orderId": "5132208051112",
    "orderFlag": "SINGLE",
    "orderType": "LIMIT",
    "legName": "TARGET_LEG",
    "quantity": 15,
    "price": 1421,
    "disclosedQuantity":1,
    "triggerPrice": 1420,
    "validity": "DAY"
}

Parameters

Field Type Description
dhanClientId
required
string User specific identification generated by Dhan
orderId
required
enum string Order specific identification generated by Dhan
orderFlag
required
string Order Flag OCO for OCO order and SINGLE for Forever Order
SINGLE OCO
orderType
required
enum string Order Type
LIMIT MARKET STOP_LOSS STOP_LOSS_MARKET
legName
required
string Order leg of Forever Order where modification is to be done
ENTRY_LEG - For Single and First leg of OCO
TARGET_LEG - For Second leg of OCO
quantity
required
int Number of shares for the order
price
required
float Price at which order is placed
disclosedQuantity int Number of shares visible (Keep more than 30% of quantity)
triggerPrice
required
float Price at which order is to be triggered
validity
required
string Validity of Order for execution
DAY IOC

Response Structure

{
    "orderId": "5132208051112",
    "orderStatus": "PENDING"
}


Parameters

Field Type Description
orderId string Order specific identification generated by Dhan
orderStatus string Last updated status of the order
TRANSIT PENDING REJECTED CANCELLED TRADED EXPIRED CONFIRM

Delete Forever Order

This API lets you delete pending Forever Order using the Order ID.

curl --request DELETE \
--url https://api.dhan.co/v2/forever/orders/{order-id} \
--header 'Accept: application/json' \
--header 'access-token: {JWT}'


Request Structure

No Body


Response Structure

{
    "orderId": "5132208051112",
    "orderStatus": "CANCELLED"
}


Parameters

Field Type Description
orderId string Order specific identification generated by Dhan
orderStatus string Order Status
TRANSIT PENDING REJECTED CANCELLED TRADED EXPIRED CONFIRM

All Forever Order Detail

Users can retrieve an array of all existing Forever Orders in their account using this API.

curl --request GET \
--url https://api.dhan.co/v2/forever/all \
--header 'Accept: application/json' \
--header 'access-token: {JWT}' \


Request Structure

No Body


Response Structure

[
    {
        "dhanClientId": "1000000132",
        "orderId": "1132208051115",
        "orderStatus": "CONFIRM",
        "transactionType": "BUY",
        "exchangeSegment": "NSE_EQ",
        "productType": "CNC",
        "orderType": "SINGLE",
        "tradingSymbol": "HDFCBANK",
        "securityId": "1333",
        "quantity": 10,
        "price": 1428,
        "triggerPrice": 1427,
        "legName": "ENTRY_LEG",
        "createTime": "2022-08-05 12:41:19",
        "updateTime": null,
        "exchangeTime": null,
        "drvExpiryDate": null,
        "drvOptionType": null,
        "drvStrikePrice": 0
    }
]


Parameters

Field Type Description
dhanClientId string User specific identification generated by Dhan
orderId string Order specific identification generated by Dhan
orderStatus enum string Last updated status of the order
TRANSIT PENDING REJECTED CANCELLED TRADED EXPIRED CONFIRM
transactionType enum string The trading side of transaction
BUY SELL
exchangeSegment enum string Exchange & Segment
NSE_EQ  NSE_FNO   BSE_EQ  MCX_COMM
productType enum string Product type of trade
CNC  INTRADAY  MARGIN  CO BO
orderType enum string Order Type
SINGLE OCO
tradingSymbol string Symbol of the instrument in which forever order is placed
securityId string Exchange standard ID for each scrip. Refer here
quantity int Number of shares for the order
price float Price at which order is placed
triggerPrice float Price at which order is to be triggered
legName string Order leg of Forever Order
ENTRY_LEG - For Single and First leg of OCO
TARGET_LEG - For Second leg of OCO
createTime string Time at which the Forever Order is created
updateTime string Time at which the Forever Order is updated
exchangeTime string Time at which order reached at exchange end
drvExpiryDate string Contract Expiry Date for Derivative contract
drvOptionType enum string Type of Option
CALL  PUT 
drvStrikePrice float Strike Price in case of Option Contract

Note: For description of enum values, refer Annexure