for x in trd_portfolio: trd_tkn1.append(x) live_open[x] = 0 live_high[x] = 0 live_low[x] = 0 live_close[x] = 0 buy_count[x] = 0 sell_count[x] = 0
#--- Taking input credentials from user to make connection with ZERODHA API c_id = "xxxxxx" ak = "xxxxxxxxxxxxxxxxxxxxx" asecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
try: trd_capital = int(input("[*] Enter Trading Capital (eg. 10000, 25000) : ")); trd_tp = float(input("[*] Enter your Reward (eg.2500, 4500, 6000 ) : ")) trd_sl = float(input("[*] Enter your Risk (eg.1200, 1500, 1800 ) : ")) trd_inc_dec = float(input("[*] Enter Percentage Increment Decrement (eg. 0.25%,0.5%,1%,2%) : "))/100 time_frame = int(input("[*] Enter timeframe (eg. 5, 15) : ")); trailing_stoploss = int(input("[*] Enter trailing-stoploss (eg. 1, 2) : "));
print("------------------------ ENTER BUY PRICE PERCENTAGE DISTRIBUTION ------------------------") total_percentage = 0; while total_percentage is not 100: print("\t[+] Please make total percentage 100") total_percentage = 0; buy_percentage_distribution = [] for x in range(1,5): buy_percentage_distribution.append(int(input("\t"+str(x)+": "))) total_percentage+=buy_percentage_distribution[x-1]
print("------------------------ ENTER SELL PRICE PERCENTAGE DISTRIBUTION ------------------------") total_percentage = 0; while total_percentage is not 100: print("\t[+] Please make total percentage 100") total_percentage = 0; sell_percentage_distribution = [] for x in range(1,5): sell_percentage_distribution.append(int(input("\t"+str(x)+": "))) total_percentage+=sell_percentage_distribution[x-1]
except Exception as e: print(e) print("[!] Please enter correct data") i = input("[!] PRESS ENTER TO EXIT... ") exit();
kite = KiteConnect(api_key=ak) print("[*] Generate access Token : ",kite.login_url()) request_tkn = input("[*] Enter Your Request Token Here : ")[-32:]; data = kite.request_access_token(request_tkn, secret=asecret) kite.set_access_token(data["access_token"]) kws = WebSocket(ak, data["public_token"], c_id)
def calculate_ohlc(tick): global live_open,live_high,live_low,live_close; for company_data in tick: live_open[company_data['instrument_token']] = company_data['ohlc']['open'] live_high[company_data['instrument_token']] = company_data['ohlc']['high'] live_low[company_data['instrument_token']] = company_data['ohlc']['low'] live_close[company_data['instrument_token']] = company_data['ohlc']['close']
def do_buy_sell_operation(tick): global live_high,live_low,buy_count,sell_count,trd_inc_dec global trd_capital,buy_percentage_distribution,sell_percentage_distribution global trd_tp,trd_sl,trailing_stoploss;
for company_data in tick: var_x1 = round(live_high[company_data['instrument_token']]+company_data['ohlc']['open']*(trd_inc_dec*buy_count[company_data['instrument_token']]),2);
if company_data['last_price'] >= var_x1 and buy_count[company_data['instrument_token']]<4: quant = int((trd_capital*(buy_percentage_distribution[buy_count[company_data['instrument_token']]]/100))//company_data['last_price']); stoploss = round((trd_tp*buy_percentage_distribution[buy_count[company_data['instrument_token']]]/100)/quant,2) takeprofit = round((trd_sl*buy_percentage_distribution[buy_count[company_data['instrument_token']]]/100)/quant,2)
you can use this code below for orb..