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.
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.