Drive for Python setup installers https://drive.google.com/drive/folders/1xHRH3BCApXMxoQJo0_fkoH2k_c767_qQ?usp=sharing
Check out this video for a complete guide on How to use Code Base? https://youtu.be/v9mLDsjhsAs
import time
import datetime
import traceback
import tradehull
import pandas as pd
# creates tradehull object
# TH = tradehull.Tradehull(api key,api secret, download_instrument_yes_no_flag)
# values of flag :
# yes
# no
TH = tradehull.Tradehull("","","yes")
# get kite object
kite = TH.kite
# get instrument dataframe
instrument = TH.instrument_file
#to get allowed scripts for intraday trading
intraday_allowed_scripts = TH.get_intraday_allowed_script()
#to get data for a single script
# ltp = TH.get_data_for_single_script(exchange,scrip name,call type)
ltp = TH.get_data_for_single_script("NSE","ACC","ltp")
open_, high, low, close = TH.get_data_for_single_script("NSE","ACC","ohlc")
quote = TH.get_data_for_single_script("NSE","ACC","quote")
# to get atm/itm/otm script
# expiry:
# 0 - currect expiry
# 1 - next expiry
# 2 - next to next expiry
# multiplier:
# 1 - previous itm / next otm
name = "NIFTY 50"
ltp = TH.get_data_for_single_script("NSE",name,"ltp")
atm = TH.get_atm(ltp=ltp,underlying=name,expiry=0,script_type="CE")
itm = TH.get_itm(ltp=ltp,underlying=name,expiry=0,multiplier = 2 , script_type="CE")
otm = TH.get_otm(ltp=ltp,underlying=name,expiry=0,multiplier = 2 , script_type="CE")
# to get straddle and strangle
# multiplier:
# 1 - previous itm / next otm
ltp = TH.get_data_for_single_script("NSE","NIFTY BANK","ltp")
straddle = TH.get_straddle(underlying = 'BANKNIFTY',step = 100,ltp = ltp, expiry = '2022-07-28')
strangle = TH.get_strangle(underlying = 'BANKNIFTY',step = 100,ltp = ltp, expiry = '2022-07-28',multiplier = 2)
# to get Option Greek value of any strike
# flag:
# price : Returns the option's price
# delta : Returns the delta value
# delta2 : Returns the dual delta value
# theta : Returns the theta value
# rho : Returns the rho value
# vega : Returns the option vega
# gamma : Returns the option gamma
# all_val : Returns dictionary of all values mentioned above
ce_delta = TH.get_option_greek(strike = 38400, expiry_date = "2022-08-11", asset = "NIFTY BANK", interest_rate = 10, flag = "delta", scrip_type = "CE")
pe_delta = TH.get_option_greek(strike = 37400, expiry_date = "2022-08-11", asset = "NIFTY BANK", interest_rate = 10, flag = "delta", scrip_type = "PE")
# to get Implied volatility of any strike
ce_IV = TH.get_implied_volatility(strike = 18000, expiry_date = "2022-10-27", asset = "NIFTY 50", interest_rate = 10, scrip_type = "CE")
pe_IV = TH.get_implied_volatility(strike = 18000, expiry_date = "2022-10-27", asset = "NIFTY 50", interest_rate = 10, scrip_type = "PE")
# to get historical data for short duration
data = TH.get_short_length_hist_data(name="ACC",exchange="NSE",interval="minute",oi=True)
# to get historical data for a specific short duration
# Max durations for which we can call historical data from kite are:
# minute : 60 days
# 3minute : 100 days
# 5minute : 100 days
# 10minute : 100 days
# 15minute : 200 days
# 30minute : 200 days
# 60minute : 400 days
# day : 2000 days
data = TH.get_short_length_hist_data_specific_dur(name="ACC",exchange="NSE",interval="minute",from_date='2022-05-21',to_date='2022-07-20',oi=True)
# to get long-term historical data more than allowed Zerodha limitations
data = TH.get_long_length_hist_data(name="ACC",exchange="NSE",interval="5minute",length=1000,oi=True)
# to get long-term historical data more than allowed Zerodha limitations for a specific long duration
df = TH.get_long_length_hist_data_specific_dur(name="ACC",exchange="NSE",interval="5minute",from_date='2019-12-30',download_till_date='2022-07-20',oi=False)
# Pivot point indicator on historical data for current day
# pp_value = TH.get_pivot_point(dataframe,flag_for_pivot_point)
# flag:
# pp - main pivot level
# r1 - for resistance 1
# r2 - for resistance 2
# r3 - for resistance 3
# s1 - for support 1
# s2 - for support 2
# s3 - for support 3
data = TH.get_short_length_hist_data_specific_dur(name="ACC",exchange="NSE",interval="15minute",from_date='2022-05-28',to_date='2022-07-26',oi=True)
pp_value = TH.get_pivot_point(data,'pp')
# Fibonacci Pivot point indicator on historical data for current day
# pp_value = TH.get_fibonacci_pivot_point(dataframe,flag_for_pivot_point)
# flag:
# pp - main pivot level
# r1 - for resistance 1
# r2 - for resistance 2
# r3 - for resistance 3
# s1 - for support 1
# s2 - for support 2
# s3 - for support 3
data = TH.get_short_length_hist_data_specific_dur(name="ACC",exchange="NSE",interval="15minute",from_date='2022-05-28',to_date='2022-07-26',oi=True)
pp_value = TH.get_fibonacci_pivot_point(data,'pp')
#resample data (monthly/hourly/weekly/minute wise)
data = TH.get_short_length_hist_data(name="ACC",exchange="NSE",interval="minute",oi=True)
df = TH.minute_resample_data(df=data,timeframe=7) # 7 minute
df = TH.hourly_resample_data(df=data,time_frame=4) # 4 hours
df = TH.weekly_resample_data(data)
df = TH.monthly_resample_data(data)
# Get completed candle data for any scrip
df15 = TH.get_short_length_hist_data(name= 'ACC' ,exchange="NSE",interval="15minute",oi=True)
completed_candle_data = TH.get_completed_candle_data(df = df15)
print(completed_candle_data)
# to send a telegram alert, firstly the receiver has to send a message(./start) to the TradeHull's bot on Telegram. The bot name is "@Tradehull_alert_bot".
TH.send_telegram_alert(message="Hii USer. This message is from TH library",receiver_chat_id="xxxxx0350")
# check if scrip/instrument is valid
# response = TH.check_valid_instrument(scrip name)
response = TH.check_valid_instrument("ACC")
#to get gapup/gapdown percentage
val = TH.market_open_stock_movement(name="ACC",exchange="NSE")
# Get last n tradable days
# data = TH.get_tradable_days(N days)
data = TH.get_tradable_days(10)
# Get last tradable day
last_tradable_day = TH.get_last_tradable_day()
# Get all the upcoming expiries of the exchange
# data = TH.get_expiries(scripname, exchange, flag)
# flag:
# monthly : returns all the monthly expiries for this, next & far month for given script
# weekly : returns all the weekly expiries in current month for given script
# all : returns all the expiries available in instrument file for given script
data = TH.get_expiries("NIFTY", "NFO", "monthly")
# Get FUT scrips for any underlying asset
# response = TH.get_fut_scripts(scrip name)
data = TH.get_fut_scripts("ACC")
# Get lot sizes of scrips
# response = TH.get_lot_size(scrip name)
lot = TH.get_lot_size("ACC22JUL1640CE")
lot = TH.get_lot_size("AARTIIND22JULFUT")
# Get prices of all indices
data = TH.get_index_data()
# to place order, all types of order with required parameter can be placed via TradeHull's place_order function
readl_orderid = TH.place_order(variety=kite.VARIETY_REGULAR, exchange='NSE', tradingsymbol='GAIL',transaction_type='SELL', quantity=5, product=kite.PRODUCT_MIS, order_type=kite.ORDER_TYPE_SLM,trigger_price=140)
# to modify order, all possible parameter, i.e. order_type, product_type, etc can be modified by TradeHull's modify_order funtion
order_id = '220722001346805'
readl_orderid = TH.modify_order(variety=kite.VARIETY_REGULAR,order_id=order_id,quantity=5, trigger_price=54)
# Get order status by passing orderID
# status = TH.get_order_status(orderID)
status = TH.get_order_status(220722001346805)
# close all orders by calling this function
TH.market_over_close_all_order()
# Get average executed price of any order
# price = TH.get_executed_price(orderID)
price = TH.get_executed_price(220722001332188)
# Get get live pnl
pnl = TH.get_live_pnl()
# Get execution time of any order
# time = TH.get_executed_time(orderID)
time = TH.get_executed_time(220722001332188)
# for position sizing, if you want to close specific number of quantity amongst placed quantities
data = TH.position_sizing(name="BHEL",number_of_quantity_to_be_exited=5)
# manage SL and target order (if sl hit cancels target and vice versa)
sl_order = '220722001016914'
tgt_order = '220722001018180'
val = TH.check_sl_tgt_order(sl_orderid=sl_order,tgt_orderid=tgt_order)
<aside> 💡 To get more details regarding function calls. let's check their outputs
</aside>