How to use the broker.Order.Action function in broker

To help you get started, we’ve selected a few broker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gbeced / pyalgotrade / pyalgotrade / strategy.py View on Github external
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