On this page

Every order carries three fields that together decide how it behaves: prd, prctyp and ret. The source documentation lists their values without explaining any of them.

FieldDecides
prd - productWhat happens to the position at the end of the day, and how much margin it needs
prctyp - price typeHow the price is determined: your price, the market's price, or only after a trigger
ret - retentionHow long the order keeps trying before it gives up

prd - the product

What happens to the position at the end of the day, and how much margin it needs.

prdMeaning
CDelivery - shares settle into your demat account (CNC)
IIntraday - must be squared off the same day (MIS)
MMargin - carry-forward derivatives position (NRML)
HCover order - entry plus a compulsory stop-loss
BBracket order - entry plus a stop-loss and a target
SSpecial
PSpecial2
The three you will actually use

C - Delivery. You are buying to keep. The shares settle into your demat account and become a holding. You pay the full amount.

I - Intraday. You are buying to sell again today. You need less money up front, but the position must be closed before the market shuts - and if you do not close it, the broker will.

M - Margin. For futures and options you are carrying overnight. You post margin rather than the full contract value.

Intraday positions are closed for you

An I position left open near the close gets squared off automatically, at whatever price the market happens to be. You do not choose the price and you do not choose the timing.

If you intend to keep a position, either use C from the start or convert it with Product Conversion - which needs the extra margin available at the moment you convert.

Cover and bracket orders

H and B are not simple products. Each creates several linked orders, which is why they have their own exit endpoint.

These need their own fields, and their own exit

Set blprc for the stop-loss (both H and B), bpprc for the target (B only), and trailprc if you want the stop to follow the price.

To close one, use Exit Cover / Bracket Order. Plain Cancel Order would cancel one leg and leave the others live - which is how you end up with a naked stop-loss on a position you no longer hold.

prctyp - the order type

prctypMeaning
LMTLimit - fills at your price or better
MKTMarket - fills immediately at whatever the market offers
SL-LMTStop-loss limit - becomes a limit order once trgprc is hit
SL-MKTStop-loss market - becomes a market order once trgprc is hit
DSDisclosed quantity order
2LTwo-leg order - both legs sent together
3LThree-leg order - all three legs sent together
prctypprctrgprcAlso needs
LMTrequiredomit-
MKTSend "0"omitmkt_protection is advisable
SL-LMTrequiredrequiredKeep a gap between the two
SL-MKTSend "0"required-
2Lrequiredomittsym2, trantype2, qty2, prc2
3LrequiredomitThe 2L fields plus tsym3, trantype3, qty3, prc3
Limit or market?

Limit - you name the price. "Buy at 1000 or better." You might wait forever, but you will never pay more than 1000.

Market - you take whatever is there. It fills almost immediately, but in a thin market the price can be a long way from the last trade you saw.

For anything automated, prefer limit. A market order in a thinly traded option can fill at a startling price, and you will have agreed to it.

Market protection exists for exactly this

The mkt_protection field caps how far a market order may fill from the current price. The API specification says it applies to MKT orders on the BSE, BFO, BCS and MCX segments.

How a stop-loss works

StageWhat is happeningOrder status
You place itYou send SL-LMT with a trigger of 950 and a limit of 948.TRIGGER_PENDING
The market is above 950Nothing. The order is not in the market and cannot fill.TRIGGER_PENDING
The price touches 950The order is released into the market as a limit order at 948.OPEN
It finds a buyer at 948 or betterIt fills.COMPLETE
The price gaps straight through 948The order is live but unfillable at your limit. This is why SL-MKT exists.OPEN, unfilled
Trigger price and limit price are different numbers

For SL-LMT you send both. trgprc is the level that activates the order; prc is the price it then tries to fill at. Setting them equal often means the order activates and never fills, because by the time it triggers the market has already moved past your limit.

Leave a gap in the direction the price is moving.

ret - the validity

retMeaning
DAYValid for the rest of today's session
IOCImmediate or cancel - fill what you can now, cancel the rest
EOSEnd of session

Which values are accepted differs by exchange:

ExchangePermitted ret values
NSEDAY, IOC
BSEEOS, DAY, IOC
NFODAY, IOC
CDSDAY, IOC
NCXDAY, IOC
BFOEOS, DAY, IOC
There is no "good till cancelled"

No ret value keeps an ordinary order alive past today. For that you need a GTT order, which is a separate mechanism with its own endpoints.

Combinations that make sense

What you wantprdprctypret
Buy shares to keepCLMTDAY
Buy and sell the same dayILMTDAY
Get in immediately, price secondaryI or CMKTDAY
Limit a loss on an open positionmatch the positionSL-MKTDAY
Limit a loss, but not at any pricematch the positionSL-LMTDAY
Carry a futures position overnightMLMTDAY
Intraday with an automatic stopHLMTDAY
Intraday with a stop and a targetBLMTDAY
Fill what you can right now, cancel the restanyLMTIOC
A spread, both legs or neitherM2LDAY
Act only if the price reaches a level, days from nowanyanyUse a GTT order - no ret value survives the day

Check before you hard-code

Entitlements are per account

The lists above are what the API defines. What your account may use is narrower, and it is returned by User Details:

  • exarr - the exchanges enabled
  • orarr - the price types enabled
  • prarr - the products enabled, with the exchanges each is allowed on

An order form offering MCX to an account without MCX produces rejections that look like bugs in your code. Drive the dropdowns from the response.

Build the order form from the account's own entitlements
"""Derive the valid choices for an order form from User Details.

Hard-coding the lists produces rejections on accounts with different
entitlements, and those are hard to tell apart from bugs in your own code.
"""


def order_options(user_details, exchange):
  """Returns the products and order types valid for one exchange."""
  # prarr entries carry their own per-exchange allow-list, so a product
  # enabled on the account is not necessarily enabled everywhere.
  products = [
      {"value": p["prd"], "label": p["s_prdt_ali"]}
      for p in user_details.get("prarr", [])
      if exchange in p.get("exch", [])
  ]

  # orarr is a flat list with no per-exchange qualification. Note that the
  # documented sample includes "4L", which does not appear in the
  # documented prctyp list -- trust orarr, not the prctyp table.
  order_types = list(user_details.get("orarr", []))

  # The documentation gives retention per exchange; orarr does not cover it.
  retention = {
      "NSE": ["DAY", "IOC"],
      "NFO": ["DAY", "IOC"],
      "CDS": ["DAY", "IOC"],
      "NCX": ["DAY", "IOC"],
      "BSE": ["EOS", "DAY", "IOC"],
      "BFO": ["EOS", "DAY", "IOC"],
  }.get(exchange, ["DAY"])

  return {
      "exchanges": user_details.get("exarr", []),
      "products": products,
      "order_types": order_types,
      "retention": retention,
  }

Which fields each order type needs

FieldAlways requiredNotes
uid, actidyesYour user and account ID.
exch, tsymyesFrom the symbol master.
qtyyesA multiple of the lot size for derivatives.
prcyesSend "0" for MKT and SL-MKT. Must be a multiple of the tick size otherwise.
prd, trantype, prctyp, retyes-
trgprcOnly for SL ordersOmit it entirely for LMT and MKT.
bpprcOnly for prd=BThe profit target.
blprcOnly for prd=H or BThe stop-loss.
amoNever requiredSend "Yes" or omit it. Never send it empty.
remarksNever requiredStrongly recommended: it is the closest thing to an idempotency key this API has.

The full field list, with types and examples, is on the Place Order page.

Multi-leg orders

2L and 3L send two or three legs as a single order, so either all of them are placed or none is. Useful for spreads, where being filled on one leg and not the other is the thing you were trying to avoid.

LegSymbolSideQuantityPrice
Leg 1tsymtrantypeqtyprc
Leg 2tsym2trantype2qty2prc2
Leg 3 3L onlytsym3trantype3qty3prc3
Multi-leg must be enabled on the account

Check that 2L or 3L appears in orarr from User Details before offering it. Each leg's fields are mandatory for the type you chose: omitting tsym2 on a 2L order is a rejection.

Next

Esc
↑↓ navigate↵ openEsc close/ to search