from Zerodha_Tradehull import Tradehull
from rich import print
import talib
api_key = ""
api_secret = ""
tsl = Tradehull(api_key, api_secret, "yes")
kite = tsl.kite
watchlist = ["BANKBARODA", "BANKINDIA", "TORNTPOWER", "UJJIVANSFB", "UNIONBANK", "VIPIND", "VEDL" ]
for name in watchlist:
print(name)
chart = tsl.get_short_length_hist_data(name=name, exchange="NSE", interval="5minute", oi=True)
chart['rsi'] = talib.RSI(chart['close'],timeperiod = 14)
comp_candle = chart.iloc[-2]
buy_cond1 = comp_candle['rsi']>70
sell_cond1 = comp_candle['rsi']<30
if sell_cond1:
print(name, "overbought")
entry_price = comp_candle['close']
sl_price = round(comp_candle['close']*1.01,1)
quantity = int(100000/entry_price)
entry_id = tsl.place_order(variety="regular", exchange='NSE', tradingsymbol=name, transaction_type='SELL', quantity=1, product="MIS", order_type="MARKET")
stoploss_id = tsl.place_order(variety="regular", exchange='NSE', tradingsymbol=name, transaction_type='BUY', quantity=1, product="MIS", order_type="SL-M", trigger_price = sl_price)
if buy_cond1 :
print(name, "oversold")
entry_price = comp_candle['close']
sl_price = round(comp_candle['close']*0.99,1)
quantity = int(100000/entry_price)
# order_id = tsl.place_order(variety="regular", exchange='NSE', tradingsymbol=name, transaction_type='BUY', quantity=1, product="MIS", order_type="MARKET")
entry_id = tsl.place_order(variety="regular", exchange='NSE', tradingsymbol=name, transaction_type='SELL', quantity=1, product="MIS", order_type="MARKET")
stoploss_id = tsl.place_order(variety="regular", exchange='NSE', tradingsymbol=name, transaction_type='BUY', quantity=1, product="MIS", order_type="SL-M", trigger_price = sl_price)
`Session 2-20250818T064722Z-1-001/Session 2/practise02/practise02.py"
Logging into zerodha
You have already loggged in for today
reading existing file all_instrument 2025-09-02.csv
you are connected to zerodha Shubham Umdi
BANKBARODA
Traceback (most recent call last):
File "c:/Tradehull_mentorship/Session 2-20250818T064722Z-1-001/Session 2/practise02/practise02.py", line 50, in <module>
stoploss_id = tsl.place_order(variety="regular", exchange='NSE', tradingsymbol=name, transaction_type='BUY', quantity=1, product="MIS", order_type="SL-M", trigger_price = sl_price)
NameError: name 'sl_price' is not defined`
Hi @7350982949 ,
You need place order either if sell_cond1 or buy_cond1 meets right, so use the below code before placing an order.
if sell_cond1 or buy_cond1:
entry_id = tsl.place_order(variety="regular", exchange='NSE', tradingsymbol=name, transaction_type='SELL', quantity=1, product="MIS", order_type="MARKET")
stoploss_id = tsl.place_order(variety="regular", exchange='NSE', tradingsymbol=name, transaction_type='BUY', quantity=1, product="MIS", order_type="SL-M", trigger_price = sl_price)