• Home
  • Products
    • Login
    • Product Info
    • User Guide
    • Pricing
  • Services
    • Stock Brokers
    • Freelancers
  • Help
    • Documentation
    • Knowledge Base
    • FAQ
  • Company
    • About Us
    • Contact Us
    • Terms & Conditions
  • Home
  • Products
    • Login
    • Product Info
    • User Guide
    • Pricing
  • Services
    • Stock Brokers
    • Freelancers
  • Help
    • Documentation
    • Knowledge Base
    • FAQ
  • Company
    • About Us
    • Contact Us
    • Terms & Conditions

AutoTrader Web

home/Documentation/AutoTrader Web
Expand All Collapse All
  • Index
  • Getting Started
  • Portfolio Management System (PMS)
  •  Copy Trading (Master-Child Auto-Copy)
    • Master-Child Copy - Performance
  • PMS vs Master-Child
  • Trading View
  •  Supported Brokers
    • Symphony XTS
    • Zerodha
    • Angel Broking
    • Dhan
    • Aliceblue
    • Fyers
    • Nuvama
    • IIFL
    • Zebu
    • Finvasia
    • Motilal Oswal
    • Kotak
    • Mastertrust
    • Five Paisa
    • Choice Broking
    • FlatTrade
    • Tradejini
    • Upstox
    • SAS Online
    • Profitmart
  •  Client Setup
    • Desktop Client
    • AmiBroker Library
    • Excel Library or Tools
    • Java Library
    • MetaTrader Library
    • C# Library
    • Python Library
    • HTTP REST
  •  User Interface
    • User Registration
    •   Settings
      • General
      • Trading Accounts
      • Pseudo Accounts
      • Group Accounts
      • API Key
    •   AutoTrader
      • Activity
      • Instruments
    •   Trading
      • Summary
      • Positions
      • Orders
      • Margins
      • Holdings
      • Trade
    •   User
      • Account
      • Profile
  •  API (Application Programming Interface)
    • Place Regular Order
    • Place Cover Order
    • Place Bracket Order
    • Place Advanced Order
    • Cancel Order
    • Cancel Child Orders
    • Cancel All Orders
    • Modify Order
    • Modify Order Price
    • Modify Order Quantity
    • Square-off Position
    • Square-off Portfolio
    • Read Orders
    • Read Positions
    • Read Margins
    • Read Holdings
    • Read Portfolio Summary
    • Fetch All Trading Accounts
    • Create or Update Trading Account
    • Validate Trading Account Credentials
    • API Parameters
    • API Rate Limits
    • Email Limits
    • Postman
  • Pricing
  • Precautions
  •  Broker Independence
    • API Functions
    • Pseudo Account
    • Instruments (Trading Symbols)
  • Quantity Multiplier
  • Architecture

Place Bracket Order

5752 views July 29, 2024 Pritesh 3

API function to place bracket order. APIs are available in AmiBroker, MetaTrader, Excel, Java, C#, Python, HTTP REST.

Api function will place a bracket order on Supports leading Indian Stock Brokers.

  • AmiBroker
  • MetaTrader
  • Java
  • C#
  • Python
  • HTTP
  • Excel
  • Postman

Signature

function placeBracketOrder(account, exchange, 
	symbol, tradeType, orderType, 
	quantity, price, triggerPrice, 
	target, stoploss, trailingStoploss, validate)

Example 1

orderId = placeBracketOrder(AT_ACCOUNT, 
	AT_EXCHANGE, AT_SYMBOL, "BUY", 
	"LIMIT", AT_QUANTITY, buyPrice, 
	defaultTriggerPrice(), 5, 3, 1, True);

This example will place a Limit Bracket order for Account, Exchange & Symbol chosen in chart parameters. With a target of 5/-, stoploss of 3/- and trailing stoploss of 1/-.

Some variables used in above code are parameters defined by AutoTrader library.

Example 2

// Place bracket order (Limit)
orderId = placeBracketOrder("ACC_NAME", 
	"NSE", "WIPRO", "BUY", 
	"LIMIT", 15, buyPrice, 
	defaultTriggerPrice(), 5, 3, 1, True);

This example will place Limit Bracket order for Account (ACC_NAME), Exchange (NSE) & Symbol (WIPRO) with quantity 15. With a target of 5/-, stoploss of 3/- and trailing stoploss of 1/-.

We have placed a LIMIT order; hence we have used a function called defaultTriggerPrice(), which return zero price.

