Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Modify All BO Stoploss - KiteNet
Public Function ModifyAllBOStoploss(ByVal ParentOrderId As String) As String
On Error GoTo ErrHandler:
'This is generic example to modify all BO stoploss at certain % from Ltp
'Modify the code to suit your requirements
'Make sure you are not calling this function in a loop
'Use static variables to restrict multiple calling of this function
Dim ModifyPct As Single
ModifyPct = 0.25 / 100 'Modify the stoploss with 0.25% from Ltp
Dim ChildOrders As String
ChildOrders = Kite.GetChildOrders(ParentOrderId)
If ChildOrders = vbNullString Then ModifyAllBOStoploss = "NullChildOrders": Exit Function
Dim ChildOrderArray() As String
ChildOrderArray = Split(ChildOrders, ",")
'Loop through all child orders
'Check for SL order type
'Check for transaction
Dim ChildOrder As Variant
For Each ChildOrder In ChildOrderArray
If ChildOrders <> vbNullString Then 'Check for Null or Empty order id
Dim OrdType As String
OrdType = Kite.GetOrderType(ChildOrder)
If OrdType = "SL" Then 'Modify only if OrderType SL
Dim Trans As String
Dim Exch As String
Dim TrdSym As String
Trans = Kite.GetOrderTrans(ChildOrder)
Exch = Kite.GetOrderExch(ChildOrder)
TrdSym = Kite.GetOrderTrdSym(ChildOrder)
Dim Ltp As Double
Ltp = Kite.GetLtp(Exch, TrdSym)
If Ltp > 0 Then 'Check we have correct Ltp
Dim NewSlPrice As Double
Dim PointsToModify As Double
PointsToModify = Ltp * ModifyPct '455 * 0.0025 = 1.14
If Trans = "BUY" Then 'SL BUY Order
NewSlPrice = Ltp + PointsToModify
Else 'SL SELL order
NewSlPrice = Ltp - PointsToModify
End If
'Modify the BO stoploss order
Kite.ModifyBOSl ChildOrder, NewSlPrice
End If
End If
End If
ModifyAllBOStoploss = "Success"
Exit Function
ModifyAllBOStoploss = Err.Description
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.