Option of executing trade as Atomic Operation

MadhuSingh
Hi,
Is there option to provide an ATOMIC flag so that either all or None quantity of requested trade gets executed.

Regards,
Madhu.
  • sujith
    sujith edited September 2017
    Hi @MadhuSingh,
    You can use validity as IOC (immediate or cancel).
    You just need to pass validity param like this,
    validity = IOC
  • sujith
    Let's consider a scenario wherein you place a LIMIT order for an instrument for 1000 quantity, if for the same price offer is there for 500 quantity then 500 will be executed and for rest quantity, it will be cancelled.
  • vineet_dhandhania
    @ sujith,
    Could you please add more details on IOC orders in the documentation, maybe with sample code? This will be useful to Zerodha as much as the traders because IOC orders could help people transition from polling order book to asynchronous order postbacks.
  • tonystark
    @vineet_dhandhania Can you elaborate on how IOC order could help in that scenario?
  • vineet_dhandhania
    vineet_dhandhania edited June 2018
    @ tonystark Place yourself in the shoes of a client-side developer who wants to use WebSocket order postback. Say you place a Limit order on SBIN to buy 1000 shares. Since postbacks are asynchronous, you program can't wait for the order execution. You never know when the order might get filled. Now say, the order gets partially filled a few times. You receive UPDATE postbacks. In order to react appropriately, your program needs to know where in the position cycle (from position building to waiting for target/stoploss to position unwinding) you currently are, for the given trading_symbol. It becomes complicated. Sequential programs are easier and intuitive. IOC orders can bridge the gap partially.
    With an IOC order, my program knows 2 things:
    1) The order will not leave any residual unfilled qty beyond the first attempt at filling
    2) There will be only one postback which will come immediately after placing the order
    This can greatly simplify position management when dealing with asynchronous postbacks and hopefully people will transition from polling.

    People do have incentive to use postbacks because polling leads to delayed reaction whereas postbacks enable reaction as and when things happen. So once people get some ideas on how to use postbacks in a not-so-complicated manner, people will want to move to postbacks.
  • tonystark
    tonystark edited June 2018
    @vineet_dhandhania I believe you want to get a trigger exactly when your order gets completed, right?

    In my point of view if you simply reject all the UPDATEs and use the COMPLETE postback of the order you placed it is pretty similar to that of IOC order. The difference will be your execution price could be different if you placed a MARKET order. Is that something you are worried about?
  • vineet_dhandhania
    @tonystark Market order can only be used with highly liquid securities. For other securities, I would use market order only to stop loss. For position initiation, I strongly prefer limit order (with reasonable impact cost).
    With limit orders, waiting for COMPLETE postback is not possible. It might take very long; the price might move sharply in the direction of stop loss, without me having entered the stop loss order (coz I kept waiting for the position initiation order to complete). I know BO order could help here but BO doesn't take care of all my use cases.
    The advantage of IOC is that I can make my program more-or-less sequential because I know there will be only one postback and that too will come immediately. The disadvantage of IOC-style position initiation is that the position size would be sub-optimal but I am ok with that to begin with.
    Personally my roadmap is that - I'd like to start with IOC and at some point, make my program capable of handling more elaborate and complicated scenarios. For most people, IOC could be a good way to begin their order postback journey.
  • cdesai1987
    Contact me for the best algo developed in India @ 9850073217 at [email protected]
Sign In or Register to comment.