import xlwings as xw
from Zerodha_Tradehull import Tradehull
import talib
wb = xw.Book('trial py algo.xlsx')
sheet = wb.sheets['Sheet1']
api_key = " "
api_secret = " "
tsl = Tradehull(api_key, api_secret, "yes")
kite = tsl.kite
sl_pct = 1
for row_no in range(2,13):
name = sheet['A'+ str(row_no)].value
ltp = tsl.get_data_for_single_script(exchange="NSE", name=name, call_type="ltp")
chart = tsl.get_short_length_hist_data(name=name, exchange="NSE", interval="5minute", oi = True)
chart['rsi'] = talib.RSI(chart['close'], timeperiod=14)
# rsi = talib.RSI(chart['close'], timeperiod=14)
sheet['B'+ str(row_no)].value = ltp
sheet['C'+ str(row_no)].value = chart.iloc[-1]['rsi']
buy_signal = sheet['E'+ str(row_no)].value
sell_signal = sheet['F'+ str(row_no)].value
qty = sheet['G'+ str(row_no)].value
if buy_signal == "BUY":
sl_price = round(ltp * (1 - sl_pct/100),1)
entry_id = tsl.place_order(variety= "amo", exchange= "NSE", tradingsymbol= name, transaction_type= "BUY", quantity= qty, product= "MIS", order_type= "MARKET")
stoploss_id = tsl.place_order(variety= "amo", exchange= "NSE", tradingsymbol= name, transaction_type= "SELL", quantity= qty, product= "MIS", order_type= "sl-M", trigger_price= sl_price)
Traceback (most recent call last):
File "c:\Users\shubh\AppData\Local\Programs\Python\Python38\lib\site-packages\Zerodha_Tradehull\Zerodha_Tradehull.py", line 1260, in place_order
order_id = self.kite.place_order(variety=variety, exchange=exchange, tradingsymbol=tradingsymbol, transaction_type=transaction_type, quantity=quantity, product=product, order_type=order_type, price=price, validity=validity, disclosed_quantity=disclosed_quantity, trigger_price=trigger_price, validity_ttl= validity_ttl,iceberg_legs = iceberg_legs, iceberg_quantity=iceberg_quantity, auction_number= auction_number, tag=tag)
File "c:\Users\shubh\AppData\Local\Programs\Python\Python38\lib\site-packages\kiteconnect\connect.py", line 361, in place_order
return self._post("order.place",
File "c:\Users\shubh\AppData\Local\Programs\Python\Python38\lib\site-packages\kiteconnect\connect.py", line 865, in _post
return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
File "c:\Users\shubh\AppData\Local\Programs\Python\Python38\lib\site-packages\kiteconnect\connect.py", line 937, in _request
raise exp(data["message"], code=r.status_code)
kiteconnect.exceptions.InputException: Missing or empty field `quantity`
i am checking the quantity but output not comes??
Hi @7350982949 ,
It seems in excel the cell is empty or returning None, make sure you give correct quantity to place order.
qty = sheet['G'+ str(row_no)].value