Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def order(self, instrument, quantity, goodTillCanceled = False):
"""Places 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.
: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.
:rtype: The :class:`pyalgotrade.broker.MarketOrder` submitted.
"""
ret = None
if quantity > 0:
ret = self.getBroker().createMarketOrder(broker.Order.Action.BUY, instrument, quantity)
elif quantity < 0:
ret = self.getBroker().createMarketOrder(broker.Order.Action.SELL, instrument, abs(quantity))
if ret:
ret.setGoodTillCanceled(goodTillCanceled)
self.getBroker().placeOrder(ret)
return ret