context. Place them in handle_data or in scheduled callbacks. Do not place orders in initialize or before_trading_start.
Execution styles
Import execution styles fromziplime.finance.execution.
Fixed quantity
await context.order(asset, amount, style, exchange_name=None)
Positive amount buys or covers. Negative amount sells or shorts.
Target quantity
await context.order_target(asset, target, style, exchange_name=None)
Adjust your position to a target number of shares or contracts.
Portfolio percent
await context.order_target_percent(asset, target, style, exchange_name=None, reserved_percentage_for_fees=0.05)
Adjust your position to a target portfolio weight. target must be between -1 and 1.
await context.order_percent(asset, percent, style, exchange_name=None)
Order an incremental percent of current portfolio value. This is not a target. It adds or removes exposure relative to the current position.
Dollar value
await context.order_target_value(asset, target, style, exchange_name=None)
Adjust your position to a target notional value.
context.order_value(...)
order_value is present as a Zipline-style compatibility method for incremental dollar orders. In current Ziplime strategy code, prefer order_target_value, order_percent, or order unless you have verified that your runtime path supports the exact order_value behavior you need.
Open orders
context.get_open_orders(asset=None)
Return currently open orders. Pass an asset to filter by asset.
context.get_order(order_id, exchange_name)
Retrieve an order by id.
await context.cancel_order(order_id, exchange_name, relay_status=True)
Cancel an open order.
Returned order object
Order methods return anOrder object or None if no order was placed.
Useful fields:
Fill timing
run_simulation(..., same_bar_execution=True) means orders submitted during handle_data can be filled in the same bar. With same_bar_execution=False, orders submitted in handle_data are filled on a later bar.
Execution price is controlled by price_used_in_order_execution, one of "open", "close", "low", or "high", and by the configured slippage model.