No description
  • HTML 53.7%
  • Python 43.4%
  • Shell 2.6%
  • PowerShell 0.3%
Find a file
Mark Johnston 7d612aa0d0 deploy.ps1: call Windows bsdtar by path; log the goal-odds restart bug
tar resolved to C:\ATMEL_PLS_Tools\ProChip\bin\tar.exe from PATH, which will not
run here and stopped the deploy before anything was copied.
2026-11-27 14:59:07 -05:00
deploy deploy.ps1: call Windows bsdtar by path; log the goal-odds restart bug 2026-11-27 14:59:07 -05:00
docs deploy.ps1: call Windows bsdtar by path; log the goal-odds restart bug 2026-11-27 14:59:07 -05:00
ledger Keep the ledger sqlite snapshots out of git 2026-11-27 04:00:21 -05:00
pi Import Kalshi desk monitor as deployed on mark-intel 2026-09-23 08:49:06 -05:00
web Goal card: keep the odds and their bands across a restart 2026-11-27 14:47:18 -05:00
.gitattributes Project scaffolding: docs (architecture, deploy, incidents), deploy script, LF attributes 2026-11-27 03:59:40 -05:00
.gitignore Keep the ledger sqlite snapshots out of git 2026-11-27 04:00:21 -05:00
fleet_sim.py Import the live dashboard state from mark-intel (2026-11-27) 2026-11-27 03:59:04 -05:00
flow.py Import the live dashboard state from mark-intel (2026-11-27) 2026-11-27 03:59:04 -05:00
kalshi-monitor.service Import Kalshi desk monitor as deployed on mark-intel 2026-09-23 08:49:06 -05:00
preview_server.py Import the live dashboard state from mark-intel (2026-11-27) 2026-11-27 03:59:04 -05:00
README.md README: point to the new project docs and deploy flow 2026-11-27 04:00:11 -05:00
requirements.txt Import Kalshi desk monitor as deployed on mark-intel 2026-09-23 08:49:06 -05:00
server.py Goal card: keep the odds and their bands across a restart 2026-11-27 14:47:18 -05:00
sim_worker.py Import the live dashboard state from mark-intel (2026-11-27) 2026-11-27 03:59:04 -05:00
tests_watch.py Import the live dashboard state from mark-intel (2026-11-27) 2026-11-27 03:59:04 -05:00

Kalshi desk monitor

A read-only live view of the 18-bot 15-minute Kalshi desk: nine crypto coins, WTI, natural gas, gold, silver, copper, palladium, platinum, EUR/USD and the Coin Race. server.py polls the Kalshi API and serves one JSON state at /api/state, plus the page in web/. The page is a single HTML file (no build step, no framework) laid out for a 480x800 portrait touch screen; it works in any browser.

Run

pip install -r requirements.txt
python3 server.py        # -> http://127.0.0.1:8765

Credentials are in env and kalshi.pem in this folder (read first; ~/.config/kalshi-monitor/env is the fallback). Set MONITOR_HOST=0.0.0.0 to open it from other machines. The page has no login: anyone who can reach the port sees the balance and positions. On a public server, keep it on 127.0.0.1 and put it behind a reverse proxy with authentication (or a VPN / SSH tunnel).

What counts as the desk

