Skip to main content

Orders

The order APIs let you place orders of different varities, modify and cancel pending orders, retrieve the daily order and more.

HTTP MethodEndpointDescriptionSection
POST/orders/:varietyPlace a new orderPlacing orders
PUT/orders/:variety/:order_idModify an existing orderModifying orders
DELETE/orders/:variety/:order_idCancel an orderCancelling orders
GET/ordersRetrieve all orders for the dayRetrieving orders
GET/orders/:order_idRetrieve an order's historyRetrieving an order's history
GET/tradesRetrieve all trades for the dayRetrieving all trades
GET/orders/:order_id/tradesRetrieve trades for a specific orderRetrieving an order's trades

Glossary of constants

Here are several of the constant enum values used for placing orders.

variety

  • regular
  • amo

order_type

  • LIMIT
  • SL - Stop-loss orders

product

  • CNC
  • NRML
  • MIS
  • MTF - Margin Trading Facility

validity

  • DAY
  • IOC
  • TTL

autoslice

  • true
  • false

Placing orders

Placing an order implies registering it with the OMS via the API. This does not guarantee the order's receipt at the exchange. The fate of an order is dependent on several factors including market hours, availability of funds, risk checks and so on. Under normal circumstances, order placement, receipt by the OMS, transport to the exchange, execution, and the confirmation roundtrip happen instantly.

When an order is successfully placed, the API returns an order_id. The status of the order is not known at the moment of placing because of the aforementioned reasons.

In case of non-MARKET orders that may be open indefinitely during the course of a trading day, it is not practical to poll the order APIs continuously to know the status. For this, postbacks are ideal as they sent order updates asynchronously as they happen.

Note: Successful placement of an order via the API does not imply its successful execution. To know the true status of a placed order, you should scan the order history or retrieve the particular order's current details using its order_id.

Order varieties

You can place orders of different varieties—regular orders, after market orders, cover orders, iceberg orders etc. See the list of varieties here.

Request:

curl https://api.blinkx.in/SmartApi/orders/regular \
-H "X-Version: 3" \
-H "Authorization: token api_key:access_token" \
-d "tradingsymbol=ACC" \
-d "exchange=NSE" \
-d "transaction_type=BUY" \
-d "order_type=LIMIT" \
-d "quantity=1" \
-d "product=MIS" \
-d "validity=DAY"

Response:

{
"status": "success",
"data": {
"order_id": "151220000000000"
}
}

Regular order parameters

These parameters are common across different order varieties.

ParameterDescription
tradingsymbolTrading symbol of the instrument
exchangeName of the exchange
transaction_typeBUY or SELL
order_typeOrder type (LIMIT, SL)
quantityQuantity to transact
productMargin product type
priceFor LIMIT orders
trigger_priceFor SL orders
disclosed_quantityQuantity to disclose publicly (for equity trades)
validityOrder validity (DAY, IOC, TTL)
validity_ttlOrder validity in minutes for TTL validity orders
iceberg_legsTotal number of legs for iceberg order variety
iceberg_quantitySplit quantity for each iceberg leg order
auction_numberAuction number for auction orders
market_protectionMarket protection percentage
autosliceAuto-slice large orders into smaller lots
tagAn optional tag to apply to an order to identify it

Modifying orders

As long as on order is open or pending in the system, certain attributes of it may be modified. It is important to sent the right value for :variety in the URL.

Request:

curl --request PUT https://api.blinkx.in/SmartApi/orders/regular/151220000000000 \
-H "X-Version: 3" \
-H "Authorization: token api_key:access_token" \
-d "order_type=LIMIT" \
-d "quantity=3" \
-d "validity=DAY"

Response:

{
"status": "success",
"data": {
"order_id": "151220000000000"
}
}

Regular order parameters

ParameterDescription
order_typeOrder type (LIMIT, SL)
quantityQuantity to transact
priceFor LIMIT orders
trigger_priceFor SL
disclosed_quantityQuantity to disclose publicly
validityOrder validity

Cover order (CO) parameters

ParameterDescription
order_idID of the order
pricePrice for LIMIT orders
trigger_priceTrigger price for stop loss

Note: For cover orders, only LIMIT order type modifications are allowed.

Cancelling orders

As long as on order is open or pending in the system, it can be cancelled.

Request:

curl --request DELETE \
"https://api.blinkx.in/SmartApi/orders/regular/151220000000000" \
-H "X-Version: 3" \
-H "Authorization: token api_key:access_token"

