ib-api-reloaded / ib_async

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

partial fills orders #78

Closed helhadry closed 1 month ago

helhadry commented 1 month ago

Hello,

I have an issue handling the partial fills orders, in my code, I need to make sure that all partial orders are executed to process with next step, I use the remaining function from trade object to check if the remaining is equal 0 or not, below is my code, the issue here is that it give always remaining == 0 even there are some remaining shares

I use this event: self.ib_client.execDetailsEvent += self.on_exec_details

` def on_exec_details(self, trade, fill):

    symbol = trade.contract.symbol

    if symbol in self.positions:

        trade_type = trade.order.orderType
        side = fill.execution.side
        order_id = trade.order.orderId
        shares = fill.execution.shares

        while not trade.isDone():
            logger.info(f"{symbol} : Trade type: {trade_type}/{side}, Trade Status {trade.orderStatus.status},"
                        f"remaining shares: {trade.orderStatus.remaining}")
            self.ib_client.sleep(1)

        logger.info(
            f"Execution of {trade_type} order for {symbol}, side = {side}, "
            f"shares = {shares}, order_id = {order_id}, Trade Status = {trade.orderStatus.status}"
            f"remaining shares: {trade.orderStatus.remaining}"
        )

        self.ib_client.sleep(1)

        if trade.remaining() != 0:
            return

`

Could you please help me understand why this is not working properly?

gnzsnz commented 1 month ago

this is not an issue, i would suggest to move this to discussions

helhadry commented 1 month ago

thanks will do that