How to get Parent OrderID and how to Exit Cover Order ?

koushi0207
koushi0207 edited July 2020 in .Net API client
I am trying to place Cover Order successfully. But I am clueless for exiting the Cover Orders. Here is the code which I have done.
'For placing Cover Order
Dim place_Order As Dictionary(Of String, Object) = kite.PlaceOrder(exchange, tradesymbol, transType, tradeqty, price, productType, ordType, validity, DisclosedQty, TriggerPrice, SqrOffValue, StopLossValue, TrailingStopLoss, variety, Tag)

Dim orderID As String = place_Order("data")("order_id")


Dim APIordstatus As List(Of Order) = kite.GetOrderHistory(orderID)
'Dim APItradestatus As List(Of Trade) = kite.GetOrderTrades(orderID)


Dim ordstatus As String
Dim entryprice As String
Dim parentOrderId As String
Dim sDate As Date

sDate = DateAdd("s", 3, Now.ToString)

Do While Now < sDate
For Each statsa In APIordstatus
If (orderID.ToString = statsa.OrderId.ToString) Then
ordstatus = statsa.Status.ToString
entryprice = statsa.AveragePrice.ToString()

If ordstatus = "COMPLETE" Then
parentOrderId = statsa.ParentOrderId.ToString
End If
End If
Next
Loop
Note :
But I am getting Parent OrderID as blank for the OrderID from my above code while updating on Table.
I tried this way for exiting the order :

Try
kite.CancelOrder(orderID , "co", parentOrderId)
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
Note :
When I try Exit method without sending Parent OrderId, it didnt work for me.

Please let me know with sample code to get the parent orderID for the order which I placed and also need a code sample for Exiting the Cover Order for the above placed order.
  • sujith
    You seem to be fetching order history. It will retrieve different states that order has gone through in the system to reach its current state. It doesn't contain information regarding the second leg order or parent order.
    When you place a cover order, the order id received in the success response is the parent order or first leg order. In order to find the second leg order, you need to fetch orderbook and look for an order which has this order id in the parent order id field.
  • koushi0207
    Thank you Mr.Sujith. As you given an idea I done the same. Now I am able to get it with executed price too on exited order.

    Thanks once again for your support.
This discussion has been closed.