Ejemplo n.º 1
0
    def IBridgePyPlaceOrder(self,
                            an_order,
                            accountCode='default',
                            followUpWaiver=False):
        self.log.debug(__name__ + '::IBridgePyPlaceOrder')
        if not self.validateAccountCode(accountCode):
            return

        an_order.order.account = self.adjust_accountCode(accountCode)
        an_order.orderId = self.nextId
        an_order.created = self.get_datetime()
        an_order.stop = an_order.order.auxPrice
        an_order.limit = an_order.order.lmtPrice
        an_order.amount = an_order.order.totalQuantity
        an_order.status = 'PreSubmitted'

        # in the test_run mode, self.nextId may change after self.placeOrder, so, record it at first place
        orderId = self.nextId
        self.nextId = self.nextId + 1
        self.PORTFOLIO.orderStatusBook[orderId] = an_order
        self.request_data(
            ReqData.placeOrder(orderId, an_order.contract, an_order.order,
                               followUpWaiver))
        return orderId
Ejemplo n.º 2
0
 def modify_order(self,
                  orderId,
                  newQuantity=None,
                  newLimitPrice=None,
                  newStopPrice=None,
                  newTif=None,
                  newOrderRef=None):
     self.log.debug(__name__ + '::modify_order: orderId = %s' % (orderId, ))
     if self.PORTFOLIO.orderStatusBook[orderId].status in [
             OrderStatus.PRESUBMITTED, OrderStatus.SUBMITTED
     ]:
         an_order = self.PORTFOLIO.orderStatusBook[orderId]
         an_order.status = OrderStatus.PRESUBMITTED
         if newQuantity is not None:
             # amount is the same number as order.totalQuantity. Keep it because Quantopian has it.
             an_order.amount = newQuantity
             an_order.order.totalQuantity = newQuantity
         if newLimitPrice is not None:
             an_order.limit = newLimitPrice
             an_order.order.lmtPrice = newLimitPrice
         if newStopPrice is not None:
             an_order.stop = newStopPrice
             an_order.order.auxPrice = newStopPrice
         if newTif is not None:
             an_order.order.tif = newTif
         if newOrderRef is not None:
             an_order.order.orderRef = newOrderRef
         self.request_data(
             ReqData.placeOrder(orderId, an_order.contract, an_order.order,
                                FollowUpRequest.DO_NOT_FOLLOW_UP))
     else:
         self.log.error(
             __name__ +
             '::modify_order: Cannot modify order. orderId = %s' %
             (orderId, ))
         exit()