Here we did not use chart parameters, instead we passed the values directly.

Example 3

// Apply your logic to calculate stoploss trigger price
stoplossTriggerPrice = buyPrice - 5;

// Place bracket order (Stoploss)
orderId = placeBracketOrder("ACC_NAME", 
	"NSE", "WIPRO", "BUY", 
	"STOP_LOSS", 15, buyPrice, 
	stoplossTriggerPrice, 5, 3, 1, True);

This example will place Stoploss Bracket order for Account (ACC_NAME), Exchange (NSE) & Symbol (WIPRO) with quantity 15. With a target of 5/-, stoploss of 3/- and trailing stoploss of 1/-.

We have placed a STOP_LOSS order; hence we have passed a triggerPrice.

Signature

string placeBracketOrder(string account, 
	Exchange exchange, string symbol, 
	TradeType tradeType, OrderType orderType, 
	int quantity, double price, 
	double triggerPrice, double target, 
	double stoploss, double trailingStoploss, 
	bool validate)

Example 1

string id = placeBracketOrder(AT_ACCOUNT, 
     AT_EXCHANGE, AT_SYMBOL, BUY, LIMIT, 1, 
     192, 0.0, 5, 3, 1, true);

This example will place a Limit Bracket order for Account, Exchange & Symbol chosen in chart parameters. With a target of 5/-, stoploss of 3/- and trailing stoploss of 1/-.

Some variables used in above code are parameters defined by AutoTrader library.

Example 2

// Apply your logic to calculate stoploss trigger price
stoplossTriggerPrice = buyPrice - 5;
 
// Place bracket order (Stoploss)
string id = placeBracketOrder(AT_ACCOUNT, 
	NSE, "WIPRO", BUY, STOP_LOSS, 15, 
	buyPrice, stoplossTriggerPrice, 5, 3, 1, true);

This example will place Stoploss Bracket order for Account (ACC_NAME), Exchange (NSE) & Symbol (WIPRO) with quantity 15. With a target of 5/-, stoploss of 3/- and trailing stoploss of 1/-.

We have placed a STOP_LOSS order; hence we have passed a triggerPrice.

Signature

/**
 * Places a bracket order.
 *
 * @param pseudoAccount    pseudo account
 * @param exchange         exchange
 * @param symbol           symbol
 * @param tradeType        trade type
 * @param orderType        order type
 * @param quantity         quantity
 * @param price            price
 * @param triggerPrice     trigger price
 * @param target           target
 * @param stoploss         stoploss
 * @param trailingStoploss trailing stoploss
 * @return the order id given by your stock broker
 */
IOperationResponse<String> placeBracketOrder(
	String pseudoAccount, String exchange, String symbol,
	TradeType tradeType, OrderType orderType, int quantity, 
	float price, float triggerPrice, float target, 
	float stoploss, float trailingStoploss);

Example

// Place a bracket order   
final IOperationResponse<String> response = autotrader
	.placeBracketOrder("ACC_NAME", "NSE", "SBIN", 
		TradeType.BUY, OrderType.LIMIT, 
		10, 180.5f, 0f, 5f, 2.5f, 1f);

// Read order id
String orderId = null;
if (response.success()) {
	orderId = response.getResult();
} else {
	final String errorMessage = response.getMessage();
}

This will place a bracket order into your trading account that is mapped to the passed pseudo account. The function will return a response object.

Response object has a function called success(), which returns true on successful execution.

We can then use the method getResult() to access order_id given by your trading platform.

Signature

/// <summary>
/// Places a bracket order. For more information, please see <a href=
/// "https://stocksdeveloper.in/documentation/api/place-bracket-order/">api
/// docs</a>.
/// </summary>
/// <param name="pseudoAccount">    pseudo account </param>
/// <param name="exchange">         exchange </param>
/// <param name="symbol">           symbol </param>
/// <param name="tradeType">        trade type </param>
/// <param name="orderType">        order type </param>
/// <param name="quantity">         quantity </param>
/// <param name="price">            price </param>
/// <param name="triggerPrice">     trigger price </param>
/// <param name="target">           target </param>
/// <param name="stoploss">         stoploss </param>
/// <param name="trailingStoploss"> trailing stoploss </param>
/// <returns> the order id given by your stock broker </returns>
IOperationResponse<String> PlaceBracketOrder(
	string pseudoAccount, string exchange, 
	string symbol, TradeType tradeType, 
	OrderType orderType, int quantity, 
	float price, float triggerPrice, float target, 
	float stoploss, float trailingStoploss);

Example

IOperationResponse<string> response = 
	autoTrader.PlaceBracketOrder("XX1234", 
	"NSE", "SBIN", TradeType.SELL, 
	OrderType.LIMIT, 3, 220f, 0, 2, 3, 0);
	
if(response.Success()) {
    Console.WriteLine("Result: {0}", response.Result);
}
else {
    Console.WriteLine("Message: {0}", response.Message);
}

This will place an order into your trading account that is mapped to the passed pseudo account. The function will return a response object.

Response object has a function called Success(), which returns true on successful execution.

We can then use the Result property to access order_id given by your trading platform.

Signature

def place_bracket_order(self, pseudo_account, \
	exchange, symbol, tradeType, orderType, \
	quantity, price, triggerPrice,
	target, stoploss, trailingStoploss=0.0):

Example

response = autotrader.place_bracket_order( \
	'XX1234', 'NSE', 'WIPRO', 'SELL', 'LIMIT', \
	1, 326.35, 0.0, 1, 1, 0)
	
if response.success():
    print("Result: {0}".format(response.result))
else:
    print("Message: {0}".format(response.message))

Example

curl https://api.stocksdeveloper.in/trading/placeBracketOrder \
   -H "api-key: <your_api_key>" \
   -d "pseudoAccount=ACC_NAME" \
   -d "exchange=NSE" \
   -d "symbol=SBIN" \
   -d "tradeType=BUY" \
   -d "orderType=LIMIT" \
   -d "quantity=10" \
   -d "price=180.5" \
   -d "triggerPrice=0" \
   -d "target=5" \
   -d "stoploss=2.5" \
   -d "trailingStoploss=1"

Response

{
	"result":"200622000335719",
	"error":null,
	"message":null,
	"status":true,
	"commandId":"9b87532c-cade-49d3-8ace-76db7be63029"
}

The response contains result (which is order_id given by your trading platform).

If there is any error, then you will get status as false & message will have error text.

The commandId cab be used to trace the activity on AutoTrader Web.

Signature

Public Function PlaceBracketOrder( _
    PseudoAccount As String, _
    Exchange As String, _
    Symbol As String, _
    TradeType As String, _
    OrderType As String, _
    Quantity As Integer, _
    Price As Double, _
    TriggerPrice As Double, _
    Target As Double, _
    Stoploss As Double, _
    TrailingStoploss As Double) As String

Example

Dim OrderId As String

OrderId = PlaceBracketOrder("ACC_NAME", _
	"NSE", "SBIN", "BUY", "LIMIT", 1, _
	200.55, 0, 3, 2, 1)

This will place a bracket order with target of 3/-, stoploss of 2/- and trailing stoploss of 1/-.

Postman is widely used tool for API testing. We have provided below a collection of all of our APIs in postman collection format. Click postman collection to know more about how to use it.


Parameters

  • account – pseudo account
  • exchange – instrument (stock/derivative) exchange
  • symbol – instrument (stock/derivative) symbol
  • tradeType – trade type
  • orderType – order type
  • quantity – quantity
    • Note: For NSE/BSE derivatives, quantity should be multiple of lot size. Example, BANKNIFTY lot size is 15. So to buy/sell 1 lot, you need to enter 15 quantity.
  • price – order price
  • triggerPrice – trigger price
  • target – target for bracket order
  • stoploss – stoploss for bracket order
  • trailingStoploss – trailing stoploss for bracket order
  • validate – validate order (check for duplicate signals). Only applicable for AmiBroker & MetaTrader.

Return value

AmiBroker, MetaTrader, Excel

This function sends place order request to AutoTrader Desktop Client. On successful submission, it will return a unique publisherId (orderId given by AutoTrader library).

Java, HTTP, C#, Python

The function returns a platformId (orderId given by your trading platform).

The type of the return value is String or Text.

Important

  • Your broker must support Bracket order on our platform. Please try placing a bracket order from our platform’s trading terminal first to confirm whether it is supported or not.
Place Cover Order
Place Advanced Order

Was this helpful?

3 Yes  No
Related Articles
  • Master-Child Copy – Performance
  • Tradejini
  • Dhan
  • FlatTrade
  • Supported Brokers
  • Symphony XTS

© 2025 Stocks Developer. All Rights Reserved.