Need example JS Code of Option Trading api

Hi, This is shivam,

I have searched all official documents no where I found any sample code. It shows “string” number etc but what value they need? or in which format it requers is compeletely missing on documents. I request you to guide me hence it can help other coders and reduce confusins.

I want example json block for market order pacement of options. I have mentioed the question at the end of value for each field.

{
  dhanClientId: 1100158871,
  correlationId: '358482', // does it needs to be unique?
  transactionType: 'SELL',
  exchangeSegment: 'NSE_FNO',
  productType: 'MARGIN', // CNC, INTRADAY,MARGIN,MTF,CO,BO all applicable in Option ?
  orderType: 'MARKET',
  validity: 'DAY',
  quantity: 3, // quantity in Lot or net quantity? 
  drvExpiryDate: '2024-Jan-15', // format of date? '15-01-2024' ,  '2024-Jan-15' etc
  drvOptionType: 'CE', 
  drvStrikePrice: '46000',
  symbol: 'BANKNIFTY', // does it require full symbol if yes in which format ? BANKNIFTY-Jan2024-45700-PE BANKNIFTY01202445700PE etc ??
securityId: 51231 // is this still required or optional? If required how to get it programetically ? 

}

From above code and use case what are optional ? or is there any missing fields?

Error I get

{
    "errorCode": "INTERNAL_SERVER_ERROR",
    "httpStatus": "INTERNAL_SERVER_ERROR",
    "internalErrorCode": "RS-9005",
    "internalErrorMessage": null
}

Feedback:

  1. Provide one example of json object for each use case on documentation page like Option Marjet Order, Equity Cash order etc with real value for any symbol or strike price.

  2. Error messges are sometime not clear like todo mandatory fields etc.

:point_right:If anyone need link to download strike price / security id , it is available at https://images.dhan.co/api-data/api-scrip-master.csv .

Hey @mn016

Great to see you around after such a long time.

Have noted your feedback here, on the documentation. Although it might not be possible to add examples of each, will definitely try to make documentation more comprehensive.

To answer your questions here:

{
  dhanClientId: 1100158871,
  correlationId: '358482', // it can or cannot be unique, depends on how your system wants to assign value; recommended to keep it unique if you wish to use Order by Correlation Id API
  transactionType: 'SELL',
  exchangeSegment: 'NSE_FNO',
  productType: 'MARGIN', // Only CNC is not applicable for Options, as 'MARGIN' should be passed for carryforward trades
  orderType: 'MARKET',
  validity: 'DAY',
  quantity: 3, // quantity needs to be multiple of lot size
  price: 0, // in case you want to place market order
  drvExpiryDate: '2024-Jan-15', // non-mandatory
  drvOptionType: 'CE', // non-mandatory
  drvStrikePrice: '46000', // non-mandatory
  symbol: 'BANKNIFTY', // this is non-mandatory, can be passed as anything or skipped
  securityId: 51231 // securityId is mandatory, this is how the system places the order. You can skip 'symbol', 'drvStrikePrice', 'drvOptionType', etc. You can call the URL, load csv in a data frame and use the same programetically
}

Hope this helps!