Only orders the bots tagged with a client_order_id (uuid5 of <ticker>:<kind>) on the desk's series: the nine crypto 15-minute bots, WTI, natgas, gold, silver, copper, palladium, platinum, EUR/USD, GBP/USD, USD/CAD, USD/JPY and the S&P 500 (KXINX15M), plus two hourly ladders: BTC hourly (KXBTCD, the twin bot's cascade legs) and gold hourly (KXGOLDH, gold's ladder leg). The order kind says which rule placed a bet: early_hz_N / late_hz_N = the early / late legs, ladder_hz_N = gold's hourly ladder, the twin's taker orders on KXBTCD = the cascade from 2026-11-17 22:38:39 UTC (its earlier rule before), anything else = the bot's original rule. On the hourly ladders only orders a bot named count (hand trades share those markets). Coin Race (KXCRYPTOLEAD15M) was removed by the owner on 2026-11-18; its bets stay in the history. The account also runs other strategies, some on the same markets, and those are excluded from every desk figure. Each bet's cost comes from its own orders' fill cost; its outcome comes from the market's settlement result; time left is measured to its own market's close (15 minutes, or the hour on the ladders). The account total and per-shard cash cover everything on the account.

The legs (since 2026-11-18)

Every bot's original rule is off (desk_entries: off since Nov 4-5); only the legs trade. Everything about them comes from the desk host's desk-status.sh report, never from constants here: each leg section of each bot config (early_hz, late_hz, ladder_hz, and the twin's l1_* / l6_* cascade levels), its kill file, the bot's and the desk's STOP files, the leg's own state file (paused by its loss rule) and the desk's BOT_MODE (it overrides each config's own mode, so a config saying "paper" or "shadow" still trades live). The Desk tiles and the radar judge each bot against the leg whose window is open (else the next one this quarter): its z threshold (time-of-day tables included), z cap, price band and skips / blackouts; not modelled are px30 (the price a minute earlier), VIX-stepped z and the legs' model gates, so a "Ready" here is close to, not identical with, the bot's decision. Prices: Coinbase (crypto), Hyperliquid xyz (WTI, natgas, metals, EUR, GBP, S&P 500, JPY) with Ostium preferred where it is open; USD/CAD has no free candle history, so its tile shows the leg windows without a z. The hourly ladders show their windows this hour, not a z. Setup, goal odds and leg sizes list every leg kind; a paused or stopped leg is shown as such and left out of the odds.

League tab

The League tab ranks every series by live edge: the posterior estimate and 90% range, P(edge>0), P(edge>backtest reference), 7d/30d P&L, the live base stake and the current stop state. Click a row for the live rule, stop file, loss-stop math and recent bets.

Each row has a 0× / ½× / 1× / 1½× / 2× control. The what-if tiles, cumulative P&L chart and top contributors update from the settled bet tape. The presets cut or halve every series below a P(edge>ref) threshold; Live set just switches stopped series off. The simulation scales each settled bet linearly by the multiplier and does not model fills, capacity, the $500 order cap, compounding or open bets; selecting cuts on the same sample that produced the edge estimate is in-sample, so treat it as a decision aid, not a forward test.

The live rule, stake and stop data come from the read-only desk-status.sh forced command on the desk host. If that command is stale or missing, the tab falls back to the dashboard's own rule constants and shows a banner.

Weather tab

The owner stopped and disabled wx-bot on 2026-11-18; the Desk strip hides while its unit is not active and the tab shows the last state the host reported.

The Weather tab is a read-only view of the separate wx-bot maker service on the desk host. It shows the nine KXHIGH* city books: the latest METAR observation, running and guarded daily max, forecast mu/sigma/nu, resting NO orders, model P(YES) per strike, edge at the 95c bid, the payoff if the max lands in each temperature bucket, and the one-bucket risk case. Clicking a city opens the strike ladder and forecast detail.

/api/wx comes from the same desk-status.sh forced command as the League data. The script reads /opt/wx_bot/state/{status,live_orders,markets,forecast,metar,settled} and the tail of the decisions log; those files are world-readable, so no new key or sudo rule is needed. HostWatch caches the block and /api/state carries only a small summary, keeping the 2-second poll light.

The weather book has its own strip on the Desk tab and a health card on Status. Its P&L and at-risk dollars are shown alongside the account total; because the account total drives the main goal, weather results are included there. The separate desk-only goal shown in League remains desk-only. The cap basis sums every resting leg (the bot's own $2,000 budget), while the one-bucket worst case uses the disjoint temperature buckets: at most one leg per city loses, so the other legs' $5 wins offset part of the loss.

API budget

No calls in minutes 4:00-8:00 of each quarter hour (the desk's entry window). Figures freeze then and refresh right after. On first start it pages through every order since Sep 15 (about 15 calls); after that it fetches incrementally.

Pi kiosk (optional)

pi/kiosk.sh opens the page full-screen in Chromium with its own profile. The Status tab's "Exit kiosk" button (tap twice) closes that Chromium; the endpoint does nothing elsewhere.

Simulations on the dstack fleet, and leg sizes

The goal-odds simulations do not run on this box. fleet_sim.py submits one short dstack task (km-sim) to the first idle machine in KM_FLEET_FLEETS (default spark,ms7a40); the task runs sim_worker.py (numpy, multi-threaded) at 200,000 paths (FLEET_PATHS) and prints the result, which the monitor reads back from the task log. The run is deleted afterwards; dstack ps -a still lists these past runs, plain dstack ps does not. If no fleet machine is idle, or the job fails or takes longer than KM_FLEET_TIMEOUT (240 s), the same job runs here in plain Python at 500 paths (LOCAL_PATHS). goal_odds.engine says which ran (where, host, secs, wait, or fleet_error). KM_FLEET=0 in env turns fleet runs off. The dstack token is read from ~/.dstack/config.yml; numpy is installed once per fleet machine under /var/tmp/km-sim-cache.

Which legs (Analytics.live_legs): the legs live on the desk now, read from the desk host's report (the same desk-status.sh the League tab uses): every bot's config file, its legs block in mode live, minus legs a stop file halts (the leg's kill file STOP_<series>EARLY / LATE, the bot's STOP_<series>, the desk's STOP). Original rules are paper on every bot and are never simulated. The leg's size is its config bet_fraction and its cap max_stake_usd. If the desk host has not reported for an hour the run fails and the last odds stay up; bet history never stands in for the desk's settings. goal_odds.excluded lists the legs left out and why.

Each leg's record (sim_model): its own settled bets since Nov 4 19:38 UTC. The bots name every order uuid5(ORDER_NS, "<ticker>:<kind>"), so the monitor reads which rule placed it (early_hz_N early leg, late_hz_N late leg, taker / maker / top-ups the original rule) and keeps an early and a late bet in the same market as two bets. Only bets inside the leg's live window and price band count (z cannot be checked, so older bets of an earlier rule on the same leg count when they fall inside). From them: losses, win and loss per dollar, and the bet count on each whole day since Nov 5; days before the leg's first bet borrow one of its own whole days, and a leg with under two whole days uses its bets since its first one over at least a day (new on the card). A live leg with no bet inside its rule yet is listed but not simulated. Loss rates: each path draws one per kind of leg (early / late, crypto / other) from the record, then each leg's own, pulled toward its kind as far as its own record cannot tell it apart (kappa_of: beta-binomial, method of moments).

USD/CAD (EXTRA_SERIES) is tracked for the simulation only: its orders and results are kept (desk_bets(every=True)), the other screens still show the 19 series in SERIES.

Leg sizes (Performance > Bets & settings > Leg sizes): a size box per live leg (desk = its config stake). Run simulations posts the changed sizes to /api/sim/run; they are saved in data/sim_sizes.json and every simulation runs again at once: cur at the desk's sizes and custom at the saved sizes, both on the same simulated bets (the worker draws the losses once), so the difference between them is not sampling noise. The Goal card's MY SIZES view shows custom. Saved sizes are used by every 30-minute pass until Sizes as traded clears them; 0 switches a leg off. A simulated bet stakes the size up to the leg's dollar cap; amber "bets x%" on the card = what its last bets actually staked when that is far from the config (thin books fill less). /api/sim reports a run in progress. One run at a time.

More variations: each is one more entry in scenarios in Analytics.simulate (a name plus a win and a loss per leg).

History window (Goal card HISTORY switch, 2026-11-18)

SINCE LEGS (default) / 14 D / 7 D / ALL sets where each leg's record and the sampled days start; the choice is saved with the leg sizes (data/sim_sizes.json, key since) and every later run uses it. ALL also adds the original-rule bets (Sep 15 on) that fit a live leg's window and price band to that leg's record; those were picked by the original rule's z (1.5, not the leg's 2-5), so it is a harsher record, not the legs' own history, and the sampled days still start with the legs (Nov 5). A leg with fewer than 30 settled bets of its own in the window (SIM_MIN_LEG_BETS), a leg with no other legs of its kind to pool with (on Nov 18 the gold hourly ladder and the BTC cascade), and every leg of a kind with fewer than 30 settled bets (SIM_MIN_KIND_BETS), is simulated on its own realized record: loss rate = its losses / bets, no prior, no pooling (owner Nov 18: "they should pull from the realized data, not the assumptions"). The worker is unchanged: such a leg gets its own group, scaled by REALIZED_SCALE with kappa REALIZED_KAPPA, which pins its drawn rate to losses / bets. A record with no loss therefore never loses in the simulation until a real loss arrives. POOL_KIND (empty) could pool a kind with another instead.

Liquidity > Flow card (order-flow segments)

Kalshi's public trades carry no account, so the card splits taker flow by behaviour and by who wins, not by who trades. flow.py holds the logic; FlowWatch in server.py feeds it.

  • Feed: its own websocket on the trade channel (FlowWS), for the nine crypto series in FLOW_SERIES. The next quarter's markets are subscribed by name from second 820, so each market is recorded from its open. A market that was already trading when the socket (re)connected, or during a websocket error, is marked partial and never saved.
  • Orders: prints sharing (ticker, ts_ms, taker side). The coin's 2-s move before each order comes from the monitor's Coinbase ticks (FLOW_PRICES, last price per second, 10 min kept).
  • Segments (first match wins): large follower (>= $1k, bought the way a top-decile 2-s move went, decile over the last 7 days per coin, histograms saved to data/flow_moves.json every 10 min so a restart keeps them), small repeated odd (< $100, a non-round size seen >= 5 times in the market on its side), fade, small round, large other, everything else.
  • Settling: after the close the result comes from the monitor's own record or one keyless GET /markets/{ticker} (never in the quiet window, <= 12 a pass); each market becomes one row in data/flow_markets.jsonl (segment $, contracts, P&L, fee, orders; and the same inside the desk zone, 60-600 s left and 80-99c). 90 days are kept in memory.
  • /api/flow: the last 30 days per coin and pooled (cached 5 min), the study's monthly history from data/flow_history.json (built by results/flow_mix_1116/scripts/combine.py on the PC), and the tracker's status.
  • Restarts: restart in seconds 828-845 of a quarter, so the next markets are subscribed before they open; the quarter running at the restart is dropped (partial). /api/flow status is live on every call; the summary is cached 5 min.
  • Headline numbers: takers' loss after fees per market (what resting orders and Kalshi collect), and informed takers' share of the desk zone (BTC: large followers; alts: large followers + small repeated odd, the segments that earned in the study). The desk's own orders land in 'everything else', so these are not retail labels.

Watch API (Zepp OS)

/api/watch (also /api/v1/watch, which the existing no-password /api/v1/* Caddy route already reaches) is a compact read-only glance for the Zepp OS app: account, today, goal pace, every series' live rule state, open positions, stops and alerts. It uses WATCH_TOKEN from env, not the assistant token, and is rate-limited to 30 requests a minute. Public URL: https://kalshi.ulatec-home.duckdns.org/api/v1/watch.

curl -s -H "Authorization: Bearer $WATCH_TOKEN" https://kalshi.ulatec-home.duckdns.org/api/v1/watch

Nothing in this endpoint can place or change orders.

Project layout and development

This is the dashboard's own project. It was migrated here on 2026-11-27 from Desktop\kalshi-monitor, which stays untouched as the archive of the earlier history.

  • docs/ARCHITECTURE.md - how server.py, the single-page UI and the analytics/simulations fit together.
  • docs/DEPLOY.md - access to mark-intel, how to publish a change, rollback, host quirks.
  • docs/INCIDENTS.md - what broke and why (most recent first).
  • Local preview: python preview_server.py -> http://127.0.0.1:8766/ (serves the real page against data/preview/; capture fresh payloads from the host when the API changes).
  • Publish: deploy/deploy.ps1 (dry run) then deploy/deploy.ps1 -Go [-Restart].