Can you please share the C# code to place MIS futures order with stop loss. I have already looked at the Kite API code and cant see the code example which would allow me to create a futures order with stop loss. It would be good if it is for BankNifty futures.
You can't directly place a mis order with stoploss. You have to place an order and then place a corresponding sl order. Or best,use cover order to place an order with a sl order.
You can refer the C# documentation here: https://github.com/zerodha/dotnetkiteconnect
@SRIJAN I thought we cannot place cover order for future segment. Am I wrong with this ? and if I can put cover order then would the code be same as what I do with cover order for any stock...except that the exchange would be NFO for future ?
@sujith Sir .Oh. I have been using the mobile app for sometime.It shows cover order. Just now,I went to desktop, and I came to know . It has been discontinued for NFO.
@prasad_n_k Then you have to go for the first method I told. Place a order and then place a corresponding sl order. That's the only way.
@sujith@SRIJAN that helps, thanks... failed to understand though how the margin requirement is anyway related to cover order discontinuation.. You could still keep 100% margin requirement for putting futures cover order... It was easier to put one order earlier in place of two orders now and then track them now in the code.
@prasad_n_k Yeah,I also don't understand. Well,as for that matter, I don't understand any new rules in stock market after SEBI become a tyrant in 2020. We just have to accept.
Does this mean my first order would be market order and second leg order will be limit order with the required stop loss price... so if first order is buy order then the other one would be sell ? Wouldn't that also mean I will need double the margin as I am putting both separate orders ?
@prasad_n_k The first leg order can be market or limit whatever you want. Just make sure if you use limit order,the sl order should be placed once the first leg order is completed. The sl order will be SL or SLM and not LIMIT order.In that case,you won't need extra margin. If you place sl before the first order is complete then you would require double margins. Also, remember that this means you can either put a sl order or target order without paying extra margin. If you want to place both sl and target then you would need extra margin. Or,you can use gtt to place both sl and target. Basically ,if you have X quantity bought/sold,you can put a squareoff order of X quantity without additional margin.
@SRIJAN@sujith thanks, one more question related to f&o order placement... if I need to complete my order then I need to call something like below correct ? where order id is id of the first leg order... Also do I need to cancel the second leg order in similar manner ?
kiteConnect.CancelOrder(orderId);
Today CancelOrder did not work correctly for some reason which I am investigating.
Why you have to call cancel order to check completed status?? You have to call order_history or you can use websocket on_order_update. You are getting the exception because the first leg order would already have been completed. You will only need to cancel sl order if you want to close the position before your sl gets hit.
I don't understand what you are trying to do. How can you complete a order from your side?? It depends on the market conditions. As you said,you are using limit orders,then they will only be completed when market will come to that point.
@prasad_n_k What? If both first leg and sl order were executed,then the position has already been closed,right?? First, clear,this,what do you mean by 'executed'? Order placed or order completed??
@prasad_n_k I understand now where's the confusion. You are using cancel order with the order_id of the first leg order. You have to cancel order with the order_id of sl order. And,then place a reverse transaction type order.
Let's say your buy order has been completed with order_id 1001. And you placed sl order with order_id 1002. So,now to square off the open position,either you modify the sl(1002) order to a market order. Or,you call cancel order(1002). And then place a new sell order at market.
@SRIJAN "So,now to square off the open position,either you modify the sl(1002) order to a market order." this looks better option. So when you say we have to make sl order to market, how would that order look... give an example buddy, that would help. Should it look something like below ?
You can refer the C# documentation here:
https://github.com/zerodha/dotnetkiteconnect
Exchange: AppConstants.EXCHANGE_NFO for future segment which was
Exchange: AppConstants.EXCHANGE_NSE for stock
Dictionary response = kiteConnect.PlaceOrder
(
Exchange: AppConstants.EXCHANGE_NFO,
TradingSymbol: symbol,
TransactionType: transactionType,
Quantity: tradeQuantity,
Product: AppConstants.PRODUCT_MIS,
OrderType: AppConstants.ORDER_TYPE_MARKET,
Validity: AppConstants.VALIDITY_DAY,
TriggerPrice: Convert.ToDecimal(stopLossPrice),
Variety: AppConstants.VARIETY_CO
);
Cover orders are not allowed for NFO, since the margin required will be more than 100%
@prasad_n_k Then you have to go for the first method I told. Place a order and then place a corresponding sl order. That's the only way.
kiteConnect.CancelOrder(orderId);
Today CancelOrder did not work correctly for some reason which I am investigating.
Exception Message >> Order cannot be cancelled as it is being processed. Try later.
I dont wantI want to complete the orderkiteConnect.CancelOrder('1001');
This is what I was doing earlier for doing a square off of stock open position and thought futures square off code would be same.
Let's say your buy order has been completed with order_id 1001. And you placed sl order with order_id 1002. So,now to square off the open position,either you modify the sl(1002) order to a market order. Or,you call cancel order(1002). And then place a new sell order at market.
kiteConnect.ModifyOrder
(
OrderId: '1002',
ParentOrderId: null,
TradingSymbol: symbol,
Exchange: AppConstants.EXCHANGE_NFO,
OrderType: AppConstants.ORDER_TYPE_MARKET,
)
and no other order to be placed, correct ? if we are following above approach ?