Skip to main content
context is the persistent algorithm object passed into lifecycle functions. Store your strategy state on it and call its methods to look up assets, trade, schedule work, inspect portfolio state, and configure controls.

Direct context style

Prefer direct method calls on context:
from ziplime.finance.execution import MarketOrder

asset = await context.symbol("AAPL")
await context.order_target_percent(asset, 0.25, style=MarketOrder())
Ziplime also exposes Zipline-style functions through ziplime.api, but context calls are clearer inside async algorithm code.

Asset lookup

await context.symbol(symbol, mic=None, asset_type=AssetType.EQUITY)

Look up an exchange-listed asset by ticker.
context.aapl = await context.symbol("AAPL")
context.nflx = await context.symbol("NFLX@XNGS")
context.msft = await context.symbol("MSFT", mic="XNGS")
If the symbol string contains @, the part after @ is interpreted as the MIC exchange code.

Multiple symbols

Recommended pattern:
SYMBOLS = ["AAPL", "MSFT", "NVDA"]


async def initialize(context):
    context.assets = [await context.symbol(symbol) for symbol in SYMBOLS]
context.symbols(*symbols) exists for compatibility, but in the current implementation it returns a list of awaitables. If you use it, gather or await each item:
import asyncio

context.assets = await asyncio.gather(*context.symbols("AAPL", "MSFT", "NVDA"))

await context.symbols_universe(name, dt=None)

Load a named symbol universe from the asset service.
context.q100us = await context.symbols_universe(name="Q100US")
If dt is omitted, Ziplime uses the current simulation datetime.

await context.sid(sid)

Look up an asset by numeric SID.
asset = await context.sid(12345)

await context.future_symbol(symbol, exchange_name=None)

Look up a futures contract.
contract = await context.future_symbol("ESM25", exchange_name="XCME")

Time and configuration

context.get_datetime()

Return the current simulation datetime.
now = context.get_datetime()
context.simulation_dt holds the same current simulation timestamp.

context.algorithm.config

Access a typed algorithm config loaded from JSON.
async def initialize(context):
    cfg = context.algorithm.config
    context.max_weight = cfg.max_weight
See Algorithm file for the config class pattern.

Available methods

MethodAwait?Main use
symbol(symbol, mic=None, asset_type=...)YesLook up an equity or exchange asset.
symbols(*symbols, **kwargs)See noteCompatibility helper; prefer list comprehensions.
symbols_universe(name, dt=None)YesLoad a named universe.
sid(sid)YesLook up by numeric asset id.
future_symbol(symbol, exchange_name=None)YesLook up a futures contract.
get_datetime()NoCurrent simulation datetime.
record(**kwargs)NoAdd custom columns to performance output.
schedule_function(func, date_rule=None, time_rule=None, ...)NoRegister a callback.
order(asset, amount, style, exchange_name=None)YesBuy or sell a fixed quantity.
order_percent(asset, percent, style, exchange_name=None)YesTrade an incremental percent of portfolio value.
order_target(asset, target, style, exchange_name=None)YesTarget a share/contract quantity.
order_target_value(asset, target, style, exchange_name=None)YesTarget a dollar exposure.
order_target_percent(asset, target, style, exchange_name=None)YesTarget a portfolio weight.
get_open_orders(asset=None)NoInspect open orders.
get_order(order_id, exchange_name)NoRetrieve a specific order.
cancel_order(order_id, exchange_name, relay_status=True)YesCancel an open order.
set_long_only()NoDisallow short positions.
set_max_leverage(max_leverage)NoCap account leverage.
set_max_position_size(...)NoCap position size.
set_max_order_size(...)NoCap single-order size.
set_max_order_count(max_count)NoCap order count per day.
attach_pipeline(pipeline, name, ...)NoRegister a pipeline during initialization.
pipeline_output(name)NoRead attached pipeline results after initialization.

Exchange names

Most order methods accept an optional exchange_name. If omitted, Ziplime uses the default exchange configured by the simulation runner. The examples in this repository commonly use "LIME" as the simulation exchange name. Use explicit exchange names when:
  • You run multiple exchanges.
  • You inspect or cancel an order with get_order or cancel_order.
  • You query portfolio helper methods by exchange.