INNER CODE UNIT · Python

on_open_order_update

ldt9/PyOptionTrader · models/futures/short_strangle.py:158

    def on_open_order_update(self, trade: Trade):
        # Add the order to the log
        conId = trade.contract.comboLegs[0].conId
        self.open_order_log.append(conId)
        # Count the current number of unique orders
        current_unique_orders = len(set(self.open_order_log))
        # Check if a new unique order is added
        if current_unique_orders > self.previous_unique_orders:
            print(f"{self.get_timestamp()} New Order Created")
            self.previous_unique_orders = current_unique_orders
            self.order_placed = not self.order_placed
            print(f"{self.get_timestamp()} Trade Placed")

    def onDisconnected(self):
        print(f"{self.get_timestamp()} Disconnect Event")
        print(f"{self.get_timestamp()} attempting restart and reconnect...")
        self.connect_to_ibkr()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…