Run The Reference Market Maker#
This page is the canonical on-ramp for the reference market maker. The kit
in packages/bot-rust is an educational starter, not a production trading
system. It is dry-run by default and should stay dry-run until you have reviewed
the config, risk limits, wallet funding, and market behavior.
What It Does#
The reference configuration:
- Reads Solana market and orderbook state.
- Reads Pyth prices through a Hermes endpoint.
- Builds simple two-sided quotes.
- Skews quotes based on inventory.
- Applies spread, inventory, max-loss, and open-order limits.
- Prints intended actions in dry-run mode.
It is not proprietary alpha and it is not a production market-making service.
Start In Dry Run#
The sample configuration does not start infrastructure. Before running it,
provide both local dependencies configured in packages/bot-rust/configs/mm.toml:
- a Solana RPC with the Seesaw program and discoverable test markets at
http://127.0.0.1:8899; and - a Hermes-compatible service with the configured feed data at
http://127.0.0.1:8787/hermes.
Then, from the repo root:
cargo test --manifest-path packages/bot-rust/Cargo.toml
cargo run --manifest-path packages/bot-rust/Cargo.toml -- packages/bot-rust/configs/mm.toml
The sample mm.toml uses safe local defaults:
dry_run = true- local Solana RPC
- local Hermes URL
- virtual dry-run balance
- no live transaction sending
- conservative quote size and inventory caps
The package README documents the framework internals and other starter strategies. Keep setup and safety guidance on this page so integrators have one market-maker entry point.
Key Config Fields#
| Field | Purpose |
|---|---|
bot.dry_run | Keeps the bot from sending transactions while testing. |
bot.dry_run_virtual_balance | Simulated settlement balance when no live account is funded. |
bot.treasury_token_accounts | Live-only ordered list of exactly eight distinct treasury SPL token accounts. |
feeds.hermes_url | Pyth Hermes endpoint. |
feeds.hermes_api_key or PYTH_API_KEY | Required for upgraded Hermes endpoints. |
strategy.market_making.base_spread_bps | Neutral spread around the mid. |
strategy.market_making.quote_size | Size per quote in settlement base units. |
strategy.market_making.max_inventory | Inventory cap for the strategy. |
strategy.market_making.exit_cutoff_secs | Time before market end when quotes should stop. |
risk.max_loss | Max cumulative buy exposure (see Risk Ledger). |
risk.max_open_orders | Maximum simultaneous open orders. |
risk.min_settlement_balance | Settlement reserve to keep untouched. |
Before Live Trading#
Do all of this before setting dry_run = false:
- Use a dedicated wallet.
- Fund only the amount you are prepared to risk.
- Confirm the target RPC, program ID, settlement mint, market creators, and Pyth feed IDs.
- Provide
PYTH_API_KEYthrough the environment or a protected config file. - Configure exactly eight distinct
bot.treasury_token_accounts, in the same index order as the on-chainconfig.treasury_recipients[i]array. A single treasury account, duplicate entries, or a reordered list is invalid. - Confirm startup uses
LiveExecutor::new_verified. It fetches the Config PDA and fails closed before trading if the program owner, settlement mint, or any indexed treasury recipient differs from the configured value. - Set
strategy.market_making.kill_switch = falseonly when ready. - Run against a local or staging market first.
- Watch order placement, cancel behavior, and settlement claims end to end.
- Keep final-minute exposure limits conservative.
Risk Ledger#
risk.max_loss caps cumulative buy exposure in settlement base units. It is
not mark-to-market P&L, and it is separate from the share-inventory and
open-order caps. The budget counts three things:
- Acquired cost. Quote spent on BUY fills, plus the protocol and referral fees decoded from the placement transaction. Taker fills are counted when the order confirms. Fills a resting order gets later as a maker are counted when a confirmed cancel-all shows how much of that order was still resting. The cost is the reserve minus the collateral returned. If the order is no longer on the book, the bot assumes it filled and counts the whole reserve. Maker rebates are not credited back. Selling shares does not lower acquired cost.
- Open reserve. The worst-case quote of each resting BUY, kept per program order id. A cancel-all frees only the part that was never filled. If the cancellation's events cannot be decoded, or the order id is unknown, the reserve stays in place.
- Pending reserve. Each signed order is written to
risk.state_pathbefore it is sent: signature, exact bytes, last valid block height, signing slot and exposure. The reserve stays until reconciliation shows the transaction succeeded, failed, or provably never landed. That last case needs the finalized block height to have passed the attempt's last valid height, an empty status lookup, and a finalized wallet history that reaches back past the signing slot without the signature. Elapsed time and restarts never release a pending order. While one is unresolved, the bot places no new orders in that market.
The ledger is versioned ("version": 2). Only one bot process can own a
ledger at a time: it holds an OS lock on <state_path>.lock. A ledger written
by an older bot (no version field) keeps its charges but blocks new orders,
because that bot never saved its pending submissions or resting-order
reserves. To upgrade:
- Stop the old bot normally so its shutdown cancel-all runs.
- Check on chain that the wallet has no unresolved signatures and no resting orders in the markets it traded.
- Remove
prior_format_reconciliation_requiredfrom the state file, or set"version": 2if the file has no version.
Older bots refuse version 2 files and stop at max_loss, so rolling back
cannot quietly drop records. The startup log line risk ledger loaded lists
every unresolved item and the evidence needed to clear it.
Risk Notes#
- Makers pay no fee on resting fills, but exiting inventory as a taker can cost fees and slippage.
- Thin books can move sharply near resolution.
- A dry-run strategy that looks stable can behave differently when live transactions compete for block space.
- Always keep enough SOL for transaction fees and enough settlement balance for the configured quote sizes.
See also: