Last active
February 6, 2019 01:12
-
-
Save botany02/a9127384ad9015b7b28800cd7a1d93e3 to your computer and use it in GitHub Desktop.
Modify All BO Stoploss - KiteNet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Next | |
ModifyAllBOStoploss = "Success" | |
Exit Function | |
ErrHandler: | |
ModifyAllBOStoploss = Err.Description | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment