Python client function for margins/orders?

zuser
Hi,

What is function of Python client for margin calculation of an order as mentioned https://kite.trade/docs/connect/v3/margins/ ?
  • sujith
    @zuser,
    pykiteconnect doesn't have it yet. We are working on it.
  • milli
    Is there a manual way to calculate the margin required for an instrument & order type combination? Say for example, if I placed an order for CDS:USDINR20DECFUT NRML type, to find the margin would there be a percentage like LTP x 1000 x percentage to find the margin?

    Thanks
  • rakeshr
    Calculating margin is a bit difficult to be done at your end. As it not only depends on the LTP movement but also on other factors like existing positions, open orders, etc. You can use open margin calculation APIs. Also, we will be integrating this API soon with all our official clients including python.
  • milli
    milli edited November 2020
    @rakeshr is there a sample code that can give an outline on integrating

    https://kite.trade/docs/connect/v3/margins/

    with the python code? Any pointers would help.

    Thanks a lot.
  • sujith
    @milli,
    Here is the Java example. Params are exactly the same, the way you interact with the python request library might be different.
  • milli
    @sujith thanks, I will study and get back.

    Meanwhile, as a quick hack and to get things up and running quickly ; would a 4% margin for currency derivatives be sufficient to cover the various parameters as mentioned by @rakeshr ? I am mainly interested in USDINR and GBPINR.

    Thanks
  • rakeshr
    would a 4% margin for currency derivatives be sufficient to cover the various parameters
    No. The Span margin varies for both CDS contracts.
    If you are in so hurry, maybe you can try using this branch of Connect Python client(which has Margin APIs integrated, but the test is still going on).
  • milli
    hi @sujith @rakeshr

    Can I not use

    https://api.kite.trade/margins/currency

    to get the currently required margin for currency derivatives?

    Thanks
  • sujith
    @milli,
    It only gives you data about the leverage. You will have to use that for calculation and it is manually updated by the RMS team which can be updated multiple times during the day as well.
    If you are looking for a straight forward solution like margin = qty * last price then you can use this. If you want the exact values which depend on your portfolio and pending orders then you need to use this.

  • rakeshr
    Margin APIs is added to python client. You can update to the latest version using pip install --upgrade kiteconnect.
  • milli
    @rakeshr Thanks a lot. Where can I find documentation about this ?
  • omkarkondhekar
    The changelog in GitHub repo is not updated one
  • rakeshr
    Where can I find documentation about this ?
    You can check out documentation here.
    The changelog in GitHub repo is not updated one
    Thanks. We will update this.
  • milli
    Is the API doc not updated? Which function to use and how to use it ? Details would be highly appreciated. @rakeshr
  • marimusicman
    Hi,

    I have been trying to get margin required for option spreads (i.e. bear call spread etc.). When I pass a list of orders with the same, I don't get the margin required as per the latest margin guidelines or as per your F&O margin calculator. Can you please help?
  • sujith
    @marimusicman,
    We don't have baskets margin API yet. This feature will be available once the baskets margin calculation API is released.
  • sabyasm
    @sujith
    What would be the python equivalent call for https://api.kite.trade/margins/equity ?
  • rakeshr
    @sabyasm
    You can use this method to fetch margin for order/orders. You can check python example here.
  • sabyasm
    @rakeshr the api call provides the necessary info for about 500 scrips in one go whereas for the python call you'll have to build each and every order_param_multi .

    Can we get an array or dataframe through python API exactly same as what's being returned via https://api.kite.trade/margins/equity
  • rakeshr
    Can we get an array or data frame through python API exactly the same?
    No, we don't have a specific python method for this. You can just fetch value from this link https://api.kite.trade/margins/equity. Maybe use the python requests library, and return JSON/List, which is easy to filter. Something like:
    import requests,json
    headers = {'cache-control': 'no-cache'}
    equityURL = 'https://api.kite.trade/margins/equity'
    equityMargin = requests.request('GET',equityURL, headers=headers).json()
    print(equityMargin)
  • sabyasm
    @rakeshr Thanks Rakesh - appreciate your help!
This discussion has been closed.