示例#1
0
 def __onOrderUpdated(self, broker, order):
     position = self.__orderToPosition.get(order.getId(), None)
     if position == None:
         self.onOrderUpdated(order)
     elif position.getEntryOrder().getId() == order.getId():
         if order.isFilled():
             self.__unregisterOrder(position, order)
             self.onEnterOk(position)
         elif order.isCanceled():
             self.__unregisterOrder(position, order)
             self.onEnterCanceled(position)
         else:
             assert (order.isAccepted())
     elif position.getExitOrder().getId() == order.getId():
         if order.isFilled():
             self.__unregisterOrder(position, order)
             self.onExitOk(position)
         elif order.isCanceled():
             self.__unregisterOrder(position, order)
             self.onExitCanceled(position)
         else:
             assert (order.isAccepted())
     else:
         # The order used to belong to a position but it was ovewritten with a new one
         # and the previous order should have been canceled.
         assert (order.isCanceled())
示例#2
0
	def __onOrderUpdated(self, broker, order):
		position = self.__orderToPosition.get(order.getId(), None)
		if position == None:
			self.onOrderUpdated(order)
		elif position.getEntryOrder().getId() == order.getId():
			if order.isFilled():
				self.__unregisterOrder(position, order)
				self.onEnterOk(position)
			elif order.isCanceled():
				self.__unregisterOrder(position, order)
				self.onEnterCanceled(position)
			else:
				assert(order.isAccepted())
		elif position.getExitOrder().getId() == order.getId():
			if order.isFilled():
				self.__unregisterOrder(position, order)
				self.onExitOk(position)
			elif order.isCanceled():
				self.__unregisterOrder(position, order)
				self.onExitCanceled(position)
			else:
				assert(order.isAccepted())
		else:
			# The order used to belong to a position but it was ovewritten with a new one
			# and the previous order should have been canceled.
			assert(order.isCanceled())
示例#3
0
 def onExitOk(self, position):
     extorder = position.getExitOrder()
     execInfo = extorder.getExecutionInfo()
     inst     = position.getEntryOrder().getInstrument()
     price    = format(execInfo.getPrice(),'<6.2f')
     shares   = format(execInfo.getQuantity(),'<10.2f')
     self.debug("SELL: " + str(inst) + " at $%s shares:%s orderid:%d" % (price,shares,extorder.getId()))
示例#4
0
 def __registerActivePosition(self, position):
     for order in [position.getEntryOrder(), position.getExitOrder()]:
         if order and order.isAccepted():
             self.__registerOrder(position, order)