It looks like you're new here. If you want to get involved, click one of these buttons!
Is there any way to check open positions from Kite and then use that to prevent repeat orders?
Public Function PlaceRegularOrder(Exch As String, TrdSym As String, Trans As String, OrdType As String, Qty As Integer, _
ProdType As String, Optional LmtPrice As Double = 0, Optional TrgPrice As Double = 0, Optional val As String = "DAY") As String
On Error GoTo ErrHandler:
If Kite Is Nothing Then
PlaceRegularOrder = "User Not Logged-In"
Exit Function
End If
Dim LastOrder As String
If Not Dict_PlaceRG.Exists(UCase(TrdSym)) Then
Dict_PlaceRG.Add UCase(TrdSym), UCase(Trans)
LastOrder = ""
Else
LastOrder = Dict_PlaceRG(UCase(TrdSym))
End If
If LastOrder = UCase(Trans) Then
PlaceRegularOrder = "Duplicate Order"
Exit Function
End If
Dict_PlaceRG.Item(UCase(TrdSym)) = UCase(Trans)
PlaceRegularOrder = Kite.PlaceRegularOrder(Exch, TrdSym, Trans, OrdType, Qty, _
ProdType, LmtPrice, TrgPrice, val)
Exit Function
ErrHandler:
PlaceRegularOrder = Err.Description
Exit Function
End Function
1) I figured out how to get the last executed Cover order ID using =getOrderID and then finding the last 15 digits using =Right function to get the last order(I think this will be the Order ID of the auto generated Stop Loss Order) and then finding the second last order ID using =mid function (I think this will be the executed parent cover order ID). Then, using these two order IDs I can build my exit strategy using the ExitCO function.
Is this logic correct? (the part where I assume the last order will be the SL order ID and second last order will be the parent Cover Order ID)
2) Also, I learnt about the MS Scripting Dictionary in VBA and it seems pretty straightforward to use. I also studied the logic you had used to restrict repeated orders in Regular Order. Unfortunately, the same logic doesn't work for CO. So I was thinking of a possible logic as below:
->Store last two Orders in two adjacent cells as per the above point 1
->Use the =getOrderStatus function on the next cell to see the last order (the auto-generated SL order) status
->Modify the PlaceCO function as follows:
Is this logic correct? Please advice na
Regards,
Arjun Murali
The logic is correct..
But Point 2 may not work. If You used vba to write Order Id to cell Values & using that value
in getOrderStatus, then the Function will not be recalculated by Excel as no parameter is changing or dynamic.You need to pass at-least some param whose value is changing, so that excel will recalculate the formula.Ex:- add ltp as additional dummy parameter.
I tried passing LTP as a dummpy parameter na, and it seemed to be working fine when I was manually testing.
But during market hours, the buy/sell order gets repeatedly executed before the getorderIds gets updated. This causes Multiple entries as well as the ExitCO to fail and the whole system doesn't work as intended.
So I have reverted back to placing a Bracket Order with a trailing SL as the exit na. For now, I've added a button to trigger a macro that manually resets the Dictionary value to " " after an SL/Target hit so as to enable it to re enter a trade on that scrip. Till I can think up an automated solution for this, I'll stick to this setup na. It seems to be working well.
If you get any idea for a logic to make this automated, do let me know na.
Thank you so much for the timely help
Regards,
Arjun Murali