Skip to Content
Examples and scripts

Guides

Examples and scripts

Rystic-Inc/rystic-scripts  holds the scripts that ship in the simulators’ release archives, one folder per simulator, plus four example stacks. The scripts are MIT-licensed: copy, change and share them. The simulators stay under each archive’s LICENSE.txt.

git clone https://github.com/Rystic-Inc/rystic-scripts
folderwhat’s in it
<simulator>/check.sha smoke check, one per simulator
kalshi/trade-check.sh, api-check.py, bots/, recordings/capture-setup.sh
github-pulls/bots/bot.py, test_bot.py and five broken variants/
environments/four example stacks

What you need

  1. bash and curl. The shell scripts run on the bash 3.2 that macOS ships. None uses jq, but the command that reads a port from rystic run --json does.
  2. curl 7.75 or later for s3/check.sh, which signs its requests with --aws-sigv4.
  3. Python 3.9 or later. The Kalshi scripts use only the standard library; the GitHub bots need requests (pip install requests).
  4. openssl for api-check.py. Kalshi’s and Clerk’s check.sh use it when it’s there.
  5. An installed simulator, and the API key or license rystic login stored. A script that boots a simulator finds them where the CLI does.

check.sh

One per simulator. It boots its own simulator from the binary in its folder, runs a short round trip on that simulator’s API (table below), then resets. The simulator stays up so you can point a client at it.

Run the shipped copy

An installed simulator lives in ~/.rystic/twins/<product>/<version>/ (under $RYSTIC_HOME if you set it): the binary, check.sh, HOWTO.md, LICENSE.txt and any extra scripts. rystic check prints the path:

rystic check stripe-twin
# -> ✓ stripe-twin ... serves and resets cleanly (model ...)
# ->   deeper product checks: bash .../check.sh

PORT=$(python3 -c 'import socket; s = socket.socket(); s.bind(("", 0)); print(s.getsockname()[1])')
bash ~/.rystic/twins/stripe-twin/$(cat ~/.rystic/twins/stripe-twin/current)/check.sh localhost:$PORT
# -> ...✓ stripe-twin is good to go on localhost:... (kill ... to stop; its log is ...)
  1. The argument is the address to serve on, and the Python line above picks a port nothing holds. Without one it takes port 8080 or a free port, depending on the simulator, and it prints the address it serves on.
  2. RYSTIC_CHECK_STOP=1 stops the simulator once the checks pass, for CI:
PORT=$(python3 -c 'import socket; s = socket.socket(); s.bind(("", 0)); print(s.getsockname()[1])')
RYSTIC_CHECK_STOP=1 bash ~/.rystic/twins/stripe-twin/$(cat ~/.rystic/twins/stripe-twin/current)/check.sh localhost:$PORT
# -> ...✓ stripe-twin passed its checks on localhost:... (stopped)

rystic check is the same idea for any simulator: it serves, reports a model hash and resets.

Run the repo copy

check.sh runs the binary next to it. Put the two in a folder of your own, not in ~/.rystic:

mkdir check
cp rystic-scripts/stripe/check.sh check/
ln -s ~/.rystic/twins/stripe-twin/0.0.36/stripe-twin check/
PORT=$(python3 -c 'import socket; s = socket.socket(); s.bind(("", 0)); print(s.getsockname()[1])')
RYSTIC_CHECK_STOP=1 bash check/check.sh localhost:$PORT
# -> ✓ stripe-twin passed its checks on localhost:... (stopped)

What each one checks

simulatorcheck.sh
Kalshiseeds a market and reads it back; then run trade-check.sh
GitHublists the open-queue scenario’s pull requests, reads one, refuses an unknown one
Stripecreates a customer, reads it back, 404 on an unknown id
Slackcreates a channel, posts a message, reads both back, refuses an unknown channel
Linearfiles an issue in the sprint-board scenario, reads it back, refuses an unknown issue
Lobsaves an address, sends a postcard to it, reads both back, refuses an unknown postcard
Notionadds a page and a paragraph to the team wiki, reads them back, trashes the page; refuses a missing page and a request without Notion-Version
Oktacreates a staged user and a group, adds the user, reads both back, 404 on an unknown user
PayPalcreates an order, reads it, patches it, 404 on an unknown capture
Resendcreates, reads and lists an email; creates, reads and deletes a webhook; 404 on an unknown email
S3lists the static-site scenario’s buckets, puts and reads an object under a key with a slash, deletes it, refuses a missing key
Clerkcreates a user and an organization, merges metadata, refuses a missing user and a request with no secret key; with openssl, signs in through the browser companion
Dropboxcreates a folder, uploads and downloads a file, refuses a duplicate and a missing path with 409, deletes
Google Drivecreates a folder, uploads a file into it, downloads it, 404 on a missing file, deletes
Anthropicreads the skill library scenario’s skills, sends a message and gets an assistant reply, creates a skill and reads it and its version back, 404 on an unknown skill, refuses a request with no API key
Gmailreads the busy inbox scenario’s messages, inserts a message and reads it back at the top of the inbox, 404 on an unknown message, refuses a request with no token
Shopifyreads the apparel storefront scenario’s shop and a product, creates a product and reads it back with the handle its title makes, null for an unknown product, refuses a request with no access token, resets and reloads the scenario
Wordserves the add-in harness, reads the redlined contract’s tracked changes and comment, appends a tracked insertion, refuses a missing comment with ItemNotFound
Jirareads the sprint-board scenario’s epic and searches its issues, files an issue and reads it back in To Do, 404 on an unknown issue, refuses a request with no credential, resets and reloads the scenario
QuickBooksreads the Blue Heron Bakery company and the seeded customer with its balance, creates a vendor and reads it back at SyncToken 0, fault 610 on an unknown customer, 401 with no token, resets and reloads the scenario
PostHogreads the first-event scenario’s signup event, captures an event and reads it back, 401 on an event with no project token, resets and reloads the scenario
Modalover gRPC, with a curl built for HTTP/2: looks up the app-states scenario’s deployed app by name, creates an app and reads it back, NOT_FOUND on a function the app does not have, resets and reloads the scenario
Airtablereads the launch-tracker scenario’s first task, creates a record and reads it back, 404 NOT_FOUND on a malformed record id, 401 on a request with no token, resets and reloads the scenario

