Error in getting margin with curl in Python

import requests

url = ‘https://api.fyers.in/api/v2/span_margin’

headers = {

'Authorization': client_token,

'Content-Type': 'application/json'

}

data1 = {

"data" : [

        {

        "symbol": "NSE:BANKNIFTY23O0443000CE",

        "qty": 15,

        "side": -1,

        "type": 2,

        "productType": "CNC",

        "limitPrice": 0.0,

        "stopLoss": 0.0

        }

        , {

        "symbol": "NSE:BANKNIFTY23O0443000PE",

        "qty": 15,

        "side": -1,

        "type": 2,

        "productType": "CNC",

        "limitPrice": 0.0,

        "stopLoss": 0.0

        }

        ]}

json_data = json.dumps(data1)

curl_command = [

'curl',

'--location',

'--request',

'POST',

'[https://api.fyers.in/api/v2/span_margin](https://api.fyers.in/api/v2/span_margin)',

'--header',

'Authorization: xxx’,

'header',

'Content-Type: application/json',

'--data-raw',

json_data

]

try:

output = subprocess.check_output(curl_command, stderr=subprocess.STDOUT)



st.write(output.decode('utf-8'))  # Print the output as a string

except subprocess.CalledProcessError as e:

print(f"Error executing cURL command: {e}")

Error

Error executing cURL command

‘–data-raw’, ‘{“data”: [{“symbol”: “NSE:BANKNIFTY23O0443000CE”, “qty”: 15, “side”: -1, “type”: 2, “productType”: “CNC”, “limitPrice”: 0.0, “stopLoss”: 0.0}, {“symbol”: “NSE:BANKNIFTY23O0443000PE”, “qty”: 15, “side”: -1, “type”: 2, “productType”: “CNC”, “limitPrice”: 0.0, “stopLoss”: 0.0}]}’]’ returned non-zero exit status 3.

import requests

url = 'https://api.fyers.in/api/v2/span_margin'

headers = {
    'Content-Type' : 'application/json',
    'Authorization': 'Your token '
}

data = {
    "data": [
        {
            "symbol": "NSE:BANKNIFTY23O0444300CE",
            "qty": 15,
            "side": 1,
            "type": 2,
            "productType": "INTRADAY",
            "limitPrice": 0.0,
            "stopLoss": 0.0
        }
    ]
}

response = requests.post(url, json=data, headers=headers)

print("Developer Debug ", response.text)
if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Request failed with status code: {response.status_code}")

Try with this code, it will work.

Thanks a lot. It works!