Difference b/w bridge and normal functions?

dadu369
@botany02 @HowUTrade

and How to get stop loss order id for a particular bracket order?
  • HowUTrade
    @dadu369

    A bracket order may have(most of the time) more than one child order. The child orders includes both target order and stoploss order. You can call GetChildOrders by passing order id of the Main/Entry order, this will return comma seperated list of child orders. You can just split it by 'comma' to get array of order ids and loop through.

    For Bridge functions refer this
  • dadu369
    dadu369 edited September 2018
    @HowUTrade Thanks for your response.

    Please also guide -

    (a) In the Excel_Template sheet (bridge functions) below formula is mentioned to get bridge mtm.
    =GetMtmBridge(E3, F3, StgyCode,"XLBRIDGE",IsLive, H3)
    How to assign any strategy a code?

    (b) In the link you mentioned 'Order routing through bridge' is available only for our Premium clients. Can we not use bridge though bridge functions are available in KiteXL?

    (c) Any specific format to use bridge functions for paper trading?

    (d) how to get number of live positions (order accepted, only parent orders) and number of open orders in Kite and Bridge?

    (d) last one, how to get available current margin when a number of orders are live, for a kite/bridge strategy?

    This would be great help. Thanks in advance.

  • HowUTrade
    @dadu369

    (a) You can place order to zerodha in two ways.
    1. Using Kite Class
    2. Using Bridge Class

    Place order function of Bridge accepts additional parameters like StgyCode, IsAsync etc..
    Si if you placed a order in "AXISBANK" using Bridge function with StgyCode as "M1" then the =GetMtmBridge("NSE", "AXISBANK", "M1","XLBRIDGE",IsLive, H3) will return the mtm of AXISBANK in "M1" strategy.

    (b) Except place order functions, all other bridges functions are available to everyone. Send us your client Id to [email protected], we will enable it for you to try.

    (c) No, The place order functions of bridge has a parameter called "IsLive", it is boolean parameter, You need to pass True if want to place order in live or pass False to paper trade.

    (d) You can use NetQty (RTD) to get outstanding positions and call GetOrderIds to get list of order ids and loop through each order id and check the Order Status for OPEN orders.

    (e) Kite API doesn't support real-time margin details, you can call GetFunds to see the fund status. But you can't call GetFunds before each order placement to check available margin. If you do, then this will kill your app (Excel) as GetFunds uses Http GET request and it is resource hungry. Pulling data using Http GET request in a loop or more frequently will affect the performance of your system.
  • dadu369
    dadu369 edited September 2018
    @HowUTrade Thanks a lot for your to-the-point response. Some doubt remain. This is my first week as a Kite developer, and have gone through almost all the vba posts in this forum. I appreciate your work and support as kiteXl.

    (a) If I understand correctly, strategy code is just an arbitrary name, described while placing an order.
    e.g.

    Function StrategyAOrder()
    If Condition is true then StrategyAOrder=PlaceBOBridge( .........,"A", ......)
    End Fiunction

    (b) Yes that will be great. I will drop an mail to you.

    (e) I think the only option we are left with is to always have (margin + max loss) money in account and to calculate quantities based on this margin only.

    Thanks in advance.
  • HowUTrade
    @dadu369

    (a) Yes, StgyCode is just an arbitrary name, passed to PlaceOrder function. It should be 2 characters and alphanumeric.

    (e)Yes, before start of the day, you should know how many trades you are going to take, what is max margin required, what will be max possible loss and accordingly keep margin.
  • dadu369
    dadu369 edited September 2018
    @HowUTrade
    Thank you for your valuable comments. Seems that islive is taking value from B24 of Excel_Template, but unable to find where it is defined.
    Seems that OHLC fields of market watch are updating slowly as compared to LTP. where and how can I define throttle interval?
  • dadu369
    dadu369 edited September 2018
    @HowUTrade Any idea to auto cancel a bracket order if hasn't been executed within 10-15 mins of its placement?
  • dadu369
    @HowUTrade thanks for your great help.

    1. As per above suggestion, I have written below UDF to cancel a bracket order unexecuted in 15 mins. But it returns #VALUE instead of "" . Please rectify the code.
    Public Function CANCEL15MINS(ByVal Exch As String, ByVal TrdSym As String, ByVal cTag As String)

    If Not GetOrderCTag(Exch, TrdSym, cTag) Is Nothing Then
    ID = GetOrderCTag(Exch, TrdSym, cTag)
    timenow = Time(Hour(Now()), Minute(Now()), Second(Now()))
    Status = GetOrderStatus(ID)
    TYM = GetOrderTime(ID)
    DIFF = (timenow - TYM) * 86400

    If DIFF > 900 AND Status = "OPEN" Then
    CANCEL15MINS = CancelBOMainBridge(ID, True)

    Else: CANCEL15MINS = ""
    End If
    End If
    End Function
    2. Below is the code written to square off all bracket orders at 3:05 PM. It has been assumed that for a given symbol if position exists it will exit, else error handler will do its work.

    But the problem is when written in KiteXl and we open next time, it starts showing Automation error, and then the workbook becomes unusable. Please let me know if are able to identify any possible bug.

    Please also help in previous code sent for exiting an open bracket order.
    Private Sub Workbook_Open()

    Application.OnTime TimeValue("15:05:00"), "ExitAll"

    End Sub
    -----------------------------------------------

    Sub ExitAll()

    Exch = "NSE"
    TrdSym = Sheets("Excel_Template").Range("F3")

    StgyCode = Array("A1", "A2", "A3")

    For i = 0 To 205
    For j = 0 To 2

    Sym = Sheets("Excel_Template").Range("F3").Offset(i, 0)
    cTag = Sym & StgyCode(j)

    Func = ExitBOByTag(Exch, Sym, cTag, StgyCode(j), "TRUE", "TRUE")

    Next
    Next

    End Sub
    3. How to get OHLC/LTP data for nifty 50, bank nifty with both NSE/NFO as Exch. What can be the reason?
    4. Looks live Market Watch is showing wrong high value for CANBK, it should be 270.85 , instead of 269.2.
  • HowUTrade
    @dadu369

    Regarding 'Automation Error', you can refer the below link.
    This is a very peculiar issue with excel.
    https://howutrade.in/2018/07/17/excel-error-activex-component-cant-create-object-kitenetupstoxnet-dll-update/

    This error happens with any COM dll, but the exact cause is unknown.
    You can follow the troubleshoot mentioned in the above link to rectify the error in your existing workbook.

    To get index data,
    Use exch as NSE_INDEX
    You can find the indices list post login in the below folder.
    My Documents\KiteNet\[ddMMMyyy]\NSE_Index.txt

    For point4,
    KiteNet just streams whatever the data received from Kite API server,
    first check the data using Market Depth of KiteNet/KiteXL. If the data is correct in Market Depth of KiteNet/KiteXL but not in Kite RTD, then some issue with Kite RTD server.
    If the data is wrong in both Market Depth of KiteNet/KiteXL and Kite RTD server, then you can raise this issue with Kite Admin @sujith .

    For rest queries, we will update sometimes later...
  • dadu369
    dadu369 edited September 2018
    @HowUTrade Thank you..resolved both codes.

    Instead of calling through Application.OnTime when called directly ExitAll() could exit all orders except one. Perhaps that was due to async. What does Isresetsignal mean?
    2. Any way to know if an open bracket order was a buy or sell, other than including it in cTag? and what was its SL value?
Sign In or Register to comment.