The best way to work with bracket orders is to keep track of the parent order ID. When you have that you can easily get the order IDs of the two leg orders. The leg order info is stored with the parent order in the attribute called legs
.
The first leg (ie legs[0]) is always the take profit limit order. The second leg (ie legs[1]) is always the stop limit order. Below is an example of a parent bracket order with the two leg order details in the legs attribute.
{ ‘asset_class’: <AssetClass.US_EQUITY: ‘us_equity’>,
‘asset_id’: UUID(‘b0b6dd9d-8b9b-48a9-ba46-b9d54906e415’),
‘canceled_at’: None,
‘client_order_id’: ‘73773fa3-551f-4c54-adbe-fd9ae0f51334’,
‘created_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 224183, tzinfo=datetime.timezone.utc),
‘expired_at’: None,
‘extended_hours’: False,
‘failed_at’: None,
‘filled_at’: None,
‘filled_avg_price’: None,
‘filled_qty’: ‘0’,
‘hwm’: None,
‘id’: UUID(‘374e5da7-71fe-4b1d-8296-6d89285e4a67’),
‘legs’: [ { ‘asset_class’: <AssetClass.US_EQUITY: ‘us_equity’>,
‘asset_id’: UUID(‘b0b6dd9d-8b9b-48a9-ba46-b9d54906e415’),
‘canceled_at’: None,
‘client_order_id’: ‘e7199a8d-d82a-491d-bdb3-af576e0f706d’,
‘created_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 224215, tzinfo=datetime.timezone.utc),
‘expired_at’: None,
‘extended_hours’: False,
‘failed_at’: None,
‘filled_at’: None,
‘filled_avg_price’: None,
‘filled_qty’: ‘0’,
‘hwm’: None,
‘id’: UUID(‘300a3588-b274-4521-85d6-e851a7114dd9’),
‘legs’: None,
‘limit_price’: ‘150’,
‘notional’: None,
‘order_class’: <OrderClass.BRACKET: ‘bracket’>,
‘order_type’: <OrderType.LIMIT: ‘limit’>,
‘qty’: ‘1’,
‘replaced_at’: None,
‘replaced_by’: None,
‘replaces’: None,
‘side’: <OrderSide.SELL: ‘sell’>,
‘status’: <OrderStatus.HELD: ‘held’>,
‘stop_price’: None,
‘submitted_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 222565, tzinfo=datetime.timezone.utc),
‘symbol’: ‘AAPL’,
‘time_in_force’: <TimeInForce.DAY: ‘day’>,
‘trail_percent’: None,
‘trail_price’: None,
‘type’: <OrderType.LIMIT: ‘limit’>,
‘updated_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 224215, tzinfo=datetime.timezone.utc)},
{ ‘asset_class’: <AssetClass.US_EQUITY: ‘us_equity’>,
‘asset_id’: UUID(‘b0b6dd9d-8b9b-48a9-ba46-b9d54906e415’),
‘canceled_at’: None,
‘client_order_id’: ‘fb472043-1f4e-4445-b5f2-174d1535a118’,
‘created_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 224232, tzinfo=datetime.timezone.utc),
‘expired_at’: None,
‘extended_hours’: False,
‘failed_at’: None,
‘filled_at’: None,
‘filled_avg_price’: None,
‘filled_qty’: ‘0’,
‘hwm’: None,
‘id’: UUID(‘58a81cd9-f5ab-43a7-8835-5c543b022925’),
‘legs’: None,
‘limit_price’: None,
‘notional’: None,
‘order_class’: <OrderClass.BRACKET: ‘bracket’>,
‘order_type’: <OrderType.STOP: ‘stop’>,
‘qty’: ‘1’,
‘replaced_at’: None,
‘replaced_by’: None,
‘replaces’: None,
‘side’: <OrderSide.SELL: ‘sell’>,
‘status’: <OrderStatus.HELD: ‘held’>,
‘stop_price’: ‘100’,
‘submitted_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 222565, tzinfo=datetime.timezone.utc),
‘symbol’: ‘AAPL’,
‘time_in_force’: <TimeInForce.DAY: ‘day’>,
‘trail_percent’: None,
‘trail_price’: None,
‘type’: <OrderType.STOP: ‘stop’>,
‘updated_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 224232, tzinfo=datetime.timezone.utc)}],
‘limit_price’: ‘125’,
‘notional’: None,
‘order_class’: <OrderClass.BRACKET: ‘bracket’>,
‘order_type’: <OrderType.LIMIT: ‘limit’>,
‘qty’: ‘1’,
‘replaced_at’: None,
‘replaced_by’: None,
‘replaces’: None,
‘side’: <OrderSide.BUY: ‘buy’>,
‘status’: <OrderStatus.ACCEPTED: ‘accepted’>,
‘stop_price’: None,
‘submitted_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 222565, tzinfo=datetime.timezone.utc),
‘symbol’: ‘AAPL’,
‘time_in_force’: <TimeInForce.DAY: ‘day’>,
‘trail_percent’: None,
‘trail_price’: None,
‘type’: <OrderType.LIMIT: ‘limit’>,
‘updated_at’: datetime.datetime(2023, 1, 24, 21, 31, 22, 224183, tzinfo=datetime.timezone.utc)}