'Submits a market order.
:param instrument: Instrument identifier.
:type instrument: string.
:param quantity: The amount of shares. Positive means buy, negative means sell.
:type quantity: int/float.
:param onClose: True if the order should be filled as close to the closing price as possible (Market-On-Close order). Default is False.
:type onClose: boolean.
:param goodTillCanceled: True if the order is good till canceled. If False then the order gets automatically canceled when the session closes.
:type goodTillCanceled: boolean.
:param allOrNone: True if the order should be completely filled or not at all.
:type allOrNone: boolean.
:rtype: The :class:`pyalgotrade.broker.MarketOrder` submitted.'

def marketOrder(self, instrument, quantity, onClose=False, goodTillCanceled=False, allOrNone=False):

    ret = None
    if (quantity > 0):
        ret = self.getBroker().createMarketOrder(pyalgotrade.broker.Order.Action.BUY, instrument, quantity, onClose)
    elif (quantity < 0):
        ret = self.getBroker().createMarketOrder(pyalgotrade.broker.Order.Action.SELL, instrument, (quantity * (-1)), onClose)
    if ret:
        ret.setGoodTillCanceled(goodTillCanceled)
        ret.setAllOrNone(allOrNone)
        self.getBroker().submitOrder(ret)
    return ret
