F&O order placement

prasad_n_k
Hi,

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.
Tagged:
  • SRIJAN
    SRIJAN edited February 2022
    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
  • prasad_n_k
    @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 ?
  • prasad_n_k
    To be more specific, would the following code work for bank nifty future ? I had this code for stock and I just changed the

    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
    );
  • sujith
    @prasad_n_k,
    Cover orders are not allowed for NFO, since the margin required will be more than 100%
  • sujith
    This is because of peak margin regulation.
  • prasad_n_k
    @sujith so how do we replicate cover order for future segment. need help.
  • SRIJAN
    SRIJAN edited February 2022
    @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
    You need to place the first leg order and then place stoploss order.
  • SRIJAN
    @sujith Sir. When did this happen?? 3weeks ago?? I just watched on a youtube channel. Till 21stJan,cover orders were showing in desktop too.
  • sujith
    You can check out bulletin here.
  • SRIJAN
    Oh,thanks. I remember now,Yes,I read that but I forgot beacuse I have not traded futures from Dec 2020 :'( ,and it was showing in the kite web/app.
  • prasad_n_k
    @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.
  • SRIJAN
    @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. :|
  • prasad_n_k
    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 ?
  • SRIJAN
    SRIJAN edited February 2022
    @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.
  • prasad_n_k
    @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.
  • prasad_n_k
    prasad_n_k edited February 2022
    I see following error generated for order cancellation. Could you please let me know the reason for the error ?

    Exception Message >> Order cannot be cancelled as it is being processed. Try later.
  • SRIJAN
    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.
  • prasad_n_k
    @SRIJAN I dont want to complete the order and above error I got for my first leg order when I wanted to complete it
  • prasad_n_k
    @SRIJAN I dont want I want to complete the order
  • SRIJAN
    SRIJAN edited February 2022
    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
    @SRIJAN my order was executed successfully (both first leg of buy order and second leg of stop loss order) and now I want to square off my position.
  • prasad_n_k
    @SRIJAN for doing the square off, I got above error. How to resolve this error ?
  • SRIJAN
    @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
    @SRIJAN simple.... how to square off open position ??
  • SRIJAN
    To square off open position,you have to place a reverse transaction order with the same quantity you have.
  • SRIJAN
    If you have a sl order already placed,cancel that order and put a new sqaureoff order. Or ,just modify the sl order to market order.
  • prasad_n_k
    @SRIJAN can you give an example ? Lets say I have open buy order with order id 1001, shouldn't I be calling like below ?

    kiteConnect.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.
  • prasad_n_k
    @SRIJAN please give an example for furtures with Buy order id of lets say 1001 and stop loss order id of lets say 1002
  • SRIJAN
    @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.
  • prasad_n_k
    @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 ?

    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 ?
  • SRIJAN
    You don't need trading symbol or exchange. It's the same as you do in kite web/app. You only need to pass order type as market with the order id.
  • prasad_n_k
    @SRIJAN alright, cool. Thanks. Let see how it goes with the changes and will let you know in this thread if I encounter any error
Sign In or Register to comment.