Description
Follow-up to #440 / #555. The convenience helpers (order_value, order_percent, order_target, order_target_value, order_target_percent) currently require an explicit price argument and always produce LIMIT orders. Extend them so users can omit price and/or request a MARKET order.
Desired Behavior
- Auto-price: When
price is omitted, fall back to context.get_latest_price(target_symbol, market) to size the order — same mechanism create_market_order already uses for percentage_of_portfolio sizing.
- MARKET variant: Accept
order_type=OrderType.MARKET on all five helpers. When set, route through create_market_order (no price required; uses the estimated latest price internally and fills at next-bar open in backtests).
- Validation: If
order_type=OrderType.LIMIT and price is None and get_latest_price returns None, raise OperationalException with a clear message.
Suggested API
# LIMIT with explicit price (today's behavior — unchanged)
context.order_target_percent("BTC", target_percent=10, price=price)
# LIMIT, auto-price from data provider
context.order_target_percent("BTC", target_percent=10)
# MARKET (immediate fill at next-bar open in backtests)
context.order_target_percent(
"BTC", target_percent=10, order_type=OrderType.MARKET
)
Notes
- The five helpers are thin wrappers around
create_limit_order today; for MARKET routing they should delegate to create_market_order instead.
- For
order_target*, the diff (BUY/SELL amount) is still computed against the current position; only the fill path changes.
- All new behavior should be covered by tests in
tests/app/algorithm/test_order_convenience_functions.py.
Related
Description
Follow-up to #440 / #555. The convenience helpers (
order_value,order_percent,order_target,order_target_value,order_target_percent) currently require an explicitpriceargument and always produce LIMIT orders. Extend them so users can omitpriceand/or request a MARKET order.Desired Behavior
priceis omitted, fall back tocontext.get_latest_price(target_symbol, market)to size the order — same mechanismcreate_market_orderalready uses forpercentage_of_portfoliosizing.order_type=OrderType.MARKETon all five helpers. When set, route throughcreate_market_order(nopricerequired; uses the estimated latest price internally and fills at next-bar open in backtests).order_type=OrderType.LIMITandprice is Noneandget_latest_pricereturnsNone, raiseOperationalExceptionwith a clear message.Suggested API
Notes
create_limit_ordertoday; for MARKET routing they should delegate tocreate_market_orderinstead.order_target*, the diff (BUY/SELL amount) is still computed against the current position; only the fill path changes.tests/app/algorithm/test_order_convenience_functions.py.Related
price.