Response:

{
"status": "success",
"data": {
"order_id": "151220000000000"
}
}

Retrieving orders

The order history or the order book is transient as it only lives for a day in the system. When you retrieve orders, you get all the orders for the day including open, pending, and executed ones.

Request:

curl "https://api.blinkx.in/SmartApi/orders" \
-H "X-Version: 3" \
-H "Authorization: token api_key:access_token"

Response:

{
"status": "success",
"data": [
{
"placed_by": "XXXXXX",
"order_id": "100000000000000",
"exchange_order_id": "200000000000000",
"parent_order_id": null,
"status": "CANCELLED",
"status_message": null,
"status_message_raw": null,
"order_timestamp": "2021-05-31 09:18:57",
"exchange_update_timestamp": "2021-05-31 09:18:58",
"exchange_timestamp": "2021-05-31 09:15:38",
"variety": "regular",
"modified": false,
"exchange": "CDS",
"tradingsymbol": "USDINR21JUNFUT",
"instrument_token": 412675,
"order_type": "LIMIT",
"transaction_type": "BUY",
"validity": "DAY",
"product": "NRML",
"quantity": 1,
"disclosed_quantity": 0,
"price": 72,
"trigger_price": 0,
"average_price": 0,
"filled_quantity": 0,
"pending_quantity": 1,
"cancelled_quantity": 1,
"market_protection": 0,
"meta": {},
"tag": null,
"guid": "XXXXX"
}
]
}

Response attributes

AttributeDescription
order_idUnique order ID
parent_order_idParent order ID for multi-legged orders
exchange_order_idExchange generated order ID
modifiedIndicates if order was modified
placed_byUser ID that placed the order
varietyOrder variety
statusCurrent status of the order
tradingsymbolTradingsymbol of the instrument
exchangeExchange
instrument_tokenThe numerical identifier issued by the exchange
transaction_typeBUY or SELL
order_typeOrder type (LIMIT, SL)
productMargin product
validityOrder validity
pricePrice at which the order was placed
quantityQuantity ordered
trigger_priceTrigger price
average_priceAverage price at which the order was executed
pending_quantityPending quantity to be filled
filled_quantityQuantity that has been filled
disclosed_quantityQuantity to disclose publicly
order_timestampTimestamp at which the order was registered
exchange_timestampTimestamp at which the order was registered at the exchange
exchange_update_timestampTimestamp at which the order was last updated at the exchange
status_messageTextual description of the order's status
status_message_rawRaw message from RMS or OMS
cancelled_quantityQuantity that was cancelled
auction_numberAuction number (for auction orders)
metaMap of arbitrary fields for internal use
tagAn optional tag
guidGlobal unique identifier

Order statuses

The status field in the order response shows the current state of the order. The status values are largely self explanatory. The most common statuses are OPEN, COMPLETE, CANCELLED, and REJECTED.

An order can traverse through several interim and temporary statuses during its lifetime. For example, when an order is first placed or modified, it instantly passes through several stages before reaching its end state. Some of these are highlighted below:

  • PUT ORDER REQ RECEIVED
  • VALIDATION PENDING
  • OPEN PENDING
  • MODIFY VALIDATION PENDING
  • MODIFY PENDING
  • TRIGGER PENDING
  • CANCEL PENDING
  • AMO REQ RECEIVED

Tagging orders

Often, it may be necessary to tag and filter orders based on various criteria, for instance, to filter out all orders that came from a particular application or an api_key of yours. The tag field comes in handy here. It let's you send an arbitrary string while placing an order. This can be a unique ID, or something that indicates a particular type or context, for example. When the orderbook is retrieved, this value will be present in the tag field in the response.

Multi-legged orders (CO)

Cover orders are "multi-legged" orders, where, a single order you place (first-leg) may spawn new orders (second-leg) based on the conditions you set on the first-leg order. These orders have special properties, where the first-leg order creates a position. The position is exited when the second-leg order is executed or cancelled.

These second-leg orders will have a parent_order_id field indicating the order_id of its parent order, that is, the first-leg order. This field may be required while modifying or cancelling an open second-leg order.

Retrieving an order's history

Every order, right after being placed, goes through multiple stages internally in the OMS. Initial validation, RMS (Risk Management System) checks and so on before it goes to the exchange. In addition, an open order, when modified, again goes through these stages.

Request:

curl "https://api.blinkx.in/SmartApi/orders/171229000724687" \
-H "Authorization: token api_key:access_token"

