Skip to content

Feature: MARKET variant + auto-price for order convenience functions #556

Description

@MDUYN

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

  1. 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.
  2. 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).
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions