Regarding recommended practices on monitoring orders,positions and trade performance

My strategy requires that no new trades are taken for a script if the following conditions hold -
1) No more than "X" longs and "X" shorts
2) Stop trading the script if there are "Y" no. of losing trades.
My all orders are market orders. So if the order is executed, entire quantity is immediately filled. This also means that after a trade is squared off/stopped - position is Zero , something which I need to check before initiating a new trade.(No fresh orders if the position is !=0)
I am polling position at the end of every minute to know the position of a particular script as one minute is the minimum frequency. Is this recommended or should I monitor the position through my program?
There is a risk if the calculated position is , for some reason , wrong. For monitoring through program , I need to know if an order has been successfully executed. If order_id is the default set in the program , then I know that order was not placed.However if this is updated , then the only thing I am certain about is that the order is successfully placed but not about the execution. Market order should also give the confidence that the order was indeed executed . But I want to be 100% sure. So, after allowing a pause of a second after receiving the order_id , I poll 'trades' with the specific 'order_id' to know the fate of the order. From the response of 'trades' ,I extract a) the quantity (and tally it with the quantity given in the order) and b) average price to know the price at which the order was executed. At this stage I have a feeling whether I am doing something redundantly only to ensure if the order was executed successfully and fully , and if yes - then at what price.
My second doubt is on how to monitor or classify a trade as a winning or losing trade. I plan to use a set of counters in my code segments - one each for target ,SL and EOD square off . Counters against the SL will help me know the count of losing trades. EOD is irrelevant as no new trade initiation will happen. But , my problem is with cover orders . How would I know that the second leg was either triggered / cancelled? How to capture that event ? My objective is to rely on api calls as minimum as possible.

Any expert view on the above will help many having similar questions in mind.
  • ZI4453
    ZI4453 edited August 2019
    please go through event emits,
    if you are applying those event's update(complete order cycle's) in your coding then you can accomplish your task.
    i have not personally worked with CO,but if you are well aware of how Kite responds to CO Orders then it should be easy @ RP3436
  • sujith
    Hi @RP3436,
    The P&L calculation for positions is straight forward, you don't need to poll positions to check that.
    You can refer that this for formula.

    You may use websockets postbacks for order updates.
Sign In or Register to comment.