Response:

{
"status": "success",
"data": [
{
"average_price": 0,
"cancelled_quantity": 0,
"disclosed_quantity": 0,
"exchange": "NSE",
"exchange_order_id": null,
"exchange_timestamp": null,
"filled_quantity": 0,
"instrument_token": 1,
"order_id": "171229000724687",
"order_timestamp": "2017-12-29 11:06:52",
"order_type": "LIMIT",
"parent_order_id": null,
"pending_quantity": 1,
"placed_by": "DA0017",
"price": 300,
"product": "CNC",
"quantity": 1,
"status": "PUT ORDER REQ RECEIVED",
"status_message": null,
"tag": null,
"tradingsymbol": "SBIN",
"transaction_type": "BUY",
"trigger_price": 0,
"validity": "DAY",
"variety": "regular",
"modified": false
},
{
"average_price": 0,
"cancelled_quantity": 0,
"disclosed_quantity": 0,
"exchange": "NSE",
"exchange_order_id": null,
"exchange_timestamp": null,
"filled_quantity": 0,
"instrument_token": 779521,
"order_id": "171229000724687",
"order_timestamp": "2017-12-29 11:06:52",
"order_type": "LIMIT",
"parent_order_id": null,
"pending_quantity": 1,
"placed_by": "DA0017",
"price": 300,
"product": "CNC",
"quantity": 1,
"status": "VALIDATION PENDING",
"status_message": null,
"tag": null,
"tradingsymbol": "SBIN",
"transaction_type": "BUY",
"trigger_price": 0,
"validity": "DAY",
"variety": "regular",
"modified": false
}
]
}

Retrieving all trades

While an orders is sent as a single entity, it may be executed in arbitrary chunks at the exchange depending on market conditions. For instance, an order for 10 quantity of an instrument can be executed in chunks of 5, 1, 1, 3 or any such combination. Each individual execution that fills an order partially is a trade. An order may have one or more trades.

This API returns a list of all trades generated by all executed orders for the day.

Request:

curl "https://api.blinkx.in/SmartApi/trades" \
-H "X-Version: 3" \
-H "Authorization: token api_key:access_token"

Response:

{
"status": "success",
"data": [
{
"trade_id": "10000000",
"order_id": "200000000000000",
"exchange": "NSE",
"tradingsymbol": "SBIN",
"instrument_token": 779521,
"product": "CNC",
"average_price": 420.65,
"quantity": 1,
"exchange_order_id": "300000000000000",
"transaction_type": "BUY",
"fill_timestamp": "2021-05-31 09:16:39",
"order_timestamp": "09:16:39",
"exchange_timestamp": "2021-05-31 09:16:39"
},
{
"trade_id": "40000000",
"order_id": "500000000000000",
"exchange": "CDS",
"tradingsymbol": "USDINR21JUNFUT",
"instrument_token": 412675,
"product": "MIS",
"average_price": 72.755,
"quantity": 1,
"exchange_order_id": "600000000000000",
"transaction_type": "BUY",
"fill_timestamp": "2021-05-31 11:18:27",
"order_timestamp": "11:18:27",
"exchange_timestamp": "2021-05-31 11:18:27"
}
]
}

Response attributes

AttributeDescription
trade_idExchange generated trade ID
order_idOrder ID
exchange_order_idExchange order ID
tradingsymbolTrading symbol
exchangeExchange
instrument_tokenInstrument token
transaction_typeBUY or SELL
productMargin product
average_pricePrice at which the quantity was filled
filledFilled quantity
fill_timestampTimestamp at which the trade was filled
order_timestampOrder timestamp
exchange_timestampExchange timestamp

Retrieving an order's trades

This API returns the trades spawned and executed by a particular order.

Request:

curl "https://api.blinkx.in/SmartApi/orders/200000000000000/trades" \
-H "X-Version: 3" \
-H "Authorization: token api_key:access_token"

Response:

{
"status": "success",
"data": [
{
"trade_id": "10000000",
"order_id": "200000000000000",
"exchange": "MCX",
"tradingsymbol": "GOLDPETAL21JUNFUT",
"instrument_token": 58424839,
"product": "NRML",
"average_price": 4852,
"quantity": 1,
"exchange_order_id": "300000000000000",
"transaction_type": "BUY",
"fill_timestamp": "2021-05-31 16:00:36",
"order_timestamp": "16:00:36",
"exchange_timestamp": "2021-05-31 16:00:36"
}
]
}