Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Order rejected error handling from notify_order

    General Code/Help
    2
    2
    186
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • orenshkol
      orenshkol last edited by

      Hi,

      When live trading on IB I wish to handle orders rejected by the type of error code received from IB, the problem is that the error code is received in notify_store, when I only want to address errors for rejected orders when I encounter them them in notify_order (notify_store receives many other messages that I don't wish to address).

      The only way I see of doing this is by logging notify_store messages as they come in, then getting the last message received for the order id when I get order.Rejected for it in notify_order.
      Is there an easier way of doing this? Is there a way of getting the error code from notify_order that I missed?

      Thank you.

      1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        Unfortunately in current backtrader IBBroker implementation only the following order statuses (coming from IB) are recognized :

        SUBMITTED, FILLED, CANCELLED, INACTIVE,  PENDINGSUBMIT, PENDINGCANCEL, PRESUBMITTED
        

        See the following code (in IBBroker.py) if you'd like to change/add that:

        def push_orderstatus(self, msg):
                # Cancelled and Submitted with Filled = 0 can be pushed immediately
                try:
                    order = self.orderbyid[msg.orderId]
                except KeyError:
                    return  # not found, it was not an order
        
                if msg.status == self.SUBMITTED and msg.filled == 0:
                    ...
        
                elif msg.status == self.CANCELLED:
                    ...
        
                elif msg.status == self.PENDINGCANCEL:
                    ...
        
                elif msg.status == self.INACTIVE:
                    ...
        
                elif msg.status in [self.SUBMITTED, self.FILLED]:
                    ...
        
                elif msg.status in [self.PENDINGSUBMIT, self.PRESUBMITTED]:
                    ...
                else:  # Unknown status ...
                    pass
        
        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors