import pandas as pd
import time
from kiteconnect import KiteConnect
api_key='your_api_key'
api_secret='your_api_secret'
kite=KiteConnect(api_key=api_key)
kite.set_access_token('your_access_token')
x=0
while (True):
try:
pnl=kite.positions()
pnl=pd.DataFrame(pnl['net'])
buy_quantity=pnl['buy_quantity'][x]
print(buy_quantity)
sell_quantity=pnl['sell_quantity'][x]
print(sell_quantity)
variety='regular'
order_type='MARKET'
exchange=pnl['exchange']
tradingsymbol=pnl['tradingsymbol'][x]
product=pnl['product'][x]
if(pnl['pnl'][x]<=-1800).any():
if(pnl['pnl'][x]<=0):
print(pnl['pnl'][x])
if(sell_quantity>buy_quantity):
BUY=sell_quantity-buy_quantity
print(BUY)
order_id=kite.place_order(variety=variety,exchange=exchange,tradingsymbol=tradingsymbol,
transaction_type='BUY',quantity=BUY,product=product,order_type=order_type)
print(order_id)
print(tradingsymbol)
if(buy_quantity>sell_quantity):
SELL=buy_quantity-sell_quantity
print(SELL)
order_id=kite.place_order(variety=variety,exchange=exchange,tradingsymbol=tradingsymbol,
transaction_type='SELL',quantity=SELL,product=product,order_type=order_type)
print(order_id)
print(tradingsymbol)
x+=1
time.sleep(1)
except Exception as e:
print(str(e))
break