[Python] Interactive Broker API wih ib_async: catch erro on callback function

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I'm developing a trading bot with Interactive Broker API with python and ib_async library. So far, so good I managed to connect, get data, place order. But I have a question regarding callback function and error. I'm using the following code to place an order

    def order_filled(trade, fill):
    """
    Called when a order has been placed
    """

    for f in fill:
    print(f.notvalidname) # it should raise AttributeError here

    order = ib_api.MarketOrder(BUY, 1)
    trade = ib.placeOrder(contract, order)
    trade.fillEvent += order_filled


    I have voluntarily used a invalid name on the fill object (which is a namedtuple) but still the code is running without catching any errors. I think there is something to do with asyncio but couldn't find any good answer.

    I will be thankful if someone has a proper explanation.

    And Is there a way to catch error without using the try/except block ?

    Many thanks in advance

    Continue reading...

Compartilhe esta Página