Kalshi

Start a simulator with a market in it:

PORT=$(rystic run kalshi-twin -d --name kalshi --port 0 --scenario tight_book --json | jq -r .data.port)

--port 0 picks a free port and PORT keeps it. The commands below use it, and rystic stop kalshi ends it.

In the archive these scripts sit next to the binary; in the repo they’re under kalshi/.

Bots

B=rystic-scripts/kalshi/bots
python3 $B/book-reader.py http://localhost:$PORT
# -> bid 0.3900 x 25  |  ask 0.4000 x 25  |  mid 0.3950
python3 $B/balance-watcher.py http://localhost:$PORT
# -> balance 10000.0000  |  positions flat  |  0 resting order(s)  |  0 fill(s)
python3 $B/simple-bot.py http://localhost:$PORT
# -> buy 1 @ 0.4000: filled 1.00 — balance 9999.6000
python3 $B/random-walker.py http://localhost:$PORT
# -> the twin coped: every order answered, account and book still read

The first three run until Ctrl-C. What each bot does, its arguments and how RYSTIC_TICKS stops it: Kalshi → Example bots.

Checks

bash rystic-scripts/kalshi/trade-check.sh localhost:$PORT
# -> ✓ trade check passed: FOK bid 10 @ 0.40 crossed the book — fill, position, book depletion, and WS egress all correct

python3 rystic-scripts/kalshi/api-check.py http://localhost:$PORT
# -> ✓ account.limits: GET account/limits -> 200 (want 200)
# -> …one line per check, then the total

Both reset the simulator and seed their own state, so post your scenario again afterward. What each one checks: Kalshi → Smoke tests.

Sort your captures into tapes

capture-setup.sh sorts Kalshi capture files you already have into the folder layout replay and batch backtests read. It records nothing:

bash rystic-scripts/kalshi/recordings/capture-setup.sh ~/Downloads/captures
# -> ✓ 2 placed, 0 already in place, 0 skipped — 2 markets / 2 files under /Users/you/data/kalshi-orderbook/events

Kalshi → Batch backtests → Tapes says where it copies and what it skips.

GitHub review bots

github-pulls/bots/ holds a Kalshi market maker, not a GitHub client. It is the code under review in the GitHub simulator’s github-pulls_bot_pr_queue scenario.

  1. bot.py keeps a bid and an ask resting behind the touch on one market, never crosses, and cancels everything at SESSION_SECONDS (default 30) or on SIGTERM. It is configured through the environment: KALSHI_BASE_URL, TICKER, QUOTE_SIZE, MAX_INVENTORY and others.
  2. variants/ holds five copies of bot.py, each broken one way: sides swapped, a syntax error, the wrong orders path, prices in cents, a required order field dropped. Each one is an open pull request in that scenario, #11 to #15, with a failed bot-smoke check run. Use them to test a grader or a review agent: approving any of them means it missed the bug.
  3. test_bot.py checks that bot.py rests both sides, never crosses or fills on a static book, and exits flat. Then it checks that no variant ever rests both sides.
pip install requests
python3 rystic-scripts/github-pulls/bots/test_bot.py
# -> Ran 2 tests in 33.3s
# -> OK
  1. With no variables, it boots the kalshi-twin that rystic pull installed. KALSHI_BASE_URL=http://localhost:$PORT uses a simulator that’s already running; KALSHI_TWIN_BIN=./kalshi-twin boots that binary.
  2. It loads the tight_book scenario before each bot.

Run the bot on its own against the Kalshi simulator from above, reset to tight_book:

curl -X POST localhost:$PORT/_rystic/scenario \
  -H 'content-type: application/json' -d '{"name":"tight_book"}'
KALSHI_BASE_URL=http://localhost:$PORT SESSION_SECONDS=5 python3 rystic-scripts/github-pulls/bots/bot.py
# -> rest bid 2@0.38 …
# -> rest ask 2@0.41 …
# -> flat, exiting
rystic stop kalshi

Example stacks

environments/ holds four stack files, each with the docker-compose.yaml that rystic export compose writes from it: Multi-simulator environments → Example stacks lists them and how to run one.

Last updated on