Debug a Paper Session Using Logs and Snapshots
A paper session produces two different things, and confusing them wastes hours. One is a record of what your code did against market data. The other is proof that the code works right now. A stored log from yesterday is the first. It is not the second. This post walks the path from worker allocation and market tick to stored logs, fills, snapshots, order history, and a terminal session state, using Banger's current documented vocabulary, and shows where each artifact lies about what it proves.
The lifecycle, in the order events actually happen
Banger is a paper strategy runtime for prediction markets. You write or clone Python, run it against current market data, and inspect the execution trail without venue keys. Live execution is not available in the public beta, so everything below is simulated fills on real quotes, not orders on an exchange.
The documented runtime sequence for a deployment is linear. The runtime resolves your universe against Kalshi to get the market list, subscribes to ticks for all matching markets, calls on_market_tick for each update, risk-gates every simulated paper order before recording its fill, and surfaces P&L and per-position attribution. When you debug, follow that same order. A symptom at step 4 rarely originates at step 4.
- Allocation and universe resolution: did the worker start and did your universe match any live markets? An empty universe produces an idle session with no ticks and no fills.
- Tick delivery: on_market_tick(self, market, tick, ctx) fires per update. Tick prices are Decimal, bid and ask can be absent, and timestamp is a datetime. Missing quotes are a real state to handle, not a bug to assume away.
- Order request: your code calls Context.place(venue, market, side, size, price=None), where size is USD notional. The risk envelope evaluates before anything is recorded.
- Fill record: a simulated fill is stored, tied to venue, market, side, size, and price.
- Snapshots and P&L: performance snapshots, open positions, and realized and unrealized P&L accumulate on the timeline.
- Terminal state: the session stops, and its history is retained.
Read the logs before you touch the code
Strategy and runtime logs stream back to the deployment timeline. That gives you two streams in one place: lines your strategy emitted and lines the runtime emitted. Separate them first. A Python traceback in the runtime stream is a runtime error. It means your code raised, not that the market moved against a position. Do not record that as a loss. It is a defect in the run.
A specific line worth knowing: the public 0.1.7 forward-paper context can fill a non-crossing requested limit at that limit and logs paper.fill.resting-assumed when it does. If you see that tag, the simulator assumed your resting order filled at your price. That is a modeling assumption, not confirmation that a real book would have traded there. Treat fills carrying it as the softest evidence in your result.
Also watch for a price fallback. Missing quotes can cause the simulator to substitute a price. If bid or ask was absent on the tick that drove a fill, the fill price reflects that fallback, not a quote you can lean on.
Inspect fills and snapshots as separate claims
For standard Kalshi binary markets, each contract trades between 1 cent and 99 cents and settles at $1 if the outcome resolves your way or $0 if it does not. Scalar or special-rule markets can have non-standard settlement values, so the full market rules always control. For typical binary markets, a marked position, a settlement claim, credited cash, and hypothetical executable proceeds are four different numbers, and they diverge most near resolution.
When you read a snapshot, name which number you are looking at. Unrealized P&L marks open contracts at a model value. It is not cash. A settlement claim assumes the market resolved a certain way. Kalshi's API lifecycle exposes states including active, closed, determined, disputed, amended, and finalized. The consumer interface may use friendlier wording while the API exposes these states. Only a finalized market has actually paid. A snapshot taken while a market is merely closed is marking an unresolved position, which is exactly when a hopeful backtest flatters itself.
One more unit trap on fills: Context.place takes USD notional, while Context.close uses held-contract quantity. If your close logic reasons in dollars, you will close the wrong amount. The fill history will show it as a size you did not intend, not as an error line.
Risk gates explain missing fills
If an order you expected never appears, the risk envelope probably rejected it. The RiskEnvelope fields are max_position_usd, max_daily_loss_usd, max_open_positions, max_concentration_pct, and max_orders_per_minute. Note that max_position_usd limits cumulative position cost basis, not a per-order stake, so a series of small orders can hit it collectively. The forward-paper daily-loss control rejects new exposure after mark-to-market loss from the current UTC-day baseline reaches its limit. It does not flatten existing holdings, does not guarantee an eventual loss ceiling, and does not stop the worker on a timer. A gated order is correct behavior, not a failure, and it is a per-context limit, not an account-wide guarantee.
The terminal state and what it does not prove
Stopping a session preserves research history. A stopped badge can appear before resource cleanup completes, so a stopped record is not yet a confirmation that hosted resources were released. For a hosted deployment, confirm the stop, the stopped record, and completed cleanup as separate facts. And stopping a paper session says nothing about any real account's positions, because there are none.
For a local check, a short supervised run is enough to reproduce a defect. Run the file, watch the first ticks and the first fill, and send Ctrl+C when you have seen what you need. Hosted stopping needs its own confirmation path.
# local supervised check, then stop with Ctrl+C
pip install bangertrades
banger run strategy.py --paperMake the next run reproducible
Retained evidence answers what happened under one data, fill, fee, and valuation model. It does not prove the same code passes now. Two things break reproducibility quietly. First, markets expire: the first result from a discovery call today is a different market than yesterday, so pin an exact current ticker and preserve it rather than re-parsing whatever comes back first. Second, the fee model matters. The packaged standard Kalshi fee helper rounds up to a whole cent, which can differ from the venue's current finer rounding, so inspect the actual result model instead of assuming a figure. A log count bounds output lines. It does not bound the session's lifetime. When you want to know whether the strategy still works, run it again and read the new logs, not the old ones.