API function to place cover order. APIs are available in AmiBroker, MetaTrader, Excel, Java, C#, Python, HTTP REST.
Api function will place a cover order on Zerodha, Upstox, AliceBlue, Finvasia, Angel Broking, Fyers, IIFL, 5Paisa, Profitmart, Mastertrust.
Signature
function placeCoverOrder(account, exchange, symbol, tradeType, orderType, quantity, price, triggerPrice, validate)
Example 1
// Apply your logic to calculate stoploss trigger price stoplossTriggerPrice = buyPrice - 5; // Place cover order orderId = placeCoverOrder(AT_ACCOUNT, AT_EXCHANGE, AT_SYMBOL, "BUY", "LIMIT", AT_QUANTITY, buyPrice, stoplossTriggerPrice, True);
This example will place a Cover order for Account, Exchange & Symbol chosen in chart parameters.
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 cover order (Limit) orderId = placeCoverOrder("ACC_NAME", "NSE", "SBIN", "BUY", "LIMIT", 10, buyPrice, stoplossTriggerPrice, True);
This example will place Cover order for Account (ACC_NAME), Exchange (NSE) & Symbol (SBIN) with quantity 10. We have placed a LIMIT order.
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 cover order (Market) orderId = placeCoverOrder("ACC_NAME", "NSE", "SBIN", "BUY", "MARKET", 10, 0, stoplossTriggerPrice, True);
This example will place Cover order for Account (ACC_NAME), Exchange (NSE) & Symbol (SBIN) with quantity 10. We have placed a MARKET order; hence the order price is zero.
Signature
string placeCoverOrder(string account, Exchange exchange, string symbol, TradeType tradeType, OrderType orderType, int quantity, double price, double triggerPrice, bool validate)
Example
// Apply your logic to calculate stoploss trigger price double stoplossTriggerPrice = buyPrice - 5; // Place cover order string id = placeCoverOrder(AT_ACCOUNT, AT_EXCHANGE, AT_SYMBOL, BUY, LIMIT, 1, 192, stoplossTriggerPrice, true);
This example will place a Cover order for Account, Exchange & Symbol chosen in chart parameters.
Some variables used in above code are parameters defined by AutoTrader library.
Example 2
// Apply your logic to calculate stoploss trigger price double stoplossTriggerPrice = buyPrice - 5; // Place cover order (Market) orderId = placeCoverOrder("XX2030", NSE, "SBIN", BUY, MARKET, 10, 0, stoplossTriggerPrice, true);
This example will place Cover order for Account (XX2030), Exchange (NSE) & Symbol (SBIN) with quantity 10. We have placed a MARKET order; hence the order price is zero.
Signature
/** * Places a cover 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 * @return the order id given by your stock broker */ IOperationResponse<String> placeCoverOrder( String pseudoAccount, String exchange, String symbol, TradeType tradeType, OrderType orderType, int quantity, float price, float triggerPrice);
Example
// Place a cover order final IOperationResponse<String> response = autotrader.placeCoverOrder("ACC_NAME", "NSE", "SBIN", TradeType.BUY, OrderType.LIMIT, 10, 180.5f, 180f); // Read order id String orderId = null; if (response.success()) { orderId = response.getResult(); } else { final String errorMessage = response.getMessage(); }
This will place a cover 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 cover order. For more information, please see <a href= /// "https://stocksdeveloper.in/documentation/api/place-cover-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> /// <returns> the order id given by your stock broker </returns> IOperationResponse<String> PlaceCoverOrder( string pseudoAccount, string exchange, string symbol, TradeType tradeType, OrderType orderType, int quantity, float price, float triggerPrice);
Example
IOperationResponse<string> response = autoTrader.PlaceCoverOrder("XX1234", "NSE", "SBIN", TradeType.SELL, OrderType.MARKET, 3, 0, 218.4f); 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_cover_order(self, pseudo_account, \ exchange, symbol, tradeType, orderType, \ quantity, price, triggerPrice):
Example
response = autotrader.place_cover_order( \ 'XX1234', 'NSE', 'SBIN', 'SELL', 'LIMIT', \ 1, 188.15, 190.0) if response.success(): print("Result: {0}".format(response.result)) else: print("Message: {0}".format(response.message))
Example
curl https://api.stocksdeveloper.in/trading/placeCoverOrder \ -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=180"
Response
{ "result":"200622000333410", "error":null, "message":null, "status":true, "commandId":"6d4b5738-c1aa-4623-b0c5-8df779e0f44d" }
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 PlaceCoverOrder( _ PseudoAccount As String, _ Exchange As String, _ Symbol As String, _ TradeType As String, _ OrderType As String, _ Quantity As Integer, _ Price As Double, _ TriggerPrice As Double) As String
Example
Dim OrderId As String OrderId = PlaceCoverOrder("ACC_NAME", _ "NSE", "SBIN", "BUY", "LIMIT", 100, 200.55, 0)
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
- price – order price
- triggerPrice – trigger price
- 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.