Skip to content

Improved sim with trader personalities#108

Open
finnfujimura wants to merge 24 commits into
mainfrom
improved-sim
Open

Improved sim with trader personalities#108
finnfujimura wants to merge 24 commits into
mainfrom
improved-sim

Conversation

@finnfujimura
Copy link
Copy Markdown

Summary

Reworks the local maker and taker simulation bots to produce more realistic
order flow, and adds per-agent identity so the frontend can label fills by
trader personality.

Taker bot

Reworks taker execution from IID order generation into stateful parent-order
execution with archetype-driven style differences, book-aware sizing, and
per-agent metrics.

  • services/taker-bot/src/taker.rs (+661): core rework. New
    MarketSnapshot / BookSideSnapshot / BookLevel types; stateful
    parent-order execution with slice counts, urgency, persistence across ticks,
    imbalance-sensitive side selection; market-aware child sizing based on visible
    opposing depth with configurable sweep limits; spread-sensitive
    waiting/cooldown so takers don't cross every book state immediately; only
    advance parent orders after a successful submit.
  • services/taker-bot/src/archetype.rs (new, +84): ExecutionProfile
    presets so retail / whale / sniper / noise differ by execution style, not
    just rate and size.
  • services/taker-bot/src/config.rs (+73): plumbs execution-profile knobs
    through agent config; archetype defaults wired to ExecutionProfile presets.
  • services/taker-bot/src/taker_context.rs (+93): RPC market-account
    snapshot fetching cached per tick; restored fetch_market_snapshot; switched
    TakerContext::new to Arc-based shared state.
  • services/taker-bot/src/main.rs (+185): per-agent execution metrics in
    the service loop — submitted children, swept levels, filled base/quote,
    skipped wide-spread ticks, empty-book skips, faucet refills.
  • services/taker-bot/config.toml.example (+60): documents the new
    execution-profile knobs.
  • services/taker-bot/Cargo.toml (+1): adds transaction-parser.

Maker bot

Adds maker style support, dynamic spread driven by local-book signals, hit
detection, and quote-TTL refresh.

  • services/maker-bot/src/maker_context.rs (+527): bulk of the rework.
    Market-wide book storage so quoting reacts to local top-of-book, not just the
    maker's own orders; local microprice, book imbalance, recent volatility,
    dynamic half-spread; hit detection by comparing maker-owned bid/ask depth
    before and after each market update; refill delays and side-specific
    replenishment throttling after hits; ladder generation now allows fewer than
    10 quotes/side, skips the touch on recently hit sides, applies per-level
    size/price jitter; batch replace switched to
    UnvalidatedOrders::new_from_slice so dynamic quote counts are valid.
  • services/maker-bot/src/config.rs (+167): style presets (tight /
    balanced / defensive) and configurable knobs — quote TTL, refill delay
    window, partial replenishment ratio, ladder size/price jitter, local-book
    fair-value weighting, hit-driven spread widening, max quote levels, spread
    multiplier.
  • services/maker-bot/src/tasks/throttled_order_update.rs (+42):
    quote-TTL refresh logic so resting liquidity ages and refreshes even without a
    websocket-triggered state change.
  • services/maker-bot/src/main.rs (+38): switches the external price
    anchor from M15 / single candle to S5 / recent candle window for a faster
    fair-value input.
  • services/maker-bot/config.toml.example (+45): documents the new
    style/knobs.
  • services/maker-bot/Cargo.toml (+1): adds rand.

Initialization, deployment, registry

  • services/shared/examples/initialization_helper.rs (~220 lines
    changed): funds each taker agent individually during init; emits
    services/taker-bot/agents.json (a generated {name, kind, pubkey} registry)
    for the frontend to consume.
  • services/taker-bot/compose.yaml (+1): mounts a keypairs/ directory
    so multiple agent keypairs run inside the container.
  • services/.gitignore: ignores keypairs/ and taker-bot/agents.json
    (both runtime-generated).

