Python client function for margins/orders? (2024)

zuser November 2020 in Python client

Hi,

What is function of Python client for margin calculation of an order as mentioned https://kite.trade/docs/connect/v3/margins/ ?

  • sujith November 2020

    @zuser,
    pykiteconnect doesn't have it yet. We are working on it.

  • milli November 2020

    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 November 2020

    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 November 2020 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 November 2020

    @milli,
    Here is the Java example. Params are exactly the same, the way you interact with the python request library might be different.

  • milli November 2020

    @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 November 2020

    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 November 2020

    hi @sujith @rakeshr

    Can I not use

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

    to get the currently required margin for currency derivatives?

    Thanks

  • sujith November 2020

    @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 December 2020

    Margin APIs is added to python client. You can update to the latest version using pip install --upgrade kiteconnect.

  • milli December 2020

    @rakeshr Thanks a lot. Where can I find documentation about this ?

  • omkarkondhekar December 2020

    The changelog in GitHub repo is not updated one

  • rakeshr December 2020

    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 December 2020

    Is the API doc not updated? Which function to use and how to use it ? Details would be highly appreciated. @rakeshr

  • marimusicman December 2020

    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 December 2020

    @marimusicman,
    We don't have baskets margin API yet. This feature will be available once the baskets margin calculation API is released.

  • sabyasm December 2020

    @sujith
    What would be the python equivalent call for https://api.kite.trade/margins/equity ?

  • rakeshr December 2020

    @sabyasm
    You can use this method to fetch margin for order/orders. You can check python example here.

  • sabyasm December 2020

    @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

  • sabyasm December 2020

    @rakeshr @sujith

  • rakeshr December 2020

    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 December 2020

    @rakeshr Thanks Rakesh - appreciate your help!

This discussion has been closed.

Python client function for margins/orders? (2024)

References

Top Articles
Latest Posts
Article information

Author: Dr. Pierre Goyette

Last Updated:

Views: 5764

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Dr. Pierre Goyette

Birthday: 1998-01-29

Address: Apt. 611 3357 Yong Plain, West Audra, IL 70053

Phone: +5819954278378

Job: Construction Director

Hobby: Embroidery, Creative writing, Shopping, Driving, Stand-up comedy, Coffee roasting, Scrapbooking

Introduction: My name is Dr. Pierre Goyette, I am a enchanting, powerful, jolly, rich, graceful, colorful, zany person who loves writing and wants to share my knowledge and understanding with you.