zerodha python api for futures trade not working

samirkelekar
I am unable to get kite python api working to place futures orders. I am able to place equity orders. I get an exception at the statement logging.info("Order placement failed {}".format(e.message)) with the error builtins.AttributeError: 'InputException' object has no attribute 'message' This makes it impossible to debug. Following is the code and after that the output.
Code:
print("symbol name is")
print(symbol_name)
print("quantity is")
print(quantity)
print("price is")
print(stock_futures_sell_value)
print("vaidity is")
print(kite.VALIDITY_DAY)
print("variety is")
print(kite.VARIETY_REGULAR)
print("exchange is")
print(kite.EXCHANGE_NFO)
print("transaction type is")
print(kite.TRANSACTION_TYPE_SELL)
print("product is")
print(kite.PRODUCT_NRML)
print("order_type is")
print(kite.ORDER_TYPE_LIMIT)
zerodha_nse_sell_futures_order_id = kite.place_order(variety=kite.VARIETY_REGULAR,
exchange=kite.EXCHANGE_NFO,
tradingsymbol=symbol_name,
transaction_type=kite.TRANSACTION_TYPE_SELL,
quantity=quantity,
product=kite.PRODUCT_NRML,
order_type=kite.ORDER_TYPE_LIMIT,
price=stock_futures_sell_value,
validity=kite.VALIDITY_DAY)
logging.info("Order placed Id is {}".format(zerodha_nse_sell_futures_order_id))
except Exception as e:
logging.info("Order placement failed {}".format(e.message))

Output:
symbol name is
NIFTY25AUGFUT
quantity is
50
price is
17696.65
vaidity is
DAY
variety is
regular
exchange is
NFO
transaction type is
SELL
product is
NRML
order_type is
LIMIT
Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 103, in callWithLogger
return callWithContext({"system": lp}, func, *args, **kw)
File "/usr/lib/python3/dist-packages/twisted/python/log.py", line 86, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/lib/python3/dist-packages/twisted/python/context.py", line 85, in callWithContext
return func(*args,**kw)
--- ---
File "/usr/lib/python3/dist-packages/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
why = selectable.doRead()
File "/usr/lib/python3/dist-packages/twisted/internet/tcp.py", line 243, in doRead
return self._dataReceived(data)
File "/usr/lib/python3/dist-packages/twisted/internet/tcp.py", line 249, in _dataReceived
rval = self.protocol.dataReceived(data)
File "/usr/lib/python3/dist-packages/twisted/protocols/tls.py", line 330, in dataReceived
self._flushReceiveBIO()
File "/usr/lib/python3/dist-packages/twisted/protocols/tls.py", line 295, in _flushReceiveBIO
ProtocolWrapper.dataReceived(self, bytes)
File "/usr/lib/python3/dist-packages/twisted/protocols/policies.py", line 120, in dataReceived
self.wrappedProtocol.dataReceived(data)
File "/home/ubuntu/.local/lib/python3.8/site-packages/autobahn/twisted/websocket.py", line 291, in dataReceived
self._dataReceived(data)
File "/home/ubuntu/.local/lib/python3.8/site-packages/autobahn/websocket/protocol.py", line 1213, in _dataReceived
self.consumeData()
File "/home/ubuntu/.local/lib/python3.8/site-packages/autobahn/websocket/protocol.py", line 1225, in consumeData
while self.processData() and self.state != WebSocketProtocol.STATE_CLOSED:
File "/home/ubuntu/.local/lib/python3.8/site-packages/autobahn/websocket/protocol.py", line 1591, in processData
fr = self.onFrameEnd()
File "/home/ubuntu/.local/lib/python3.8/site-packages/autobahn/websocket/protocol.py", line 1713, in onFrameEnd
self._onMessageEnd()
File "/home/ubuntu/.local/lib/python3.8/site-packages/autobahn/twisted/websocket.py", line 319, in _onMessageEnd
self.onMessageEnd()
File "/home/ubuntu/.local/lib/python3.8/site-packages/autobahn/websocket/protocol.py", line 634, in onMessageEnd
self._onMessage(payload, self.message_is_binary)
File "/home/ubuntu/.local/lib/python3.8/site-packages/autobahn/twisted/websocket.py", line 322, in _onMessage
self.onMessage(payload, isBinary)
File "/home/ubuntu/.local/lib/python3.8/site-packages/kiteconnect/ticker.py", line 71, in onMessage
self.factory.on_message(self, payload, is_binary)
File "/home/ubuntu/.local/lib/python3.8/site-packages/kiteconnect/ticker.py", line 673, in _on_message
self.on_ticks(self, self._parse_binary(payload))
File "options_data_aug_totp.py", line 575, in on_ticks
logging.info("Order placement failed {}".format(e.message))
builtins.AttributeError: 'InputException' object has no attribute 'message'







Tagged:
  • SRIJAN
    SRIJAN edited August 2022
    You can directly print the exception,like print(e) to get the exception message.

    Also,your instrument is NIFTY25AUGFUT.
    This is not a valid instrument, that's why place order API is throwing InputException.

    The correct format for tradingsymbol of future instruments is:

    Underlying+YY+1st 3 letters of the month+FUT.

    Like -NIFTY22AUGFUT.

    You can get the correct tradingsymbol for all instruments tradable for the day from the instruments dump:

    https://kite.trade/docs/connect/v3/market-quotes/#instruments
  • tahseen
    First step

    logging.info("Order placement failed {}".format(e.message))

    change it to

    logging.info("Order placement failed {}".format(e))
  • samirkelekar
    Thanks much Srijan and Tahseen. Very helpful.
This discussion has been closed.