Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBBroker marks the order as rejected on unknown error notifications from the broker #40

Open
vladisld opened this issue Sep 26, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@vladisld
Copy link

Community discussion:

https://community.backtrader.com/topic/2862/ibbroker-live-trading-idealpro-minimum-value-error-code-399-odd-lot-orders-reported-as-rejected

Unexpected behavior:

Looking at ibbroker.py:

def push_ordererror(self, msg):
        with self._lock_orders:
            try:
                order = self.orderbyid[msg.id]
            except (KeyError, AttributeError):
                return  # no order or no id in error

            if msg.errorCode == 202:
                if not order.alive():
                    return
                order.cancel()
            elif msg.errorCode == 201:  # rejected
                if order.status == order.Rejected:
                    return
                order.reject()
            else:
---->        order.reject()  # default for all other cases

called from ibstore.py registered error notify method:

    @ibregister
    def error(self, msg):
        # 300-399 A mix of things: orders, connectivity, tickers, misc errors
        ...  # < code removed for clarity >
        if msg.errorCode is None:
        ...  # < code removed for clarity >
        elif msg.errorCode < 500:
            # Given the myriad of errorCodes, start by assuming is an order
            # error and if not, the checks there will let it go
            if msg.id < self.REQIDBASE:
                if self.broker is not None:
---->            self.broker.push_ordererror(msg)
            else:
                # Cancel the queue if a "data" reqId error is given: sanity
                q = self.qs[msg.id]
                self.cancelQueue(q, True)

The order is marked rejected for every "unknown" ( to be more exact - unhandled) error/warning.

Discussion:

It seem the currently implemented behavior makes a conservative/defensive decision about marking the order as rejected when broker notifies an error which is currently unsupported. It is hard to know whether or not the unknown error code constitutes a real error or just a warning.

It is possible of cause to try to search for the 'warning' or 'error' keywords in the test message itself - but this is error prone at best.

@vladisld vladisld added the bug Something isn't working label Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant