Skip to main content
This guide documents the language surface you use inside a Ziplime algorithm file. An algorithm file is ordinary Python, but Ziplime gives it a small event-driven API:
  • context stores your strategy state and exposes trading functions.
  • data gives access to current and historical market data.
  • Lifecycle functions tell Ziplime when to set up, trade, prepare a session, and analyze results.
Most strategy work happens in two functions:

Mental model

initialize is your setup block. Look up assets, store parameters, register scheduled callbacks, and configure controls there. handle_data is your trading block. It runs on every emitted bar, reads data, checks portfolio state, places orders, and records metrics. before_trading_start is an optional daily preparation hook. Use it for daily universe selection or pipeline output. Do not place orders there. analyze is an optional reporting hook after the backtest finishes.

Minimal algorithm

Main objects

Async rule of thumb

Use await when calling functions that load data, look up assets, place orders, or cancel orders:
In the current runtime:

API map

  1. Algorithm file
  2. Context API
  3. Market data
  4. Orders
  5. Portfolio and recording
  6. Scheduling and controls
  7. Pipelines
  8. Migrating from Classic Zipline