hi @sujith / @rakeshr please assist a bit in this, action is to place gtt sell order automatally agaisnt buy order punched manually.
def on_order_update(self, ws, data): # TODO: Here we need to add code to place the order print(f"[+] NEW ORDER UPDATE: {data}") Thread(target=KiteConnect.place_gtt, args=(data,)).start()
# Extract necessary information from the order update order_id = data['order_id'] status = data['status'] symbol = data['tradingsymbol'] price = data['price'] quantity = data['quantity'] order_type = data['order_type'] exchange = data['exchange'] product = data['product']
# Check if the order status is complete if status == 'COMPLETE': # Calculate stop-loss and target prices based on the percentage stop_loss_percentage = -0.03 target_percentage = 0.02
# Assuming you have access to the required parameters for the GTT order quantity = data['quantity']
# Create a fresh sell GTT order against the order ID try: order_oco = [{ "exchange":exchange, "tradingsymbol": symbol, "transaction_type": kite.TRANSACTION_TYPE_SELL, "quantity": quantity, "order_type": "LIMIT", "product": "NRML", "price": 99 },{ "exchange": exchange, "tradingsymbol": symbol, "transaction_type": kite.TRANSACTION_TYPE_SELL, "quantity": quantity, "order_type": "LIMIT", "product": "NRML", "price": 121 }] # Using a thread to place the GTT order asynchronously Thread(target=self.kite.place_gtt, args=(order_oco,)).start()
except Exception as e: print(f"Error preparing GTT order: {e}")