Frontend

  • frontend/src/app/api/agents/route.ts (new, +35): reads
    services/taker-bot/agents.json, returns [] when the file is missing
    (devnet/mainnet path).
  • frontend/src/lib/queries/fetch-agent-registry.ts (new, +13) and
    frontend/src/lib/hooks/use-agent-registry.ts (new, +29): client-side
    fetch + hook exposing a pubkey → agent map.
  • frontend/src/components/TransactionLog.tsx (+68): each fill is labeled
    with its trader personality (retail-1, whale-1, sniper-1, noise-1,
    maker), color-coded by archetype; falls back to truncated signer pubkey when
    unknown.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reworks the local maker/taker simulation services to generate more realistic order flow, adds per-agent identity for takers, and exposes an agent registry so the frontend can label fills by trader personality.

Changes:

  • Taker bot: introduces market snapshots + execution profiles, runs multiple independently-keyed agents, and adds per-agent execution metrics.
  • Maker bot: adds style presets, local-book-driven quoting/spread logic, hit detection, and quote TTL refresh behavior.
  • Localnet + frontend: initialization helper now generates per-agent keypairs + agents.json; frontend adds /api/agents + client hook and UI labeling in the transaction log.

Reviewed changes

Copilot reviewed 18 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
services/taker-bot/src/taker_context.rs Adds per-agent context with shared RPC/faucet clients and market snapshot fetching.
services/taker-bot/src/taker.rs Implements market-aware, stateful parent/child execution and execution profiles; updates tests/helpers.
services/taker-bot/src/main.rs Runs one loop per configured agent, adds per-agent metrics and snapshot caching per tick.
services/taker-bot/src/config.rs Moves from single strategy config to multi-agent config with archetype defaults + keypair paths.
services/taker-bot/src/archetype.rs Adds taker archetype presets mapping to activity + execution profiles.
services/taker-bot/compose.yaml Mounts keypairs/ directory for multi-agent keypairs in container.
services/taker-bot/Cargo.toml Adds transaction-parser dependency for event parsing/snapshots.
services/shared/examples/initialization_helper.rs Funds each agent, creates missing agent keypairs, and writes services/taker-bot/agents.json.
services/run-services-on-localnet.sh New helper script to start validator, deploy, init, and run services via Docker.
services/maker-bot/src/tasks/throttled_order_update.rs Adds quote TTL-driven refresh even without websocket-triggered updates.
services/maker-bot/src/maker_context.rs Major quoting logic update: local-book signals, hit detection, jitter, throttled replenishment, TTL tracking.
services/maker-bot/src/main.rs Switches price anchor granularity/window for faster fair-value updates.
services/maker-bot/src/config.rs Adds maker style presets and new configurable quoting/spread/TTL/refill knobs.
services/maker-bot/Cargo.toml Adds rand dependency for jitter/refill delay sampling.
services/.gitignore Ignores runtime-generated keypairs directory and agent registry (but pattern needs adjustment).
frontend/src/app/api/agents/route.ts New API route to read services/taker-bot/agents.json and return [] if missing.
frontend/src/lib/queries/fetch-agent-registry.ts New client fetch helper for the agent registry.
frontend/src/lib/hooks/use-agent-registry.ts New React Query hook exposing a pubkey→agent map.
frontend/src/components/TransactionLog.tsx Labels fills with trader personality (agent or fallback signer pubkey) and colors by archetype.
Cargo.lock Locks new Rust deps (transaction-parser, rand).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/maker-bot/src/maker_context.rs
Comment thread services/.gitignore Outdated
Comment thread services/taker-bot/src/taker.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 29, 2026 21:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 20 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/maker-bot/src/config.rs Outdated
Copilot AI review requested due to automatic review settings April 29, 2026 21:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 20 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/components/TransactionLog.tsx Outdated
Comment thread frontend/src/components/TransactionLog.tsx
Comment thread services/taker-bot/src/config.rs
Comment thread services/taker-bot/src/main.rs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 29, 2026 21:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 20 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/shared/examples/initialization_helper.rs
Comment thread services/taker-bot/src/taker.rs Outdated
@alnoki
Copy link
Copy Markdown
Contributor

alnoki commented Apr 30, 2026

@finnfujimura the detailed PR summary is helpful for making sense of the architecture, but once this merges it'll be hard to follow things along from the repo itself. How about updating the relevant README(s) to describe the new layout? Might be useful to talk about the new neat activity profiles like aggressive/passive etc.

Glad to do a more detailed review once you've addressed comments from Copilot and @val-levy

Comment thread services/maker-bot/src/maker_context.rs Outdated
Comment thread services/maker-bot/src/maker_context.rs Outdated
Comment thread services/.gitignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants