Skip to content

Orders

All order methods return OrderResult:

python
OrderResult(
    success=True,
    order_id='738082887',
    message=None,
    raw={'result': [...], 'status': 'success'}
)

Market Orders

python
result = client.buy_market("SPY", 10)
result = client.sell_market("SPY", 10)

Limit Orders

python
result = client.buy_limit("SPY", 10, price=690.50)
result = client.sell_limit("SPY", 10, price=695.00)

Stop Orders

python
result = client.buy_stop("SPY", 10, stop_price=695.00)
result = client.sell_stop("SPY", 10, stop_price=685.00)

Stop-Limit Orders

python
result = client.buy_stop_limit("SPY", 10, stop_price=695.00, limit_price=695.50)
result = client.sell_stop_limit("SPY", 10, stop_price=685.00, limit_price=684.50)

Common Parameters

ParameterTypeDefaultDescription
symbolstrrequiredTicker symbol
quantityintrequiredOrder quantity
pricefloat-Limit price
stop_pricefloat-Stop trigger price
limit_pricefloat-Limit price for stop-limit
conidintNoneContract ID (auto-resolved if None)
tifstr"DAY"Time in force: DAY, GTC, IOC, OPG
exchangestr"SMART"Routing exchange
forceboolTrueAuto-confirm IBKR warnings

Cancel Order

python
success = client.cancel_order("738082887")  # Returns bool

Wait for Fill

python
status = client.wait_for_fill(order_id, timeout=30)

Returns: Dict

python
{
    'status': 'Filled',
    'filled_quantity': 10,
    'avg_fill_price': 690.54
}

Bracket Orders

python
result = client.place_bracket_order(
    symbol="SPY",
    quantity=10,
    side="BUY",
    entry_price=690.00,
    stop_loss=685.00,
    take_profit=700.00,
    entry_type="LMT"
)

Trailing Stop

python
result = client.place_trailing_stop(
    symbol="SPY",
    quantity=10,
    side="SELL",
    trail_amount=2.00,      # or trail_percent=0.5
)

Combo Orders

python
from trading_sdk import ComboLeg

legs = [
    ComboLeg(conid=123456, ratio=1, action="SELL"),
    ComboLeg(conid=789012, ratio=1, action="BUY")
]

result = client.place_combo_order(
    legs=legs,
    quantity=1,
    side="BUY",
    order_type="LMT",
    price=1.50
)

Options with conid

For options, always provide the conid:

python
# Get option conid first
contracts = client.get_option_contract(
    symbol="SPX", expiry="20260126", strike=6900, right="P", trading_class="SPXW"
)
opt_conid = contracts[0]["conid"]

# Place order with conid
result = client.buy_limit("SPX", 1, price=5.00, conid=opt_conid)