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.
| Style | Example | Meaning |
|---|---|---|
MarketOrder() | MarketOrder() | Fill using the configured simulation execution price and slippage model. |
LimitOrder(limit_price) | LimitOrder(150.0) | Buy no higher than the limit, sell no lower than the limit. |
StopOrder(stop_price) | StopOrder(145.0) | Trigger a market order after the stop threshold is reached. |
StopLimitOrder(limit_price, stop_price) | StopLimitOrder(151.0, 149.0) | Trigger a limit order after the stop threshold is reached. |
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:
| Field | Meaning |
|---|---|
id | Ziplime order id |
asset | Ordered asset |
amount | Requested amount |
filled | Filled amount |
open_amount | Remaining amount |
status | Current order status |
commission | Accumulated commission |
dt | Last order update datetime |
exchange_name | Exchange that owns the order |
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.