context is the persistent algorithm object passed into every lifecycle function. Store your strategy state on it and call its methods to look up assets, trade, schedule work, inspect portfolio state and configure controls.
ziplime.api, but context calls are clearer in async code.
Asset lookup
await context.symbol(symbol, mic=None, asset_type=AssetType.EQUITY)
Look up an exchange listing by ticker. Raises SymbolNotFound if there is none.
TICKER@MIC is for when you actually know the venue — an invented MIC is the usual cause of “no asset found”. When a ticker exists on more than one venue, name the MIC.
await context.symbols(*symbols)
Several lookups at once. Returns a list of listings.
await context.universe_symbols(name, dt=None, mic=None, tradeable=True)
The members of a named universe as tradeable listings, ordered by symbol.
dtdefaults to the current session, so calling it at every rebalance follows the composition as it changes rather than freezing the one you read ininitialize.- Only members the run’s market data actually holds are returned. Pass
tradeable=Falsefor the full reference list. NAME@MICormic=pins one venue — useful when an issuer is listed on several markets.
await context.symbols_universe(name, dt=None) returns the memberships themselves (issuers, not listings). Use universe_symbols for anything you want to price or order.
await context.sid(sid)
Look up an asset by numeric SID.
Futures, options and bonds
See Futures, Options & Bonds for the full set, including sizing, Greeks and bond analytics.
Time and calendar
is_week_start() and is_month_start() read the simulation’s calendar, so holidays are handled. They are plain calls, not awaited:
Datasets
await context.huggingface_dataset(repo_id, config=None, revision=None, fields=None, start_date=None, end_date=None, name=None)
Mount a point-in-time dataset from the Hugging Face Hub, then read it with data.history(..., data_source=...). Requires ziplime[huggingface]. See Point-in-Time Datasets.
Configuration
context.algorithm.config holds the typed config loaded from JSON. See Algorithm File.
Available methods
Exchange names
Most order methods accept an optionalexchange_name. If omitted, the engine uses the default exchange of the run, which is "LIME" unless you pass default_exchange_name to run_simulation.
Use explicit exchange names when you run multiple exchanges, when you inspect or cancel an order with get_order or cancel_order, and when you query portfolio helper methods by exchange.