Buy order working but sell order not working using pmClient

Here are my commands:

pm.place_order(txn_type=“B”, exchange=“NSE”, segment=“E”, product=“C”, security_id=“3351”, quantity=1, validity=“DAY”, order_type=“LMT”, price=1004, source=“W”, off_mkt_flag=False)

pm.place_order(txn_type=“S”, exchange=“NSE”, segment=“E”, product=“C”, security_id=“3351”, quantity=1, validity=“DAY”, order_type=“LMT”, price=1004, source=“W”, off_mkt_flag=False)

These are same but first is for Buy and second is for Sell. The first one is working successfully but second one is failing with error:
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\pyPMClient-master\pmClient\pmClient.py”, line 116, in place_order
return self.api_call_helper(helper, Requests.POST, None, order)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\NSE\pyPMClient-master\pmClient\apiService.py”, line 20, in api_call_helper
raise AttributeError(response.text)
AttributeError: {“status”:400,“message”:“Bad Request”,“error_code”:“PM_OPEN_API_400”}

Please help.

1 Like

Hi 9899281828,
Thank you for your query,

While placing the buy/sell order please use product=“I”, this will solve your issue.

I (Intraday)(Valid for Segment= E/D)
C ((Cash and Carry / Delivery) Valid only for Segment=‘E’)
E = Equity, D= Derivative

Q: Why are you getting Bad requests?
A: When you try to sell a stock for product C, you need to have that stock in your portfolio and also you need to complete the edis authorization for the day then you will not get this error.

1 Like

So do you mean, even though the stock is in my portfolio, I should sale for product “I” though I am not doing intraday trading?

if you have the stock in your portfolio and you want to sell as product C, you need to complete the edis authorization for the day then you will not get this error.

2 Likes

Please refer
https://developer.paytmmoney.com/docs/api/edis-authorisation-status-api/

2 Likes

Thank you Ravi for your help. but sorry I am still not clear about values for edis_txn_id & edis_auth_mode paramters.
Is edis_txn_id TPIN?
And what is the value of edis_auth_mode?

Step 1: if TPIN is not generated earlier, once you run this, you will receive it on your phone and email from CDSL:
# %%
# Generate TPIN
pm.generate_tpin()

Step 2: At this stage, you need to send the ISIN list and quantity to want to authorize to sell.

# %%
# Validate TPIN order
print(pm.validate_tpin("PRE", isin_list= [
        {
            "isin": "INE114A01011",
            "qty": 1
        }
    ]))

In response you will get 

    DpId: 
    ReqId: 
    Version: 
   TransDtls:


After getting this response we need to submit the form in the browser using "form" tag with the "action" attribute value as "https://eDIS.cdslindia.com/eDIS/VerifyDIS" and the "method" attribute value as "post" and all the details from the response in the fields.

Please find below an example HTML form:

<!DOCTYPE HTML>
<html xmlns:th="https://www.thymeleaf.org">
<head>
    <title>Submit TPIN Req to CDSL</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Request TPIN</h1>
<form action="https://eDIS.cdslindia.com/eDIS/VerifyDIS" method="post">
    <p>DpId: <input type="text"  name="DpId"/></p>
    <p>ReqId: <input type="text" name="ReqId"/></p>
    <p>Version: <input type="text" name="Version"/></p>
    <p>TransDtls: <input type="text" name="TransDtls"/></p>
    <p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>

Once you click on submit, you will be redirected to a CDSL web page, where you need to enter TPIN, then OTP.

Once  TPIN and OTP are submitted successfully, you will get a blank page otherwise there will be some error message in the webpage from CDSL. 

After TPIN request to CDSL is submitted successfully there will be query param "ReqId" in the redirect url "https://www.paytmmoney.com/stocks/edis-redirect?ReqId=15811127". 

You need to use that query param "ReqId" value in the below given eDIS status method to check which "ISIN" are validated.

# %%
# Check status
print(pm.status(15811127))


Once it is done, you can place your delivery sell order.

2 Likes

Hi, you need not pass edis_txn_id & edis_auth_mode parameters while placing sell CNC order,
these params are obsolete now.

I hope we have resolved your query, If you require any further clarification, please let us know.