class_docstr: An algorithm that ensures that 'phantom' positions do not appear in
  portfolio.positions in the case that a position has been entered
  and fully exited.
class_docstr_tok: ["An","algorithm","that","ensures","that","'phantom","'","positions","do","not","appear","in","portfolio.positions","in","the","case","that","a","position","has","been","entered","and","fully","exited","."]
code: def handle_data(self, data):
      if not self.ordered:
          for s in self.sids:
              self.order(self.sid(s), 1)
          self.ordered = True
  
      if not self.exited:
          amounts = [
              pos.amount for pos in itervalues(self.portfolio.positions)
          ]
  
          if len(amounts) > 0 and all(
              [(amount == 1) for amount in amounts]
          ):
              for stock in self.portfolio.positions:
                  self.order(self.sid(stock), -1)
              self.exited = True
  
      # Should be 0 when all positions are exited.
      self.record(num_positions=len(self.portfolio.positions))
  
imports: import numpy
  from nose.tools import assert_raises
  from six import itervalues
  from zipline.algorithm import TradingAlgorithm
  from zipline.api import FixedSlippage, order, set_slippage, record, sid
  from zipline.errors import UnsupportedOrderParameters
  from zipline.finance.execution import LimitOrder, MarketOrder, StopLimitOrder, StopOrder
label_desc: Use image node_id 2 for calling the EmptyPositionsAlgorithm obj's underlying member method code with example usage: obj.handle_data(data) without return types