ib-api-reloaded / ib_async

Python sync/async framework for Interactive Brokers API (replaces ib_insync)
BSD 2-Clause "Simplified" License
467 stars 73 forks source link

reqOpenOrders() inside the event handler #43

Closed psdon closed 4 months ago

psdon commented 4 months ago

I'm trying to figure out how to execute a blocking method such as reqOpenOrders() inside the event handler.

Snippet:


self.broker.ib.reqTickByTickData(self.contract, "BidAsk")
self.broker.ib.pendingTickersEvent += self.on_event

def on_event(self, event):
    ....
    self.get_orders(self.symbol)

def get_orders(self, symbol: ib_async.Contract):
        orders = []
        for order in self.ib.reqOpenOrders():
            if order.contract == symbol:
                orders.append(order)

        return orders

error message:

this event loop is already running

EDIT: Turns out I'm executing reqOpenOrders() too many times and I'm hitting the API rate limit. Thus, I'm closing this thread.