title: Bracket Order With Multiple Target Exits Using ib_insync
body: <p>I am trying to create a bracket order that that will exit 1/2 the position at target 1 and the 2nd half at target 2. I am able to generate the orders, however, the quantity for both of the targets is the entire position amount rather than 1/2. For instance, when placing an order to buy 200 SPY the profit taking orders should have a quantity of 100 each, not 200. However, when I run my code this is the order displayed in TWS:</p>
  <p><a href="https://i.stack.imgur.com/pyBmt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pyBmt.png" alt="enter image description here" /></a></p>
  <p>I am running:</p>
  <pre><code>Python 3.8.2 (default, May  6 2020, 09:02:42) [MSC v.1916 64 bit (AMD64)]
  ib_insync 0.9.61
  TWS Build 979.4t
  Java Version: 1.8.0_152, OS: Windows 10 (amd64, 10.0)
  </code></pre>
  <p>Any ideas on how to solve this issue?</p>
  <p>Please run this code to reproduce the situation:</p>
  <pre><code>from ib_insync import *
  import time
  from typing import NamedTuple
  
  class BracketOrderTwoTargets(NamedTuple):
      parent: Order
      takeProfit: Order
      takeProfit2: Order
      stopLoss: Order
  
  #modified from this post, https://groups.io/g/insync/message/3135
  def bracketStopLimitOrderTwoTargets(
          action: str, quantity: float, stopPrice: float,
          limitPrice: float, takeProfitPrice1: float, takeProfitPrice2: float,
          stopLossPrice: float, **kwargs) -&gt; BracketOrderTwoTargets:
      &quot;&quot;&quot;
      Create a limit order that is bracketed by 2 take-profit orders and
      a stop-loss order. Submit the bracket like:
  
      Args:
          action: 'BUY' or 'SELL'.
          quantity: Size of order.
          stopPrice: Stop Price for stopLimit entry order
          limitPrice: Limit price of entry order.
          takeProfitPrice1: 1st Limit price of profit order.
          takeProfitPrice2: 2nd Limit price of profit order.
          stopLossPrice: Stop price of loss order.
          StopLimitOrder(action, totalQuantity, lmtPrice, stopPrice, **kwargs)
      &quot;&quot;&quot;
      assert action in ('BUY', 'SELL')
      reverseAction = 'BUY' if action == 'SELL' else 'SELL'
      parent = StopLimitOrder(
          action, quantity, limitPrice, stopPrice,
          orderId=ib.client.getReqId(),
          transmit=False,
          outsideRth=True,
          **kwargs)
      takeProfit1 = LimitOrder(
          action=reverseAction, totalQuantity=quantity/2, lmtPrice=takeProfitPrice1,
          orderId=ib.client.getReqId(),
          transmit=False,
          parentId=parent.orderId,
          outsideRth=True,
          **kwargs)
      takeProfit2 = LimitOrder(
          action=reverseAction, totalQuantity=quantity/2, lmtPrice=takeProfitPrice2,
          orderId=ib.client.getReqId(),
          transmit=False,
          parentId=parent.orderId,
          outsideRth=True,
          **kwargs)
      stopLoss = StopOrder(
          reverseAction, quantity, stopLossPrice,
          orderId=ib.client.getReqId(),
          transmit=True,
          parentId=parent.orderId,
          outsideRth = True,
          **kwargs)
      return BracketOrderTwoTargets(parent, takeProfit1, takeProfit2, stopLoss)
  
  
  ib = IB()
  client_id = int(time.time())  # gets second since epoch. No need for the milliseconds, so round to int
  ib.connect('127.0.0.1', 7497, clientId=client_id, timeout=10)
  
  contract = Stock('SPY', exchange='SMART', currency='USD')
  [ticker] = ib.reqTickers(contract)
  contract_price = ticker.marketPrice()
  
  high_bracket = bracketStopLimitOrderTwoTargets(action='BUY', quantity=200, stopPrice=contract_price+18,
                                                 limitPrice=contract_price+20,
                                                 takeProfitPrice1=contract_price+30,
                                                 takeProfitPrice2=contract_price+45,
                                                 stopLossPrice=contract_price-5)
  
  for order in high_bracket:
      order_res = ib.placeOrder(contract=contract, order=order)
      print(order_res)
  </code></pre>