Margin Calculator in Python


  • Hi, Can someone help me share the code of the Margin calculator I tried the one shared on https://smartapi.angelbroking.com/docs/MarginCalculator but it's not working for me.
    Below is the code:
    import http.client

    conn = http.client.HTTPSConnection("apiconnect.angelbroking.com")
    payload = "{\n" +
    " "positions": [\n" +
    " {\n" +
    " "exchange": "NFO",\n" +
    " "qty": 50,\n" +
    " "price": 0,\n" +
    " "productType": "INTRADAY",\n" +
    " "token": "67300",\n" +
    " "tradeType": "BUY"\n" +
    " },\n" +
    " {\n" +
    " "exchange": "NFO",\n" +
    " "qty": 50,\n" +
    " "price": 0,\n" +
    " "productType": "INTRADAY",\n" +
    " "token": "67308",\n" +
    " "tradeType": "SELL"\n" +
    " }\n" +
    " ]\n" +
    "}"
    headers = {
    'X-PrivateKey': 'API_KEY',
    'Accept': 'application/json',
    'X-SourceID': 'WEB',
    'X-ClientLocalIP': 'CLIENT_LOCAL_IP',
    'X-ClientPublicIP': 'CLIENT_PUBLIC_IP',
    'X-MACAddress': 'MAC_ADDRESS',
    'X-UserType': 'USER',
    'Authorization': 'Bearer AUTHORIZATION_TOKEN',
    'Accept': 'application/json',
    'X-SourceID': 'WEB',
    'Content-Type': 'application/json'
    }
    conn.request("POST", "/rest/secure/angelbroking/margin/v1/batch", payload, headers)
    res = conn.getresponse()
    data = res.read()
    print(data.decode("utf-8"))

    pls help me out.