InQuantWeTrust logo
ArticleCommunity articleby Salem, Founder & Maintainer8 min read

IBKR Bracket Orders with Risk Controls

A safe pattern for attaching take-profit and stop-loss legs in a bracket order structure using ib_insync.

IBKRBracket orderRisk managementPythonib_insync

Bracket order intent

Bracket orders pair entry, take-profit, and stop-loss logic so risk and target behavior are pre-defined.

Always validate contract, quantity, and side carefully in paper sessions.

Python example

python
from ib_insync import IB, Stock

ib = IB()
ib.connect("127.0.0.1", 7497, clientId=22)

contract = Stock("MSFT", "SMART", "USD")
bracket = ib.bracketOrder(
    action="BUY",
    quantity=10,
    limitPrice=410.00,
    takeProfitPrice=422.00,
    stopLossPrice=402.00,
)

for order in bracket:
    trade = ib.placeOrder(contract, order)
    print(trade.order.orderType, trade.order.action, trade.order.totalQuantity)

ib.disconnect()

Risk checks before submit

  • Confirm account and contract mapping.
  • Confirm all three prices match your plan.
  • Use paper mode before any live route.
Status: PublishedFree article0 comments (thread persistence moves to PostgreSQL phase)

Related articles