Exemplo n.º 1
0
    def TrailBracketOrder(self, parentOrderId, childOrderId, action, quantity,
                          limitPrice, trailAmount):

        # This will be our main or "parent" order
        parent = Order()
        parent.orderId = parentOrderId
        parent.action = action
        parent.orderType = "LMT"
        parent.totalQuantity = 1000  #quantity
        parent.lmtPrice = limitPrice
        parent.transmit = False

        stopLoss = Order()
        stopLoss.orderId = childOrderId
        logging.info("Action is " + action)
        if action == "Buy":
            stopLoss.action = "Sell"
            stopLoss.trailStopPrice = limitPrice - (limitPrice * .02)
        if action == "Sell":
            stopLoss.action = "Buy"
            stopLoss.trailStopPrice = limitPrice + (limitPrice * .02)
        stopLoss.orderType = "TRAIL"
        stopLoss.auxPrice = limitPrice  #trailAmount
        #trailAmount
        stopLoss.totalQuantity = 1000  #quantity
        stopLoss.parentId = parentOrderId
        stopLoss.transmit = True

        bracketOrder = [parent, stopLoss]
        return bracketOrder
Exemplo n.º 2
0
    def modify_limit_price_given_original_objects(
            self, original_order_object: ibOrder,
            original_contract_object_with_legs: ibcontractWithLegs,
            new_limit_price: float) -> tradeWithContract:

        original_contract_object = original_contract_object_with_legs.ibcontract
        original_order_object.lmtPrice = new_limit_price

        new_trade_object = self.ib.placeOrder(original_contract_object,
                                              original_order_object)

        new_trade_with_contract = tradeWithContract(
            original_contract_object_with_legs, new_trade_object)

        return new_trade_with_contract