class_docstr: Broker implementation for Interactive Brokers.
  
  This class maps the orders/positions from Interactive Brokers to the
  internal API of ``backtrader``.
  
  Notes:
  
    - ``tradeid`` is not really supported, because the profit and loss are
      taken directly from IB. Because (as expected) calculates it in FIFO
      manner, the pnl is not accurate for the tradeid.
  
    - Position
  
      If there is an open position for an asset at the beginning of
      operaitons or orders given by other means change a position, the trades
      calculated in the ``Strategy`` in cerebro will not reflect the reality.
  
      To avoid this, this broker would have to do its own position
      management which would also allow tradeid with multiple ids (profit and
      loss would also be calculated locally), but could be considered to be
      defeating the purpose of working with a live broker
class_docstr_tok: ["Broker","implementation","for","Interactive","Brokers",".","This","class","maps","the","orders\/positions","from","Interactive","Brokers","to","the","internal","API","of","``","backtrader","``",".","Notes",":","-","``","tradeid","``","is","not","really","supported",",","because","the","profit","and","loss","are","taken","directly","from","IB",".","Because","(","as","expected",")","calculates","it","in","FIFO","manner",",","the","pnl","is","not","accurate","for","the","tradeid",".","-","Position","If","there","is","an","open","position","for","an","asset","at","the","beginning","of","operaitons","or","orders","given","by","other","means","change","a","position",",","the","trades","calculated","in","the","``","Strategy","``","in","cerebro","will","not","reflect","the","reality",".","To","avoid","this",",","this","broker","would","have","to","do","its","own","position","management","which","would","also","allow","tradeid","with","multiple","ids","(","profit","and","loss","would","also","be","calculated","locally",")",",","but","could","be","considered","to","be","defeating","the","purpose","of","working","with","a","live","broker"]
code: 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:
          if order.status == order.Accepted:  # duplicate detection
              return
  
          order.accept(self)
          self.notify(order)
  
      elif msg.status == self.CANCELLED:
          # duplicate detection
          if order.status in [order.Cancelled, order.Expired]:
              return
  
          if order._willexpire:
              # An openOrder has been seen with PendingCancel/Cancelled
              # and this happens when an order expires
              order.expire()
          else:
              # Pure user cancellation happens without an openOrder
              order.cancel()
          self.notify(order)
  
      elif msg.status == self.PENDINGCANCEL:
          # In theory this message should not be seen according to the docs,
          # but other messages like PENDINGSUBMIT which are similarly
          # described in the docs have been received in the demo
          if order.status == order.Cancelled:  # duplicate detection
              return
  
          # We do nothing because the situation is handled with the 202 error
          # code if no orderStatus with CANCELLED is seen
          # order.cancel()
          # self.notify(order)
  
      elif msg.status == self.INACTIVE:
          # This is a tricky one, because the instances seen have led to
          # order rejection in the demo, but according to the docs there may
          # be a number of reasons and it seems like it could be reactivated
          if order.status == order.Rejected:  # duplicate detection
              return
  
          order.reject(self)
          self.notify(order)
  
      elif msg.status in [self.SUBMITTED, self.FILLED]:
          # These two are kept inside the order until execdetails and
          # commission are all in place - commission is the last to come
          self.ordstatus[msg.orderId][msg.filled] = msg
  
      elif msg.status in [self.PENDINGSUBMIT, self.PRESUBMITTED]:
          # According to the docs, these statuses can only be set by the
          # programmer but the demo account sent it back at random times with
          # "filled"
          if msg.filled:
              self.ordstatus[msg.orderId][msg.filled] = msg
      else:  # Unknown status ...
          pass
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import collections
  from copy import copy
  from datetime import date, datetime, timedelta
  import threading
  import uuid
  import ib.ext.Order
  import ib.opt
  from backtrader.feed import DataBase
  from backtrader import TimeFrame, num2date, date2num, BrokerBase, Order, OrderBase, OrderData
  from backtrader.utils.py3 import bytes, bstr, with_metaclass, queue, MAXFLOAT
  from backtrader.metabase import MetaParams
  from backtrader.comminfo import CommInfoBase
  from backtrader.position import Position
  from backtrader.stores import ibstore
  from backtrader.utils import AutoDict, AutoOrderedDict
  from backtrader.comminfo import CommInfoBase
label_desc: Use image node_id 17 for calling the IBBroker obj's underlying member method code with example usage: obj.push_orderstatus(msg) without return types