InQuantWeTrust logo
ArticleCommunity articleby Samir Patel9 min read

IBKR Order Types with Python Examples

A practical guide to market, limit, stop, and stop-limit orders in IBKR with safe Python examples using ib_insync.

IBKROrder typesPythonib_insyncExecution

Why order type choice matters

Order type selection directly affects fill quality, slippage, and execution risk.

Start with explicit order parameters and paper-trading validation before using any order logic in live environments.

Core order types

  • MarketOrder: prioritizes immediate execution, not price certainty.
  • LimitOrder: prioritizes price control, but may not fill.
  • StopOrder: activates a market order after trigger price is reached.
  • StopLimitOrder: combines trigger behavior with limit-price constraints.

Python example

python
from ib_insync import IB, Stock, MarketOrder, LimitOrder, StopOrder, StopLimitOrder

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

contract = Stock("AAPL", "SMART", "USD")

market_order = MarketOrder("BUY", 10)
limit_order = LimitOrder("BUY", 10, 185.00)
stop_order = StopOrder("SELL", 10, 175.00)
stop_limit_order = StopLimitOrder("SELL", 10, 174.50, 175.00)

print(market_order, limit_order, stop_order, stop_limit_order)
ib.disconnect()
Status: PublishedFree article0 comments (thread persistence moves to PostgreSQL phase)

Related articles