'Held orders act almost identically to open orders, except for the
status indication. When a fill happens, the order should switch
status to OPEN/FILLED as necessary'

def test_order_hold(self):

    blotter = Blotter(self.sim_params.data_frequency)
    blotter.hold(56)
    self.assertEqual(blotter.new_orders, [])
    open_id = blotter.order(self.asset_24, 100, MarketOrder())
    open_order = blotter.open_orders[self.asset_24][0]
    self.assertEqual(open_order.id, open_id)
    blotter.hold(open_id)
    self.assertEqual(len(blotter.new_orders), 1)
    self.assertEqual(len(blotter.open_orders[self.asset_24]), 1)
    held_order = blotter.new_orders[0]
    self.assertEqual(held_order.status, ORDER_STATUS.HELD)
    self.assertEqual(held_order.reason, '')
    blotter.cancel(held_order.id)
    self.assertEqual(len(blotter.new_orders), 1)
    self.assertEqual(len(blotter.open_orders[self.asset_24]), 0)
    cancelled_order = blotter.new_orders[0]
    self.assertEqual(cancelled_order.id, held_order.id)
    self.assertEqual(cancelled_order.status, ORDER_STATUS.CANCELLED)
    for data in ([100, self.sim_params.sessions[0]], [400, self.sim_params.sessions[1]]):
        trade_amt = data[0]
        dt = data[1]
        order_size = 100
        expected_filled = int((trade_amt * DEFAULT_EQUITY_VOLUME_SLIPPAGE_BAR_LIMIT))
        expected_open = (order_size - expected_filled)
        expected_status = (ORDER_STATUS.OPEN if expected_open else ORDER_STATUS.FILLED)
        blotter = Blotter(self.sim_params.data_frequency)
        open_id = blotter.order(self.asset_24, order_size, MarketOrder())
        open_order = blotter.open_orders[self.asset_24][0]
        self.assertEqual(open_id, open_order.id)
        blotter.hold(open_id)
        held_order = blotter.new_orders[0]
        filled_order = None
        blotter.current_dt = dt
        bar_data = self.create_bardata(simulation_dt_func=(lambda : dt))
        (txns, _, _) = blotter.get_transactions(bar_data)
        for txn in txns:
            filled_order = blotter.orders[txn.order_id]
        self.assertEqual(filled_order.id, held_order.id)
        self.assertEqual(filled_order.status, expected_status)
        self.assertEqual(filled_order.filled, expected_filled)
        self.assertEqual(filled_order.open_amount, expected_open)
