option order is not placing
-
i have try to place order in nifty option but not able to place
from smartapi import SmartConnect
from smartapi import SmartWebSocket
import login as lobj=SmartConnect(api_key=l.api_key)
data = obj.generateSession(l.user_name,l.password)
refreshToken= data['data']['refreshToken']
#fetch the feedtoken
feedToken=obj.getfeedToken()
l.feed_token = feedToken
#fetch User Profile
userProfile= obj.getProfile(refreshToken)try:
orderparams = {
"variety": "NORMAL",
"tradingsymbol": "NIFTY25NOV2117600CE",
"symboltoken": "54385",
"transactiontype": "buy",
"exchange": "NFO",
"ordertype": "LIMIT",
"producttype": "CARRYFORWARD",
"duration": "DAY",
"price": "0",
"squareoff": "0",
"stoploss": "0",
"quantity": "1"
}
orderId=obj.placeOrder(orderparams)
print("The order id is: {}".format(orderId))
except Exception as e:
print("Order placement failed: {}".format(e.message))error showing :
Traceback (most recent call last):
File "C:\Users\rishi\PycharmProjects\pythonProjectnew\venv\lib\site-packages\smartapi\smartConnect.py", line 188, in request
data = json.loads(r.content.decode("utf8"))
File "C:\Program Files\Python310\lib\json_init.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Program Files\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files\Python310\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\rishi\PycharmProjects\pythonProjectnew\error.py", line 36, in <module>
orderId=obj.placeOrder(orderparams)
File "C:\Users\rishi\PycharmProjects\pythonProjectnew\venv\lib\site-packages\smartapi\smartConnect.py", line 290, in placeOrder
orderResponse= self._postRequest("api.order.place", params)['data']['orderid']
File "C:\Users\rishi\PycharmProjects\pythonProjectnew\venv\lib\site-packages\smartapi\smartConnect.py", line 220, in _postRequest
return self._request(route, "POST", params)
File "C:\Users\rishi\PycharmProjects\pythonProjectnew\venv\lib\site-packages\smartapi\smartConnect.py", line 191, in _request
raise ex.DataException("Couldn't parse the JSON response received from the server: {content}".format(
smartapi.smartExceptions.DataException: Couldn't parse the JSON response received from the server: b''During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\rishi\PycharmProjects\pythonProjectnew\error.py", line 39, in <module>
print("Order placement failed: {}".format(e.message))
AttributeError: 'DataException' object has no attribute 'message'please tell how to squareoff order in option
-
-
@rajanprabu i have try with market order but result is same
-
Hi @rishi6310 said in option order is not placing:
please tell how to squareoff order in option
it is similar how you do it in equity and other segment initiate reverse order to the one which you entered while executing keeping the transaction type as sell and other parameters same.
-
@admin i have try this but it executed order on sell side and my position doesn't square in option
-
@rishi6310 send us the request which you executed to take the position and the req which you executed for selling.