Convert NRML to MIS content-type error

FoxTradingSolutions
When I am trying to convert my NRML position to MIS it is giving content-type error.

Here is the code
kite.convert_position(exchange = 'NFO'
tradingsymbol = 'NIFTY22MAYFUT',
quantity = -50,
transaction_type = 'SELL' if quantity <= -1 else 'BUY',
position_type = 'overnight',
old_product = 'NRML' ,
new_product = 'MIS')
  • SRIJAN
    Please post the exact error stacktrace or debug logs.
  • FoxTradingSolutions
    ---------------------------------------------------------------------------
    KeyError Traceback (most recent call last)
    C:\Users\user\AppData\Local\Temp/ipykernel_12748/655508613.py in
    ----> 1 kite.convert_position(exchange='NFO',
    2 tradingsymbol='NIFTY22MAYFUT',
    3 transaction_type='SELL',
    4 position_type='overnight',
    5 quantity=-50,

    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in convert_position(self, exchange, tradingsymbol, transaction_type, position_type, quantity, old_product, new_product)
    452 new_product):
    453 """Modify an open position's product type."""
    --> 454 return self._put("portfolio.positions.convert", params={
    455 "exchange": exchange,
    456 "tradingsymbol": tradingsymbol,

    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in _put(self, route, url_args, params, is_json, query_params)
    843 def _put(self, route, url_args=None, params=None, is_json=False, query_params=None):
    844 """Alias for sending a PUT request."""
    --> 845 return self._request(route, "PUT", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
    846
    847 def _delete(self, route, url_args=None, params=None, is_json=False):

    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in _request(self, route, method, url_args, params, is_json, query_params)
    896
    897 # Validate the content type.
    --> 898 if "json" in r.headers["content-type"]:
    899 try:
    900 data = json.loads(r.content.decode("utf8"))

    ~\anaconda3\lib\site-packages\requests\structures.py in getitem(self, key)
    52
    53 def getitem(self, key):
    ---> 54 return self._store[key.lower()][1]
    55
    56 def delitem(self, key):

    KeyError: 'content-type
  • SRIJAN
    SRIJAN edited May 2022
    Due to some technical glitch,the server returned no content probably,so there was no 'content-type' in the headers of the reponse.
    So,the requests library gave key error.

    You have to retry incase something like this happens.
  • FoxTradingSolutions
    Have retried may times, this happened on Friday and today as well
  • rakeshr
    rakeshr edited May 2022
    quantity = -50,
    You are sending wrong quantity param. Quantity should be positive integer i.e 50 here. As you are already sending transaction_type as SELL.
  • FoxTradingSolutions
    tried this as well, it also didn't work.
  • rakeshr
    Can you paste here the complete debug log for the PUT request as explained here?
  • FoxTradingSolutions
    FoxTradingSolutions edited May 2022
    kite.convert_position(exchange='NFO',
    tradingsymbol='NIFTY22MAYFUT',
    transaction_type='SELL',
    position_type='overnight',
    quantity= 50,
    old_product='NRML',
    new_product='MIS')
    error:-

    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "PUT /portfolio/positions HTTP/1.1" 500 116
    send: b'PUT /portfolio/positions HTTP/1.1\r\nHost: api.kite.trade\r\nUser-Agent: Kiteconnect-python/4.0.2\r\nAccept-Encoding: gzip, deflate, br\r\nAccept: */*\r\nConnection: keep-alive\r\nX-Kite-Version: 3\r\nAuthorization: token XXXXXXXXXX:XXXXXXXXXX\r\nContent-Length: 131\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'
    send: b'exchange=NFO&tradingsymbol=NIFTY22MAYFUT&transaction_type=SELL&position_type=overnight&quantity=50&old_product=NRML&new_product=MIS'
    reply: 'HTTP/1.1 500 Internal Server Error\r\n'
    header: Date: Thu, 12 May 2022 07:16:18 GMT
    header: Content-Type: application/json
    header: Content-Length: 116
    header: Connection: keep-alive
    header: CF-Cache-Status: DYNAMIC
    header: Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    header: Strict-Transport-Security: max-age=15552000; includeSubDomains
    header: Server: cloudflare
    header: CF-RAY: 70a15e3e9dd88e7e-DEL
    ---------------------------------------------------------------------------
    GeneralException Traceback (most recent call last)
    C:\Users\PRINCE~1\AppData\Local\Temp/ipykernel_8552/16661507.py in
    ----> 1 kite.convert_position(exchange='NFO',
    2 tradingsymbol='NIFTY22MAYFUT',
    3 transaction_type='SELL',
    4 position_type='overnight',
    5 quantity= 50,

    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in convert_position(self, exchange, tradingsymbol, transaction_type, position_type, quantity, old_product, new_product)
    452 new_product):
    453 """Modify an open position's product type."""
    --> 454 return self._put("portfolio.positions.convert", params={
    455 "exchange": exchange,
    456 "tradingsymbol": tradingsymbol,

    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in _put(self, route, url_args, params, is_json, query_params)
    843 def _put(self, route, url_args=None, params=None, is_json=False, query_params=None):
    844 """Alias for sending a PUT request."""
    --> 845 return self._request(route, "PUT", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
    846
    847 def _delete(self, route, url_args=None, params=None, is_json=False):

    ~\anaconda3\lib\site-packages\kiteconnect\connect.py in _request(self, route, method, url_args, params, is_json, query_params)
    911 # native Kite errors
    912 exp = getattr(ex, data.get("error_type"), ex.GeneralException)
    --> 913 raise exp(data["message"], code=r.status_code)
    914
    915 return data["data"]

    GeneralException: Enterd Qty cannot be greater than Net qty
  • rakeshr
    'HTTP/1.1 500 Internal Server Error\r\n'
    GeneralException: Enterd Qty cannot be greater than Net qty
    Are you sure, the above exception message is from kiteconnect python client?
    As, we return `quantity` should be a multiple of lot size {lot_size} for invalid qty with HTTP 400.
    User-Agent: Kiteconnect-python/4.0.2
    you seem to be also on latest python client version.
    1 kite.convert_position(exchange='NFO',
    2 tradingsymbol='NIFTY22MAYFUT',
    3 transaction_type='SELL',
    4 position_type='overnight',
    5 quantity= 50,
    Re-inspect, all of these values are correct.
Sign In or Register to comment.