Which API function gives me at what price the CO Order has been created

catchmaheshkcf
Hello Support
I have created and integrated my Algo in the KiteXL excel sheet. Just to brief my algo checks some parameters and the study of the stocks (this data I provide) that I have done, the result of my study is, it says direction of a particular stock, it may be Up or Down. So if the stocks is selected, it either buys or short. Now I have a doubt for example if a particular stock say A is selected and the same has to be Short, the algo places a CO order with a stop loss, to be more specific if the current market price of the stock A is 100 I set the stop loss to 101, now at the time when this CO order reaches the exchange there can be a possibility that the market price has gone to 102 so the Sell order will be executed at 102, now since the stop loss is set to 101 I will have to modify the SL (in this case to 103) as per the price of the Sell order, which API function gives me at what price the Sell order was executed
  • catchmaheshkcf
    I got these two API functions
    GetOrderDetails Method
    Public Function GetOrderDetails (
    OrderId As String
    ) As String
    returns output in this format
    Order Details as Csv in the below format
    EXCHANGE,TOKEN,SYMBOL,PRODUCT,ORDER_TYPE,PRICE,TRIGGER_PRICE,QUANTITY,TRANSACTION_TYPE,AVERAGE_PRICE,TRADED_QUANTITY,MESSAGE,EXCHANGE_ORDER_ID,PARENT_ORDER_ID,ORDER_ID,ORDER_TIME,STATUS
    I believe the PlaceCO function in KiteXL will return the Order ID and the same has to be used for this function correct ? (Does it also return the order id of the Stop Loss order that has the status as Trigger Pending)
    GetOrderStatus Method,
    Public Function GetOrderStatus (
    OrderId As String
    ) As String
    returns One of the Order Status OPEN|TRIGGER PENDING|COMPLETE|CANCELLED|REJECTED, I believe to get the status the Order Id returned by the PlaceCO function in KiteXL (how do I get the order Id of the SL order of the CO order)
  • HowUTrade
    @catchmaheshkcf

    You need to call GetChildOrders function by passing the OrderId returned by PlaceCO to get the child order.

    To put it simple:
    PlaceOCO will return OrderId of the MainOrder i.e. Ist leg. You need to store this OrderId.
    GetChildOrders(OrderId-Main) will return OrderId of the Stoploss Order i.e. 2nd leg.
    Now you got two OrderId's.

    To get OrderStatus of MainOrder
    Call GetOrderStatus(Orderid-Main)

    To get price at which the MainOrder is filled
    Call GetOrderFilledPrice(Orderid-Main)

    To get OrderStatus of StoplossOrder
    Call GetOrderStatus(Orderid-Stoploss)

    Function names that start with GetOrder* are used to retrieve order specific information.
  • catchmaheshkcf
    Thanks a lot for the quick response, I had some more queries,
    Since the PlaceCO function will be executed by the system does the execution wait until the PlaceCO function returns the Order ID or the next line of code is executed what I mean to say is does the line of code gets executed Synchronously or Asynchronously.
    The reason for asking this question is I would be storing the Order id and child Order id of every stock that my algo has selected. Also I would be checking if filled price is less then the Stop Loss in case of a Sell order and similarly the filled price is greater than the Stop Loss in case of a Buy order.

    I believe to modify the SL I will have to use the Child Order ID that is
    ModifyCOSl(ChildOrderID-2nd leg, Trigger price) - correct ?
  • catchmaheshkcf
    I just checked in the documentation of ModifyCOSl and found that
    the order id of the SL has to be used
  • HowUTrade
    @catchmaheshkcf
    All order request functions such as PlaceCO, ModifyCOSl etc are synchronous commands.
    So it will either return OrderId (If everything is ok) or will throw error on timeout.

    Here the timeout occurs mainly for 2 reasons.
    1. Network congestion at Kite server or Kite server unable to process your request due to some issues at kite end.
    2. Your internet connection is fluctuating or dropped.

    Yes, to modify stoploss, you need to call ModifyCOSl(ChildOrderID-2nd leg, Trigger price)

    Also have a look at Custom tag.
    You can go through this link. The link is written for UpstoxNet, but holds good for KiteNet also.

    Please note,
    The GetOrder* functions depends on order updates received through websocket.
    If any order update is missed due to issues at kite end or network drop at your end, these functions will return last stored status.

    The GetOrder* functions are the best part of KiteNet, as it stores the order details received through web-socket and returns values from memory. So it will not pull order details from kite server.

    Example:
    Even if you call 1000 times GetFilledPrice, it won't take more than 1sec and also will not have any impact on your system.

    But if you try to get filledprice from Kite server, it will take > 1sec/request to get data from kite server in normal time and if any network congestion it may take more time.
    If you have more orders to get filledprice, then you need to pull orderbook and loop through each order, process and store filledprice for each order. Again this is nightmare.
  • catchmaheshkcf
    Hello, Today I did paper trading by using the Bridge functions.
    on placing the bridge CO order that is PlaceCOBridge function, it returned the order id of the main leg,
    but I am encountering following issues
    1) To get the Child Order ID that is the SL order ID I executerd Getchildorders(Order id - Main Leg) it returned me "OrderId is null or invalid"
    2) To get the Order Status of the main order I used GetOrderStatus(Order id - Main leg) it returned me
    "OrderId is null or invalid"
    3 For some positions the price has hit the Triggerprice but the order is still open (checked in the Dashboard sheet by clicking on the Bridge Position button)
    4) To get the Filled price of the Main leg, I used GetOrderFilledPrice(Order ID - Main) it returned me
    "OrderId is null or invalid"
    5) Now since the Getchildorders(Orderid - Main leg) is returning me "OrderId is null or invalid" how will i exit the
    Trades
    6) Since the GetOrderStatus(Order id - Main Leg) is returing me "OrderId is null or invalid" I am not able to check the status for further processing
    Could you please help
  • HowUTrade
    @catchmaheshkcf

    The GetOrder* functions will return values only for real orders.
    Paper trading is very limited option to check simulated PnL on your Buy/Sell/Short/Cover.
    https://howutrade.in/docs/kitenet/html/Introduction.htm#Section25

    Here is the article explains order placement through Bridgeclass.
    It is written for UpstoxNet, but holds good for KiteNet also.
    https://upstox.com/forum/topic/1339/bridge-method-get-orderid-ctag/6
    https://upstox.com/forum/topic/1339/bridge-method-get-orderid-ctag/7

    More info on Bridge class
    https://kite.trade/forum/discussion/comment/16629/#Comment_16629
  • catchmaheshkcf
    thanks a lot for the reply I will go through the links
  • catchmaheshkcf
    Thanks for links, now I will be placing live CO order in the system with 1 quantity I had one doubt, if I forcefully exit the CO order using the ExitCO method then how do I know at what price the CO order has been exit.
  • HowUTrade
    @catchmaheshkcf

    Exit price of CO is nothing but the average filled price (Executed price) of the child order (2nd leg order). The child order is a SELL order if main order is BUY and vice versa.

    Just get the order id of the child order and call
    Call GetOrderFilledPrice(Orderid-Child)

    Pls note, the names or tags, CO/BO/Regular etc are defined by Broker/OMS to identify how the order is placed and executed, by whom the order is placed, to calculate charges and margins.
    These are not universal.


    Universally, there exists only 2 kinds of transactions BUY & SELL

    Example:
    Product type MIS - informs broker to calculate Brkg for intraday

    In normal, you buy a stock and after some time you sell and vice versa.
    With tag CO, you only place a Buy order and sell order will be placed by broker (OMS) and vice versa.
    etc...

    Just remember BUY & SELL
  • catchmaheshkcf
    Thanks, got it, yesterday I actually tested some live transaction with by placing the PlaceCO function. I use the GetOrderStatus function in the cell to check the status, but unfortunately the status does not get updated automatically. Is there any way to get the order status updated automatically, for example the cells that contain the LTP, ATP ... gets updated automatically (Since these cells use the RTD function it gets updated automatically)
    Is there any way to use the Kite.OrderUpdateEvent Event in Excel VBA if yes then how do I go about
  • sujith
    sujith edited October 2018
    Posting on behalf of @HowUTrade,

    @catchmaheshkcf

    RTD is client-server model and works on the principle of Push-Pull mechanism.
    GetOrder* is a function and you (Excel) need to call this everytime you want result.

    Event handling in VBA is more complex.

    To update like RTD:
    We have to fool Excel by
    Making it volatile or Using dummy dynamic parameter.
    Later is recommended.

    Pls go through this link https://upstox.com/forum/post/2284
  • catchmaheshkcf
    Is it possible to get 1 minute intraday data download in csv format for all the 204 Future scrips. For example now if it is 12:00 PM and if I want to download 1 minute intraday data from 9:15 AM to 11:59 AM for all the 204 Future scrips, is is possible
  • HowUTrade
    Yes, on below conditions.
    1. You just need it one time.
    2. You have subscribed for Historical API

    Here you go GetHistDataBatch

    Basically, historical OHLC data is provided for off-line backtesting purpose.
    Even if you want to use it for real time, you need to pull that data once in the morning and compute today's candle from real-time data. But this requires more coding work.
    Pulling Historical data in real-time (say every 1min etc) is not at all recommended and will kill your application.

    Pulling data for 204 scrips is possible, but it may take at least 4-5 mins to download in normal time and may take more time if kite server is congested or your network speed is slow.
  • catchmaheshkcf
    Thanks, I would be upgrading my MS office from 32-bit to 64-bit, do I have to re-run the batch file that was provided with the KiteXL, My system is running Windows 10 Operation system on 64 bit
  • HowUTrade
    Better, you re-register the DLL.
    Post install of MS office, restart computer, the register DLL.

    Install test version from the below link, it has some bug fixes.
    https://kite.trade/forum/discussion/comment/17705/#Comment_17705

  • catchmaheshkcf
    Today I saw a very surprising situation on BATAINDIA18OCTFUT script, on the Kite web platform it shows on a 1 Minute scale, the 9:15 candle OPEN and HIGH which is equal to 876.20, on changing the scale from 1 minute to daily the OPEN and HIGH is still the same (at 10:15 AM). But in KiteXL it shows OPEN = 871.85 and HIGH = 876.75, which one is correct KiteXL or Kite web platform
  • HowUTrade
    @catchmaheshkcf
    KiteXL just returns whatever the data received from Kite API.
    KiteXL will not modify or truncate the data.

    As per NSE...
    Day Open : 871.85
    Day High : 876.75

    Avoid comparing Chart High with Day high, most of the time it will never match.
    The day high which is available in real time quotes and market depth is the correct one.
    Chart may or may not show correct day high as the candles are formed from received quotes.
  • catchmaheshkcf
    Thanks for the reply,
    Before subscribing for the Historical API data I had some below queries
    1 Can we access this API data in KiteXL (if yes then)
    2 Will this API give me live 1 min.,3 min. , 5 min. ,10 min. ,15 min... intraday data quotes
    (For example if the current time is 9:16 AM and I have entered a trade that is moving my direction, I would like to programatically trail (change) the SL based on the previous minute candle)

    Regards
  • catchmaheshkcf
    Could you please reply ?
  • catchmaheshkcf
    Checked previous posts and got the answer of my query.
  • HowUTrade
    @catchmaheshkcf
    Glad, you got the answer.
    We totally forgot this thread...

    Couple of points...
    The historical data provided by Kite API is purely meant for offline back-testing/analysis.
    You can easily import the data in to existing excel sheet or save as csv.
    Our sample sheet has a UDF which gets data from Kite server and writes that data to a sheet. You can use that as a start point.
    You will get candles up to last completed period only.
  • madhukar
    @HowUTrade
    In live mode bridge
    To exit BObridge I need to pass childorderid, but childorderids is a string of two long numbers saperated by comma, I guess first is for target and second for SL , so which one to pass?

    Same for modifyBObridge , do I need to saperate childorderids using split string? And then pass separately to modify SL or Tgt?

    How do I know the second id in string is always for SL?
  • catchmaheshkcf
    how to get the allowed range of price between the Market price and Trigger price in a CO order. For example I place a CO order for a particular stock and select Market, LTP is 100 if I enter 50 as Trigger price (in case of BUY CO order) it will reject the order. So is it possible to get the the Percentage price range between the LTP and Trigger price
  • HowUTrade
    @catchmaheshkcf

    Currently, no such function available in our KiteNet DLL.
    But Kite API provides this information.

    https://api.kite.trade/margins/equity
    Text/Csv Format: https://howutrade.in/brokerdata/symbol_list/equity_margin.txt
    Html Format (To import using Webquery): https://howutrade.in/brokerdata/symbol_list/?data=equity_margin

    You can fetch and store the details once in the morning.
  • catchmaheshkcf
    Is there any way in KiteXL, meaning is there any API available where in I can directly add stocks in Kite web platform from the stocks selected by my algo in KiteXL. The reason is before entering the trade I need to check some parameters manually in the chart. I hope you understood what I mean to say
  • HowUTrade
    HowUTrade edited March 2019
    @catchmaheshkcf

    It is not possible to add stocks from KiteXL to Kite Web MW.
  • catchmaheshkcf
    Is there any API that gives me ATR (Average True Range) Value at a particular point. for example I want to enter a trade at 9:45 AM, at this time can I get the ATR values
  • HowUTrade
    @catchmaheshkcf
    There is no API to get ATR values.
  • catchmaheshkcf
    Do you have any way to get leverages of all the FnO scrips
  • sujith
    You can check out this thread.
Sign In or Register to comment.