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.
| Field | Decides |
|---|---|
prd - product | What happens to the position at the end of the day, and how much margin it needs |
prctyp - price type | How the price is determined: your price, the market's price, or only after a trigger |
ret - retention | How 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.
| prd | Meaning |
|---|---|
C | Delivery - shares settle into your demat account (CNC) |
I | Intraday - must be squared off the same day (MIS) |
M | Margin - carry-forward derivatives position (NRML) |
H | Cover order - entry plus a compulsory stop-loss |
B | Bracket order - entry plus a stop-loss and a target |
S | Special |
P | Special2 |
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.
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.
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
| prctyp | Meaning |
|---|---|
LMT | Limit - fills at your price or better |
MKT | Market - fills immediately at whatever the market offers |
SL-LMT | Stop-loss limit - becomes a limit order once trgprc is hit |
SL-MKT | Stop-loss market - becomes a market order once trgprc is hit |
DS | Disclosed quantity order |
2L | Two-leg order - both legs sent together |
3L | Three-leg order - all three legs sent together |
prctyp | prc | trgprc | Also needs |
|---|---|---|---|
LMT | required | omit | - |
MKT | Send "0" | omit | mkt_protection is advisable |
SL-LMT | required | required | Keep a gap between the two |
SL-MKT | Send "0" | required | - |
2L | required | omit | tsym2, trantype2, qty2, prc2 |
3L | required | omit | The 2L fields plus tsym3, trantype3, qty3, prc3 |
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.
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
| Stage | What is happening | Order status |
|---|---|---|
| You place it | You send SL-LMT with a trigger of 950 and a limit of 948. | TRIGGER_PENDING |
| The market is above 950 | Nothing. The order is not in the market and cannot fill. | TRIGGER_PENDING |
| The price touches 950 | The order is released into the market as a limit order at 948. | OPEN |
| It finds a buyer at 948 or better | It fills. | COMPLETE |
| The price gaps straight through 948 | The order is live but unfillable at your limit. This is why SL-MKT exists. | OPEN, unfilled |
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
| ret | Meaning |
|---|---|
DAY | Valid for the rest of today's session |
IOC | Immediate or cancel - fill what you can now, cancel the rest |
EOS | End of session |
Which values are accepted differs by exchange:
| Exchange | Permitted ret values |
|---|---|
| NSE | DAY, IOC |
| BSE | EOS, DAY, IOC |
| NFO | DAY, IOC |
| CDS | DAY, IOC |
| NCX | DAY, IOC |
| BFO | EOS, DAY, IOC |
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 want | prd | prctyp | ret |
|---|---|---|---|
| Buy shares to keep | C | LMT | DAY |
| Buy and sell the same day | I | LMT | DAY |
| Get in immediately, price secondary | I or C | MKT | DAY |
| Limit a loss on an open position | match the position | SL-MKT | DAY |
| Limit a loss, but not at any price | match the position | SL-LMT | DAY |
| Carry a futures position overnight | M | LMT | DAY |
| Intraday with an automatic stop | H | LMT | DAY |
| Intraday with a stop and a target | B | LMT | DAY |
| Fill what you can right now, cancel the rest | any | LMT | IOC |
| A spread, both legs or neither | M | 2L | DAY |
| Act only if the price reaches a level, days from now | any | any | Use a GTT order - no ret value survives the day |
Check before you hard-code
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 enabledorarr- the price types enabledprarr- 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.
"""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
| Field | Always required | Notes |
|---|---|---|
uid, actid | yes | Your user and account ID. |
exch, tsym | yes | From the symbol master. |
qty | yes | A multiple of the lot size for derivatives. |
prc | yes | Send "0" for MKT and SL-MKT. Must be a multiple of the tick size otherwise. |
prd, trantype, prctyp, ret | yes | - |
trgprc | Only for SL orders | Omit it entirely for LMT and MKT. |
bpprc | Only for prd=B | The profit target. |
blprc | Only for prd=H or B | The stop-loss. |
amo | Never required | Send "Yes" or omit it. Never send it empty. |
remarks | Never required | Strongly 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.
| Leg | Symbol | Side | Quantity | Price |
|---|---|---|---|---|
| Leg 1 | tsym | trantype | qty | prc |
| Leg 2 | tsym2 | trantype2 | qty2 | prc2 |
| Leg 3 3L only | tsym3 | trantype3 | qty3 | prc3 |
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.