Stages 3 and 4
Backtest and paper trading
One service, two sources of events. The backtest replays a dataset and computes trades with a formula over the pool reserves; paper trading executes virtual transactions against live network accounts. They share the trade journal and the PnL module; the strategy logic is the same, only a thin adapter changes.
- Stage
- Backtest
- Command or package
divers sim- Indexer
- required via a dataset
- State
- with caveats Runs on live datasets: every pump.fun curve, PumpSwap, LaunchLab and CPMM trade re-simulated exactly; Raydium AMM v4 approximated; Meteora not simulated; pump.fun curve fees are constants (the indexer does not record them). Results are in the app; the protocol and the API are drafts.
- Stage
- Paper trading
- Command or package
- Paper RPC + UI
- Indexer
- not required
- State
- works Works (
divers paper serve): checked on a mainnet node with swaps through real pool programs, each compared with the node's own simulation of the same transaction, and with replays of landed transactions. HTTP only: no WebSocket subscriptions and no Jito bundles.
Which mode for which strategy
Paper trading is for mid-frequency strategies
Paper trading is a way to test a mid-frequency strategy on data it has not seen yet.
HFT: backtest with delay only
HFT means backtest with buy-with-delay and sell-with-delay only. Paper trading is not offered for HFT.
Why: we technically cannot serve account reads with the same latency as the executor. An HFT strategy on a server with shreds sees the state before the paper node does, and when it sends a transaction we may not have the state it needs yet.
| Backtest | Paper trading | |
|---|---|---|
| Which strategy | any, including HFT: latency is set by the trade delay | mid-frequency; not HFT |
| Events for the strategy | dataset events replayed over WebSocket | live network events |
| Pool state | reserves after the previous dataset event | live accounts via getMultipleAccounts |
| How a trade is computed | the protocol's price formula over the reserves | program execution on LiteSVM |
| What the strategy changes | sends a buy or sell message to the sidecar | only the RPC address |
| Indexer | required via a dataset | not required: a node and LiteSVM |
| State | works (divers sim), results are in the app | works (divers paper serve) |
What it is
Backtest: divers sim
divers sim serve starts a sidecar over a dataset. It sends the strategy events one at a time in key order (slot, tx idx, ix idx) and takes buy, sell and ack from it. The next event goes out only after the ack of the previous one, so a run is deterministic and does not depend on the strategy's speed.
A trade has a delay in microseconds (buy-with-delay, sell-with-delay): it executes against the pool state the given time after the current replay point, by the tx_timestamp values from the indexer database. This models the strategy's latency.
Paper trading: the paper RPC
divers paper serve is an HTTP JSON-RPC compatible with Solana RPC, with API-key access. The strategy changes only its RPC address, to http://HOST:PORT/<API_KEY>/<SESSION>. Each session is a fork bound to a session id and one wallet. The RPC reads the accounts it needs from the upstream node via getMultipleAccounts, substitutes the wallet's accounts from the fork and executes the transaction on LiteSVM; nothing is sent to the network, and virtual trades change neither pools nor other accounts.
Testing. Checked on a mainnet node: swaps built by a public router through real pool programs give the same outcome, and the same compute units when both read the same slot, as the node's own simulation of the same transaction; landed version-1 transactions replay with the network's fee.
A session's virtual transactions, successful and failed, live in its virtual pool: getTransaction and getSignatureStatuses look up the signature there first. The strategy learns that a trade failed the same way it does on mainnet.
A paper session on the chart
120 candles from 14:00:00.000 to 14:09:55.000 UTC, price 0.0₇284 to 0.0₇284 SOL, 1247 events. Use the arrow keys to step through candles, Enter to open an own trade of the candle; the event list below has every event.
- Buy
- Sell
- Real: filled
- Paper / backtest: hollow, dashed
- Failed: crossed
- Trigger
- Pool txs: buys above, sells below the line
Event list (1247)
What it gives traders and quants
- One strategy on history and on the live network. Only the adapter changes: a
buy/sellmessage in the backtest, a transaction to the RPC in paper trading. An example of the split:crates/divers-sim/examples/backtest_strategy.rs. - Reproducibility. The same strategy on the same dataset produces a byte-identical journal, whether it is fast or slow.
- Latency as a parameter.
delay_uson every trade: you see what each millisecond costs. - Honest failures. A trade the program would reject (slippage, insufficient balance or liquidity) is written to the journal as failed, with the fee charged, as on mainnet. A trade on a program the formulas do not compute is rejected, not approximated.
- One journal and one PnL. Every trade is written in the
divers-pnlformat;divers sim reportshows positions, changes and costs. - Without a strategy.
divers sim tradeanddivers sim runexecute one trade or a file of trades on the same replay.
How to run
divers sim serve pump-jan --listen 127.0.0.1:8765 --journal-dir runs/ --once
# the strategy connects to ws://127.0.0.1:8765: hello → ready → update/ack, buy, sell → end
divers sim trade pump-jan --pool P --side buy --amount 100000000 \
--at 250231044/3/2 --delay-us 300000
divers sim run pump-jan --trades trades.jsonl --journal run.jsonl
divers sim report run.jsonl # positions, changes, costs (divers-pnl)The dataset must be downloaded with the "backtest required" group, otherwise the sidecar does not start; a dataset without the verification flag gets a warning.
The hello, update, ack, buy, sell, receipt and end messages are described in docs/PROTOCOL-backtest-ws.md. This is a draft of version 1: the format awaits confirmation and may change.
export DIVERS_API_KEY=YOUR_API_KEY # or api_key in .onchaindivers
export DIVERS_PAPER_UPSTREAM=YOUR_NODE_URL # or --upstream URL
divers paper serve --listen 127.0.0.1:8899 # strategy: http://127.0.0.1:8899/<API_KEY>/<SESSION>
divers paper sessions # sessions; divers paper session ID: transactions and PnL
divers paper reset ID # return a session to its initial state
divers paper report # PnL from the journals, no server
divers sim api --journal-dir <data dir>/paper # paper sessions in /appRPC address for the strategy: http://HOST:PORT/<API_KEY>/<SESSION>. A request without the key gets HTTP 401. Journals: one <SESSION>.jsonl per session, in <data dir>/paper by default.
divers sim api --journal-dir runs/ --dataset pump-jan # UI API at http://127.0.0.1:8766/api/v1
divers sim serve pump-jan --journal-dir runs/ --api-listen 127.0.0.1:8766 # the same inside a backtest
# then open /app on this siteThe API only reads journals; the /app page in your browser makes the requests. The API is a draft (docs/API-ui.md).
Backtest results are viewed in the app: run divers sim api --journal-dir DIR (listens on 127.0.0.1:8766 by default; with --dataset NAME it also serves candles and neighbouring trades) or divers sim serve DATASET --journal-dir DIR --api-listen 127.0.0.1:8766 to watch a backtest while it runs. Paper sessions are written by divers paper serve (journals in <data dir>/paper by default); to see them in the app, run divers sim api --journal-dir <data dir>/paper.
Limitations
Both modes
- No competition for the slot. A virtual trade does not lose a race to other transactions of the slot or block.
- Virtual trades do not move the market. History is replayed as it was; only the virtual wallet changes. A second trade in the same pool executes against the historical reserves, not those shifted by the first.
- The result is an upper bound relative to live trading.
Backtest, first version
- The formulas are reconciled with live history for the pump.fun curve, PumpSwap, Raydium LaunchLab and CPMM (exact); Raydium AMM v4 is approximated; Meteora is not simulated; pump.fun curve fees are constants because the indexer does not record them.
- Not computed: Meteora DBC and DAMM v1, Raydium LaunchLab curves other than constant product, Meteora DAMM v2 modes other than compounding; CLMM and DLMM are outside the first version.
- Network fees, priority fee and tip are constants per trade; there is no model of compute units or of token-account rent.
- One strategy per sidecar at a time.
Paper trading, this version
- Legacy and version-0 transactions are accepted, including Address Lookup Tables, and version-1 transactions. Jito bundles are not supported.
- Only the signer's SOL and token accounts live in the fork (SPL Token and Token-2022). Other accounts a program writes for the user (protocol PDAs) are not kept between transactions.
- Virtual transactions do not appear in Geyser: a strategy's subscription to its own results will not see them. The result is read with
getSignatureStatusesorgetTransaction. - HTTP JSON-RPC only. There are no WebSocket subscriptions: a strategy that confirms transactions through
signatureSubscribemust pollgetSignatureStatusesorgetTransaction. No Jito bundles.
Place in the chain
- Input
- Backtest: a dataset from the fetcher, preferably with the validation flag. Paper trading: the live network, no indexer needed.
- Output
- A trade journal with balances before and after, for post-trade analysis and
divers-pnl.