Skip to content
Skip to content

SDK reference

The olypse Python module: the Strategy class and its settings, the callbacks, what ctx offers, and the helper functions, each with what it does.

Bot sandboxUpdated

On this page
  1. A minimal strategy
  2. Strategy settings
  3. Callbacks
  4. What ctx offers
  5. Helper functions

Your code imports olypse. The same strategy runs under Run (live prices, paper orders) and Backtest (replayed history), with one difference: limit orders work in backtests only, because paper trading takes market orders only. The editor shows each name's full description on hover; this page is the overview.

A minimal strategy#

  1. Subclass olypse.Strategy and set markets, for example markets = ["kalshi:<market ticker>"] or ["polymarket:<condition id>"] (at most 100 in a backtest, 25 in a Run). To find a market's id, ask the sandbox assistant for it by name: its market search returns the id to use.
  2. Override on_bar(self, ctx): read ctx.price(m), decide, and call ctx.buy(m, shares) or ctx.sell(m, shares). Call ctx.why("…") when it decides not to trade.
  3. End the file with olypse.main(YourStrategy).

Strategy settings#

markets

The markets, as kalshi:<market ticker> (the ticker Kalshi shows for the market) or polymarket:<condition id> (a long code starting 0x that the assistant's market search returns). Name them explicitly for a backtest.

interval

1m, 5m, 15m or 1h: the bar size in a backtest and the poll period in a run (never faster than 10 seconds). Default 1m.

warmup

Bars of history loaded before the strategy starts (default 100, at most 1,000). Set it to your longest lookback.

max_orders

Runs only: the most paper orders one run may place (default 10).

poll_seconds

Runs only: a different poll period, 10 seconds or more.

preflight

Runs only: replay the last 7 days first and print the expected trades a day (default on).

news

True loads news linked to your markets for ctx.news and on_news. Also news_kinds and news_lookback_hours (0–168, default 24).

Keep tunable numbers in config.toml and read them with olypse.config() inside __init__ or on_start, so a backtest can try other values.

Callbacks#

on_start(ctx)

Once, before the first bar; warm-up bars are already loaded.

on_bar(ctx)

Each time new bars arrive (backtest) or on every poll (run).

on_whale(ctx, trade)

A whale trade ($1,000 or more) on one of your markets, when Olypse had it.

on_news(ctx, item)

A news item linked to one of your markets, when Olypse had it and had linked it, never the publisher's date.

on_resolution(ctx, res)

One of your markets resolved: its status, outcome and payout per YES share.

on_timer(ctx, tag)

A timer set with ctx.schedule(seconds, tag) is due.

What ctx offers#

ctx.now, ctx.markets, ctx.mode

The current time (the replay clock in a backtest), your markets, and backtest or live.

ctx.price, ctx.bid, ctx.ask

The last known YES price, bid and ask (0 to 1). Bid and ask only where the venue reports quotes.

ctx.history, ctx.bars, ctx.bar_at

Recent prices or bars, oldest first, and one bar by its start time.

ctx.price_at, ctx.quote_at

What was known at an earlier time, never after now.

ctx.info(m)

What was known about a market before it traded: title, outcome, category, event and end date. Never the result.

ctx.buy, ctx.sell

A market order for a number of shares on YES or NO. fill='mid' asks for an idealised fill at the midpoint, flagged as IDEALISED FILLS.

ctx.limit_buy, ctx.limit_sell, ctx.cancel, ctx.open_orders

Resting limit orders at a price in cents (1–99), with an optional time to live, and managing them. Backtests only: under Run every limit order is refused, because paper trading takes market orders only. Running a bot on paper.

ctx.position, ctx.filled_position, ctx.pending

Shares held (with or without orders still waiting), and shares in waiting orders.

ctx.cash, ctx.equity

Cash, and cash plus positions at the bid.

ctx.news, ctx.news_count, ctx.last_news

Linked news Olypse had by now, by market and kind.

ctx.schedule, ctx.cancel_timer

Call on_timer after a number of seconds, and cancel it.

ctx.updated()

The markets whose bars arrived in this on_bar (every market in a run).

ctx.why(text), ctx.log(…)

Say why it is not trading (counted per bar in a backtest, shown in a run's status), and print to the terminal.

Helper functions#

For scripts and for code outside a Strategy's callbacks. In a backtest, read data through ctx instead: the replay switches the network helpers off.

olypse.markets(…), olypse.market(venue, id)

Open markets, busiest first (filter by venue, search text, category), and one market's details.

olypse.prices(ids)

Current prices for one or more venue:id keys.

olypse.whale_trades(…), olypse.whale_target(trade)

Recent whale trades, newest first, and the paper order that would copy a whale's buy.

olypse.news(…)

News linked to markets, newest first.

olypse.paper_buy, olypse.paper_sell

Place a paper order in the API sandbox portfolio (runs only).

olypse.orders(), olypse.positions(), olypse.portfolio()

The sandbox portfolio's recent orders, positions and balance.

olypse.config()

The project's config.toml as a dictionary, with any backtest overrides applied.

olypse.get(path, …)

Any other read, returning the whole page of results.

olypse.minutes_ago(n), olypse.sleep(s), olypse.log(…)

A timestamp n minutes ago, a pause of up to 120 seconds (skipped in a backtest), and printing.

olypse.main(Strategy)

Starts the run or the backtest. Call it once, at the end of the file.

olypse.OlypseError

Raised when a call fails, with its status, error code and how long to wait before retrying.

Still stuck? Contact support.