Skip to the content
AI Test AutomationPreview AI Security Learning Center

AI Test AutomationCapital markets AI testingTrading lab

Capital markets AI testing Preview

Trading lab: test a brokerage by breaking it

A small trading and stock plan product you can use, a suite that checks every rule it follows against the page the rule comes from, and switches that break it the way fintech products really break.

The product

Kitestring: trading, investing and stock plans, in one account

Order ticket with trailing stops, on-close orders, IOC, FOK and good till date, cancel and change on the wire, T+1 settlement, buying power, the day-trading rules in force on the date, and an employee stock plan. Trade Kitestring or ten popular real tickers, started at their actual Oct 26, 2026 closes; move prices by hand, or replay IEX market data (the bundled sample, or a small real slice you load) and watch each order go out as FIX 4.4. Everything runs in your browser. The feed itself is in the market data lab.

KitestringFictional demo, simulated prices

    Moves the selected stock up and down on its own. Place an order while it runs.
    Prices: simulated, by hand

    Estimated
    Buying power

    Open orders

    OrderSideTypeSharesLimitStopTIF

    Done today filled, cancelled or expired; a cancel for one of these is too late

      FIX 4.4 on the wire newest first; | stands for the SOH byte; click a message to read its fields, or check any of them in the FIX workbench
      OUT client to broker IN broker to client ACK accepted or filled NACK rejected
      Orders: 35=D, F and G out; 35=8 and 9 back
      1. Orders you place and their execution reports appear here.
      Market data: 35=X from the feed
      1. Trades from the IEX feed appear here while it plays.

      Tests and defects

      The suite, and seventeen defects to catch with it

      Each test is tied to a rule and the page it comes from. The same tests run in Node in CI and here, against the engine the product runs on. Running them resets the demo account.

      Every test grouped by area, each with its source

      Break it

      Each switch breaks one rule in the engine: a stop that fills at the stop on a gap looks fine until the price gaps. Turn some on, use the product, then run the suite, or let the mutation run turn each on alone and report which tests caught it. A defect no test catches is a gap in the suite.

      Rules and risk

      What a QA owner of a trading product has to know

      The pattern day trader rule is going away; for 16 months both rules are live

      The SEC approved FINRA's rule change on April 14, 2026. It replaces the day trading margin requirements, including the pattern day trader test (four or more day trades within five business days, over six percent of the margin account's trades) and its $25,000 minimum, with an intraday margin standard. The amendments took effect on June 4, 2026; firms that need more time may phase in until October 20, 2027.

      • Two code paths in production. The firm's switch-over date is configuration, and configuration goes untested. The suite pins the dates: the day before, the effective date, the firm's own date, and the deadline that overrides it.
      • Business days, not calendar days. Thursday, Friday, Monday and Tuesday are four day trades in five business days; counted in calendar days Thursday drops out and the customer is never flagged. One switch above breaks it and one test catches it.
      • What the customer sees. A restriction lifted on the switch-over date, a banner still quoting $25,000 after it. Try the Margin account in the product and move the firm's date on the Portfolio tab.

      FINRA: new intraday margin standards adopted (SEC approval, April 14, 2026) · FINRA Regulatory Notice 26-10: intraday margin standards replace day trading margin requirements · investor.gov glossary: pattern day trader, and the 2026 change. The intraday computation itself is beyond this demo; the dates and the switch are not.

      Where the risk is, area by area, and the test for each
      AreaWhat breaks, and who noticesThe test, and its layer
      Order rulesA stop fills at the wrong price on a gap; a limit fills through its limit. The customer notices first.Rule tests on the engine for every order type and price path (cross, gap, recover); a contract test on the order API.
      MoneyA cent lost in floating point, rounding applied per lot instead of once. Reconciliation finds it weeks later.Integer cents end to end, exact-value tests, property tests on sums and splits.
      Settlement and buying powerProceeds spendable a day early, or a day late after a holiday.Date tests across weekends and the exchange holiday calendar.
      Regulatory datesA rule switched on early, or never switched off. Found in an exam.Configuration tests with the dates written down: before, on, after, and the deadline.
      Cancel and changeA cancel that "succeeds" on an order that already filled; a change that skips the buying power check; a trailing stop that follows the price down and never fires. The customer finds out from the statement.Lifecycle tests per message: 35=F and 35=G accepted or rejected with 35=9 and the right CxlRejReason, buying power after every change, and the trail on a rising, a falling and a gapping price.
      Order entryA double click sends two orders; a retry after a timeout sends two more.An idempotency key per ticket, tested at the API and by double-clicking in the browser.
      Market dataA price read with the wrong scale, a gap nobody noticed, a crossed quote in the book. Orders fill at wrong prices.Decoder tests against the spec's byte layouts, sequence checks, a replayed slice of real data.
      Stock planA cliff a month late, withholding at the wrong rate above $1 million. Employees notice on vest day, all at once.Schedule tests from the grant terms, withholding tests on the threshold, end-to-end tests on the statement.
      The openQueued orders, quotes and logins all at 9:30, the busiest minute of the day.A load profile shaped like the open, with latency percentiles as the gate.

      SEC investor bulletin: stop, stop-limit and trailing stop orders · SEC investor bulletin: the new T+1 settlement cycle · IRS Publication 15 (2026): supplemental wages, 22 and 37 percent · FIX 4.4 TimeInForce (59): Day, GTC, IOC, FOK, Good Till Date, At the Close · FIX 4.4 Order Cancel Request (F) · FIX 4.4 Order Cancel/Replace Request (G) · FIX 4.4 Order Cancel Reject (9) · FIX 4.4 CxlRejReason (102): 0 is too late to cancel · FIX 4.4 ExecType (150): 4 Canceled, 5 Replace · FIX 4.4 ExecInst (18): a is Trailing Stop Peg. The house rules (whole shares for limit and stop orders, no buying with unsettled proceeds, no short selling) are this demo broker's own policies, as every broker has its own.

      Real runs

      Node, the mutation run, and Playwright driving this page

      Recorded on 2026-10-29; the transcripts are unedited and in the repository beside the engine and the tests.

      node run.js --mutate

      CAUGHT  stop-at-stop        1 test(s): stop-gap
              first failure: fill price: expected "$37.50", got "$40.00"
      CAUGHT  limit-at-market     8 test(s): limit-rests-then-fills, day-expires, gtd-through-its-date, ioc-cancels-the-rest, cancel-open, change-limit, change-checks-power, change-frees-cash
              first failure: status while the market is at $42.10: expected "open", got "filled"
      CAUGHT  closed-market-fills 1 test(s): closed-waits
              first failure: status after the close: expected "open", got "filled"
      CAUGHT  double-submit       1 test(s): idempotent
              first failure: orders: expected 1, got 2
      CAUGHT  settle-t2           3 test(s): t1-monday, t1-friday, unsettled-not-spendable
              first failure: settlement date: expected "2026-10-27", got "2026-10-28"
      CAUGHT  unsettled-power     1 test(s): unsettled-not-spendable
              first failure: buying power on the trade date: expected "$790.00", got "$5,000.00"
      CAUGHT  float-money         3 test(s): cents-exact, cents-sum, fraction-rounding
              first failure: cost: expected "$1,020.00", got "$1,019.99"
      CAUGHT  pdt-calendar        1 test(s): pdt-business-days
              first failure: pattern day trader: expected true, got false
      CAUGHT  phase-in            1 test(s): phase-in-deadline
              first failure: the day after: expected "intraday-margin", got "pattern-day-trader"
      CAUGHT  cliff-late          3 test(s): rsu-cliff, rsu-before-cliff, month-end
              first failure: first vest date: expected "2026-11-15", got "2026-12-15"
      CAUGHT  flat-22             1 test(s): withholding-37
              first failure: $200,000 vest after $900,000 earlier in the year: expected "$59,000.00", got "$44,000.00"
      CAUGHT  trail-ratchets-down 2 test(s): trail-follows, trail-holds-on-a-fall
              first failure: stop after a dip to $43.50: expected "$43.00", got "$42.50"
      CAUGHT  moc-fills-now       2 test(s): moc-at-the-close, loc-within-limit
              first failure: status at 10:00: expected "open", got "filled"
      CAUGHT  gtd-early           1 test(s): gtd-through-its-date
              first failure: status on its good-till date: expected "open", got "expired"
      CAUGHT  ioc-rests           1 test(s): ioc-cancels-the-rest
              first failure: status: expected "cancelled", got "open"
      CAUGHT  cancel-filled       1 test(s): cancel-too-late
              first failure: cancel accepted: expected false, got true
      CAUGHT  replace-skips-power 1 test(s): change-checks-power
              first failure: change accepted: expected false, got true
      CAUGHT  price-scale         4 test(s): fix-md, iex-quote, iex-sample, iex-crossed
              first failure: bid price: expected "42.10", got "4210.00"
      CAUGHT  big-endian          1 test(s): iex-quote
              first failure: bid size: expected 600, got 1476526080
      CAUGHT  ignore-gaps         1 test(s): iex-gap
              first failure: gaps: expected 1, got 0
      CAUGHT  accept-crossed      1 test(s): iex-crossed
              first failure: bid in the book: expected 4210, got 4215
      CAUGHT  checksum-skips-soh  1 test(s): fix-checksum
              first failure: CheckSum: expected "135", got "128"
      CAUGHT  seq-reuse           2 test(s): fix-gap, fix-gap-fill
              first failure: MsgSeqNum of the resent message: expected "2", got "4"
      CAUGHT  gapfill-short       2 test(s): fix-gap-fill, lint-log-recovered
              first failure: NewSeqNo: expected "4", got "3"
      CAUGHT  delta-stale-base    1 test(s): fast-roundtrip
              first failure: message 18 (Quote) field Time: sent 1793021398020230498, decoded 1793021398028100334
      CAUGHT  stopbit-reversed    3 test(s): fast-uint, fast-int, fast-roundtrip
              first failure: mandatory 942755: expected "39 45 a3", got "23 45 b9"
      
      26 of 26 injected defects caught
      exit 0

      pytest e2e (Playwright, Chromium)

      ============================= test session starts ==============================
      platform linux -- Python 3.13.18, pytest-9.1.1, pluggy-1.6.0 -- /usr/local/bin/python3
      rootdir: /home/claude/repo
      configfile: pyproject.toml
      plugins: platformdirs-4.13.0, anyio-4.15.1, playwright-0.10.0
      collecting ... collected 31 items
      
      data/testlab/trading/e2e/test_trading_lab.py::test_review_then_place_a_limit_order_that_fills_on_a_dip[chromium] PASSED [  3%]
      data/testlab/trading/e2e/test_trading_lab.py::test_a_stop_on_a_gap_fills_at_the_next_price[chromium] PASSED [  6%]
      data/testlab/trading/e2e/test_trading_lab.py::test_double_click_sends_one_order[chromium] PASSED [  9%]
      data/testlab/trading/e2e/test_trading_lab.py::test_fractional_limit_is_refused_with_a_reason[chromium] PASSED [ 12%]
      data/testlab/trading/e2e/test_trading_lab.py::test_sale_proceeds_settle_next_business_day[chromium] PASSED [ 16%]
      data/testlab/trading/e2e/test_trading_lab.py::test_stock_plan_shows_the_cliff_and_sell_to_cover[chromium] PASSED [ 19%]
      data/testlab/trading/e2e/test_trading_lab.py::test_the_suite_passes_on_the_product_as_shipped[chromium] PASSED [ 22%]
      data/testlab/trading/e2e/test_trading_lab.py::test_an_injected_defect_turns_the_suite_red[chromium] PASSED [ 25%]
      data/testlab/trading/e2e/test_trading_lab.py::test_mutation_run_catches_every_defect[chromium] PASSED [ 29%]
      data/testlab/trading/e2e/test_trading_lab.py::test_feed_replay_drives_the_product_and_orders_go_out_as_fix[chromium] PASSED [ 32%]
      data/testlab/trading/e2e/test_trading_lab.py::test_simulation_moves_the_price_and_fills_a_waiting_limit_order[chromium] PASSED [ 35%]
      data/testlab/trading/e2e/test_trading_lab.py::test_max_quantity_range_alert_and_profit[chromium] PASSED [ 38%]
      data/testlab/trading/e2e/test_trading_lab.py::test_clicking_a_fix_message_reads_it_field_by_field[chromium] PASSED [ 41%]
      data/testlab/trading/e2e/test_trading_lab.py::test_messages_are_marked_in_or_out_and_ack_or_nack[chromium] PASSED [ 45%]
      data/testlab/trading/e2e/test_trading_lab.py::test_heartbeats_are_hidden_until_you_toggle_them[chromium] PASSED [ 48%]
      data/testlab/trading/e2e/test_trading_lab.py::test_a_popular_ticker_trades_at_its_price[chromium] PASSED [ 51%]
      data/testlab/trading/e2e/test_trading_lab.py::test_a_popular_ticker_can_be_added_and_any_other_is_refused[chromium] PASSED [ 54%]
      data/testlab/trading/e2e/test_trading_lab.py::test_the_cutoff_keeps_only_the_symbols_and_minutes_asked_for[chromium] PASSED [ 58%]
      data/testlab/trading/e2e/test_trading_lab.py::test_orders_and_the_slice_can_be_downloaded[chromium] PASSED [ 61%]
      data/testlab/trading/e2e/test_trading_lab.py::test_a_trailing_stop_follows_the_price_up_and_can_be_changed[chromium] PASSED [ 64%]
      data/testlab/trading/e2e/test_trading_lab.py::test_a_cancel_after_the_fill_comes_back_as_too_late[chromium] PASSED [ 67%]
      data/testlab/trading/e2e/test_trading_lab.py::test_a_market_on_close_order_fills_at_the_close[chromium] PASSED [ 70%]
      data/testlab/trading/e2e/test_trading_lab.py::test_market_data_suite_and_mutation_run[chromium] PASSED [ 74%]
      data/testlab/trading/e2e/test_trading_lab.py::test_a_lost_segment_is_a_gap_with_a_gap_fill_request[chromium] PASSED [ 77%]
      data/testlab/trading/e2e/test_trading_lab.py::test_the_inspector_names_every_byte[chromium] PASSED [ 80%]
      data/testlab/trading/e2e/test_trading_lab.py::test_harness_tool_fanout_reacts_to_the_fleet[chromium] PASSED [ 83%]
      data/testlab/trading/e2e/test_trading_lab.py::test_harness_tool_hook_fails_open_then_holds[chromium] PASSED [ 87%]
      data/testlab/trading/e2e/test_trading_lab.py::test_harness_tool_rules_and_session_gate[chromium] PASSED [ 90%]
      data/testlab/trading/e2e/test_trading_lab.py::test_workbench_finds_what_is_wrong_and_mends_the_frame[chromium] PASSED [ 93%]
      data/testlab/trading/e2e/test_trading_lab.py::test_workbench_reads_a_session_and_its_recovery[chromium] PASSED [ 96%]
      data/testlab/trading/e2e/test_trading_lab.py::test_workbench_intercept_drop_then_recover[chromium] PASSED [100%]
      
      ============================= 31 passed in 36.12s ==============================
      exit 0
      The end-to-end tests, and the full node run

      The end-to-end tests

      e2e/test_trading_lab.py
      """End-to-end tests for the trading lab page: Playwright drives the product as a customer would.
      
          python -m http.server 8765 --directory site     # in one terminal
          pytest data/testlab/trading/e2e -q               # in another; LAB_URL overrides the address
      """
      import os
      from pathlib import Path
      
      import pytest
      from playwright.sync_api import Page, expect
      
      URL = os.environ.get("LAB_URL", "http://localhost:8765/test-automation/trading-lab/")
      
      
      @pytest.fixture
      def lab(page: Page) -> Page:
          page.goto(URL)
          expect(page.get_by_test_id("price")).to_have_text("$42.10")
          return page
      
      
      def use_source(page: Page, which: str):
          page.get_by_test_id("tab-data").click()
          page.get_by_test_id(f"src-{which}").check(force=True)
          page.get_by_role("tab", name="Trade").click()
      
      
      def ticket(page: Page, *, side="buy", type="market", qty="10", limit=None, stop=None):
          t = page.get_by_test_id("ticket")
          t.locator(".kx-seg label", has_text=side.capitalize()).click()  # the label is the control a person clicks
          page.get_by_test_id("type").select_option(type)
          page.get_by_test_id("qty").fill(qty)
          if limit:
              page.get_by_test_id("limit").fill(limit)
          if stop:
              page.get_by_test_id("stop").fill(stop)
          page.get_by_test_id("review-btn").click()
      
      
      def test_review_then_place_a_limit_order_that_fills_on_a_dip(lab: Page):
          ticket(lab, type="limit", qty="10", limit="41.00")
          expect(lab.get_by_test_id("review")).to_contain_text("Estimated cost: $410.00")
          lab.get_by_test_id("place").click()
          expect(lab.get_by_test_id("open-orders")).to_contain_text("O0001 KITE")
          lab.get_by_label("New price in dollars").fill("40.95")
          lab.get_by_role("button", name="Set", exact=True).click()
          expect(lab.get_by_test_id("open-orders")).to_contain_text("No open orders")
          lab.get_by_role("tab", name="Activity").click()
          expect(lab.get_by_test_id("activity")).to_contain_text("$40.95")
      
      
      def test_a_stop_on_a_gap_fills_at_the_next_price(lab: Page):
          ticket(lab, qty="10")
          lab.get_by_test_id("place").click()
          ticket(lab, side="sell", type="stop", qty="10", stop="40.00")
          lab.get_by_test_id("place").click()
          lab.get_by_test_id("gap-down").click()  # $42.10 -> $37.89
          lab.get_by_role("tab", name="Activity").click()
          expect(lab.get_by_test_id("activity")).to_contain_text("$37.89")
      
      
      def test_double_click_sends_one_order(lab: Page):
          ticket(lab, qty="1")
          lab.get_by_test_id("place").dblclick()
          lab.get_by_role("tab", name="Activity").click()
          expect(lab.get_by_test_id("activity").locator("tbody tr")).to_have_count(1)
      
      
      def test_fractional_limit_is_refused_with_a_reason(lab: Page):
          ticket(lab, type="limit", qty="0.5", limit="40")
          expect(lab.get_by_test_id("error")).to_have_text("Fractional shares are for market orders only.")
          expect(lab.get_by_test_id("place")).to_be_hidden()
      
      
      def test_sale_proceeds_settle_next_business_day(lab: Page):
          ticket(lab, qty="10")
          lab.get_by_test_id("place").click()
          ticket(lab, side="sell", qty="10")
          lab.get_by_test_id("place").click()
          lab.get_by_role("tab", name="Portfolio").click()
          expect(lab.get_by_test_id("unsettled")).to_contain_text("$421.00 (settles Oct 27)")
          lab.get_by_test_id("next-day").click()
          expect(lab.get_by_test_id("unsettled")).to_have_text("$0.00")
      
      
      def test_stock_plan_shows_the_cliff_and_sell_to_cover(lab: Page):
          lab.get_by_role("tab", name="Stock plan").click()
          expect(lab.get_by_test_id("rsu")).to_contain_text("Nov 15, 2026: 1,200 units")
          expect(lab.get_by_test_id("sell-to-cover")).to_contain_text("$11,114.40")
      
      
      def test_the_suite_passes_on_the_product_as_shipped(lab: Page):
          lab.get_by_test_id("run-suite").click()
          expect(lab.get_by_test_id("summary")).to_contain_text("53 passed, 0 failed")
      
      
      def test_an_injected_defect_turns_the_suite_red(lab: Page):
          lab.get_by_test_id("defect-double-submit").check()
          lab.get_by_test_id("run-suite").click()
          expect(lab.get_by_test_id("summary")).to_contain_text("51 passed, 2 failed")
          expect(lab.locator('[data-test="ui-double-click"]')).to_contain_text("FAIL")
      
      
      def test_mutation_run_catches_every_defect(lab: Page):
          lab.get_by_test_id("mutate").click()
          expect(lab.get_by_test_id("mutation-summary")).to_have_text("17 of 17 injected defects caught")
      
      
      def test_feed_replay_drives_the_product_and_orders_go_out_as_fix(lab: Page):
          use_source(lab, "iex")
          expect(lab.get_by_test_id("feed-clock")).to_contain_text("09:29:58")
          ticket(lab, qty="5")  # before the open: it waits for 09:30
          lab.get_by_test_id("place").click()
          lab.get_by_test_id("speed").select_option("60")
          lab.get_by_test_id("play").click()
          expect(lab.get_by_test_id("feed-clock")).to_contain_text("end of the slice", timeout=15000)
          wire = lab.get_by_test_id("wire")
          expect(wire).to_contain_text("35=D|49=CLIENT|56=KITESTRING")
          expect(wire).to_contain_text("150=F|39=2|55=KITE")
          expect(lab.get_by_test_id("wire-md")).to_contain_text("35=X")
          expect(lab.get_by_test_id("bbo")).to_contain_text("IEX bid")
      
      
      SAMPLE = Path(__file__).resolve().parents[1] / "feed" / "iex-tops-sample.pcap"
      
      
      def test_simulation_moves_the_price_and_fills_a_waiting_limit_order(lab: Page):
          lab.get_by_role("button", name="MSFT").first.click()
          ticket(lab, type="limit", qty="1", limit="520.00")
          lab.get_by_test_id("place").click()
          lab.get_by_test_id("sim-speed").select_option("200")
          lab.get_by_test_id("simulate").click()
          expect(lab.get_by_test_id("price")).not_to_have_text("$532.60", timeout=5000)
          lab.get_by_test_id("simulate").click()
          expect(lab.get_by_test_id("simulate")).to_have_attribute("aria-pressed", "false")
      
      
      def test_max_quantity_range_alert_and_profit(lab: Page):
          lab.get_by_test_id("qty-max").click()
          expect(lab.get_by_test_id("qty")).to_have_value("593")  # $25,000 of buying power at $42.10
          lab.get_by_test_id("qty").fill("10")
          lab.get_by_test_id("review-btn").click(); lab.get_by_test_id("place").click()
          lab.get_by_label("New price in dollars").fill("44.10")
          lab.get_by_role("button", name="Set", exact=True).click()
          expect(lab.get_by_test_id("range")).to_contain_text("$44.10")
          expect(lab.get_by_test_id("tape")).to_contain_text("$44.10")
          lab.get_by_test_id("alert-px").fill("45")
          lab.get_by_test_id("alert-set").click()
          expect(lab.get_by_test_id("alerts")).to_contain_text("$45.00")
          for _ in range(3):
              lab.get_by_role("button", name="+1%").click()
          expect(lab.get_by_test_id("alerts")).not_to_contain_text("$45.00")  # crossed, so it fired and went away
          lab.get_by_role("tab", name="Portfolio").click()
          expect(lab.get_by_test_id("unrealized")).to_contain_text("+$")
      
      
      def test_clicking_a_fix_message_reads_it_field_by_field(lab: Page):
          ticket(lab, type="limit", qty="3", limit="41.00")
          lab.get_by_test_id("place").click()
          msg = lab.get_by_test_id("wire").locator("li.kx-msg").last  # the order as sent, 35=D
          msg.click()
          fields = msg.get_by_test_id("fix-fields")
          expect(fields).to_contain_text("MsgType")
          expect(fields).to_contain_text("NewOrderSingle")
          expect(fields.locator("tr", has_text="OrdType")).to_contain_text("Limit")
          expect(fields.locator("tr", has_text="Side")).to_contain_text("Buy")
          expect(fields.locator("tr", has_text="CheckSum")).to_contain_text("three digits")
          msg.locator("em").click()
          expect(fields).to_be_hidden()
      
      
      def test_messages_are_marked_in_or_out_and_ack_or_nack(lab: Page):
          ticket(lab, qty="3")
          lab.get_by_test_id("place").click()
          wire = lab.get_by_test_id("wire")
          expect(wire.locator("li", has_text="NewOrderSingle").locator(".kx-dir")).to_have_text("OUT")
          report = wire.locator("li", has_text="ExecutionReport")
          expect(report.locator(".kx-dir")).to_have_text("IN")
          expect(report.locator(".kx-ack")).to_have_text("ACK")
          # an order the broker refuses: send it anyway and read the NACK
          lab.get_by_label("Shares").fill("0.5")
          lab.get_by_test_id("type").select_option("limit")
          lab.get_by_test_id("limit").fill("40")
          lab.get_by_test_id("review-btn").click()
          lab.get_by_test_id("send-anyway").click()
          nack = wire.locator("li", has_text="rejected").first
          expect(nack.locator(".kx-nack")).to_have_text("NACK")
          nack.click()
          expect(nack.get_by_test_id("fix-fields").locator("tr", has_text="OrdStatus")).to_contain_text("Rejected")
      
      
      def test_heartbeats_are_hidden_until_you_toggle_them(lab: Page):
          lab.get_by_test_id("hb-interval").select_option("5")
          hb = lab.get_by_test_id("wire").locator("li.kx-hb")
          lab.wait_for_timeout(6500)
          assert hb.count() >= 2
          expect(hb.first).to_be_hidden()
          lab.get_by_test_id("show-heartbeats").check()
          expect(hb.first).to_be_visible()
          expect(hb.first).to_contain_text("35=0")
          assert {"IN", "OUT"} == {hb.nth(i).locator(".kx-dir").inner_text() for i in range(2)}
      
      
      def test_a_popular_ticker_trades_at_its_price(lab: Page):
          lab.get_by_role("button", name="MSFT").first.click()
          expect(lab.get_by_test_id("price")).to_have_text("$532.60")
          ticket(lab, qty="2")
          lab.get_by_test_id("place").click()
          expect(lab.get_by_test_id("review")).to_be_hidden()
          lab.get_by_role("tab", name="Portfolio").click()
          expect(lab.get_by_test_id("settled")).to_have_text("$23,934.80")
      
      
      def test_a_popular_ticker_can_be_added_and_any_other_is_refused(lab: Page):
          lab.get_by_test_id("add-input").fill("jpm")
          lab.get_by_test_id("add-btn").click()
          expect(lab.get_by_role("button", name="JPM").first).to_be_visible()
          expect(lab.get_by_test_id("price")).not_to_have_text("$42.10")
          lab.get_by_test_id("add-input").fill("QQQ")
          lab.get_by_test_id("add-btn").click()
          expect(lab.locator("#kx-add-err")).to_contain_text("Pick one of")
      
      
      def test_the_cutoff_keeps_only_the_symbols_and_minutes_asked_for(lab: Page):
          lab.get_by_test_id("tab-data").click()
          lab.get_by_test_id("src-file").check(force=True)
          lab.get_by_test_id("file").set_input_files(str(SAMPLE))
          lab.get_by_test_id("cut-symbols").fill("MSFT")
          lab.get_by_test_id("cut-start").fill("09:30:00")
          lab.get_by_test_id("cut-minutes").fill("0.5")
          lab.get_by_test_id("cut-go").click()
          summary = lab.get_by_test_id("cut-summary")
          expect(summary).to_contain_text("MSFT, 09:30:00")
          expect(summary).not_to_contain_text("KITE")
          lab.get_by_test_id("cut-symbols").fill("ZZZZ")
          lab.get_by_test_id("cut-go").click()
          expect(summary).to_contain_text("no quotes or trades")
      
      
      def test_orders_and_the_slice_can_be_downloaded(lab: Page):
          use_source(lab, "iex")
          ticket(lab, qty="3")
          lab.get_by_test_id("place").click()
          lab.get_by_test_id("tab-data").click()
          with lab.expect_download() as d:
              lab.get_by_test_id("dl-orders").click()
          text = Path(d.value.path()).read_text()
          assert d.value.suggested_filename.endswith(".fix") and "35=D" in text and "35=8" in text
          with lab.expect_download() as d:
              lab.get_by_test_id("dl-slice").click()
          csv = Path(d.value.path()).read_text().splitlines()
          assert csv[0].startswith("time_et,type,symbol") and len(csv) > 100
      
      
      def test_a_trailing_stop_follows_the_price_up_and_can_be_changed(lab: Page):
          ticket(lab, qty="10")
          lab.get_by_test_id("place").click()
          lab.get_by_test_id("ticket").locator(".kx-seg label", has_text="Sell").click()
          lab.get_by_test_id("type").select_option("trailing-stop")
          lab.get_by_test_id("review-btn").click()
          expect(lab.get_by_test_id("review")).to_contain_text("starts at $41.10")
          lab.get_by_test_id("place").click()
          lab.get_by_test_id("gap-up").click()  # $42.10 -> $46.31: the stop follows to $45.31
          expect(lab.get_by_test_id("open-orders")).to_contain_text("$45.31")
          lab.locator('[data-change="O0002"]').click()
          lab.get_by_test_id("chg-trail").fill("2")
          lab.get_by_test_id("chg-send").click()
          expect(lab.get_by_test_id("open-orders")).to_contain_text("$44.31")
          expect(lab.get_by_test_id("wire")).to_contain_text("35=G")
          expect(lab.get_by_test_id("wire")).to_contain_text("150=5")
      
      
      def test_a_cancel_after_the_fill_comes_back_as_too_late(lab: Page):
          ticket(lab, qty="1")
          lab.get_by_test_id("place").click()
          lab.get_by_test_id("done").get_by_role("button", name="Try to cancel").click()
          expect(lab.locator("#kx-wire li.kx-msg").first).to_contain_text("35=9")
          expect(lab.locator("#kx-wire li.kx-msg").first).to_contain_text("102=0")
      
      
      def test_a_market_on_close_order_fills_at_the_close(lab: Page):
          lab.get_by_test_id("type").select_option("moc")
          lab.get_by_test_id("qty").fill("5")
          lab.get_by_test_id("review-btn").click()
          lab.get_by_test_id("place").click()
          expect(lab.get_by_test_id("open-orders")).to_contain_text("AT CLOSE")
          lab.get_by_test_id("gap-up").click()
          lab.get_by_test_id("close").click()
          expect(lab.get_by_test_id("open-orders")).to_contain_text("No open orders")
          lab.get_by_role("tab", name="Activity").click()
          expect(lab.get_by_test_id("activity")).to_contain_text("$46.31")
      
      
      MD = URL.replace("trading-lab", "market-data")
      
      
      def test_market_data_suite_and_mutation_run(page: Page):
          page.goto(MD)
          page.get_by_test_id("run-feed-suite").click()
          expect(page.get_by_test_id("feed-summary")).to_have_text("25 passed, 0 failed")
          page.get_by_test_id("feed-mutate").click()
          expect(page.get_by_test_id("feed-summary")).to_have_text("9 of 9 injected defects caught")
      
      
      def test_a_lost_segment_is_a_gap_with_a_gap_fill_request(page: Page):
          page.goto(MD)
          page.get_by_test_id("lose").click()
          expect(page.get_by_test_id("r-gaps")).to_have_text("33 to 33, 800 to 800")
          expect(page.get_by_test_id("r-gap")).to_contain_text("01 01 03 80")  # version 1, sequenced messages, protocol 0x8003
      
      
      def test_the_inspector_names_every_byte(page: Page):
          page.goto(MD)
          expect(page.get_by_test_id("fields")).to_contain_text("Message Protocol ID")
          expect(page.get_by_test_id("fields")).to_contain_text("32771 (0x8003, TOPS)")
          expect(page.get_by_test_id("formats")).to_contain_text("FAST 1.1")
      
      
      TOOL = URL.replace("trading-lab", "harness-tool")
      
      
      def test_harness_tool_fanout_reacts_to_the_fleet(page: Page):
          page.goto(TOOL)
          expect(page.get_by_test_id("gate")).to_contain_text("2 of 5")
          page.locator("tr[data-client=lender] [data-f=auto]").check()
          expect(page.get_by_test_id("gate")).to_contain_text("3 of 5")
          page.get_by_test_id("fix-all").click()
          expect(page.get_by_test_id("gate")).to_contain_text("5 of 5 client harnesses that run core-harness get 1.8.0 now · gate PASS")
      
      
      def test_harness_tool_hook_fails_open_then_holds(page: Page):
          page.goto(TOOL + "#hooks")
          expect(page.get_by_test_id("h-claude")).to_contain_text("FAILED OPEN")
          page.get_by_test_id("hook").select_option("guard-secrets-1.8.0")
          expect(page.get_by_test_id("h-claude")).to_contain_text("BLOCKED")
      
      
      def test_harness_tool_rules_and_session_gate(page: Page):
          page.goto(TOOL + "#rules")
          page.get_by_role("button", name="Load the brokerage's rules").click()
          expect(page.get_by_test_id("r-decision")).to_have_text("DENY")
          page.get_by_role("tab", name="Session gate").click()
          expect(page.get_by_test_id("session-gate")).to_contain_text("forbidden call Bash: kubectl get")
      
      
      FW = URL.replace("trading-lab", "fix-workbench")
      
      
      def test_workbench_finds_what_is_wrong_and_mends_the_frame(page: Page):
          page.goto(FW)
          page.get_by_test_id("sample").select_option(label="A limit order with no limit, and a broken checksum")
          expect(page.get_by_test_id("verdict")).to_contain_text("2 errors")
          expect(page.get_by_test_id("findings")).to_contain_text("needs Price (44)")
          page.get_by_test_id("mend").click()
          expect(page.get_by_test_id("verdict")).to_contain_text("1 error")
      
      
      def test_workbench_reads_a_session_and_its_recovery(page: Page):
          page.goto(FW + "#log")
          page.get_by_test_id("log-sample").select_option(label="An order lost in transit, and the recovery")
          expect(page.get_by_test_id("log-verdict")).to_contain_text("holds together")
          expect(page.get_by_test_id("lanes")).to_contain_text("gap fill")
          page.get_by_test_id("log-sample").select_option(label="A broken session: everything that can go wrong")
          expect(page.get_by_test_id("log-findings")).to_contain_text("serious error")
      
      
      def test_workbench_intercept_drop_then_recover(page: Page):
          page.goto(FW + "#wire")
          page.get_by_test_id("x-speed").select_option("0")
          page.get_by_test_id("x-drop").check(force=True)
          page.get_by_test_id("x-market").click()
          expect(page.get_by_test_id("x-events")).to_contain_text("Dropped in transit")
          page.get_by_test_id("x-chb").click()
          expect(page.get_by_test_id("x-events")).to_contain_text("sees a gap")
          expect(page.get_by_test_id("x-events")).to_contain_text("accepts a gap fill")
          expect(page.get_by_test_id("x-orders")).to_contain_text("filled")

      node run.js

      
      Orders
        PASS  A popular ticker trades like any other, and an unknown one is refused
        PASS  A ticker added after the account opened can be bought, at its simulated price
        PASS  A market buy during regular hours fills at the current price
        PASS  A buy limit below the market waits, then fills at the limit or better
        PASS  A buy limit above the market fills at the market, the better price
        PASS  A sell stop becomes a market order: on a gap it fills at the next price, not the stop
        PASS  A sell stop-limit that gaps below its limit waits; it fills only at the limit or better
        PASS  A sell stop must sit below the current price
        PASS  A market order placed after the close waits for the next open
        PASS  Fractional shares on market orders; whole shares on limit and stop orders
        PASS  You cannot sell more than you hold, counting open sell orders
        PASS  A buy above buying power is refused, and the message says by how much
        PASS  The same ticket sent twice (a double click, a retry) makes one order
        PASS  A day order expires at the end of the day; a GTC order stays
        PASS  A sell trailing stop of $1 follows the price up, holds when it falls, and sells on the drop
        PASS  When the price only falls, a trailing stop stays where it started and triggers there
        PASS  A 10 percent trailing stop on $42.10 starts at $37.89 and is $45.00 after a rise to $50.00
        PASS  A market-on-close order waits all day and fills at the closing price
        PASS  A limit-on-close buy fills at the close only when the closing price is at its limit or better
        PASS  Market-on-close orders are taken until 15:50; at 15:55 the ticket is refused
        PASS  A good-till-date order is good through the whole of its date, then expires
        PASS  A good-till-date ticket without a date, or with a past one, is refused
        PASS  An immediate-or-cancel limit that cannot fill is cancelled at once, and its cash is free again
        PASS  A fill-or-kill limit at or above the market fills in full at once
      
      Cancel and change
        PASS  Cancelling an open order cancels all of it and frees its cash
        PASS  A cancel for a filled order is rejected, too late to cancel, and the shares stay
        PASS  Changing a resting limit keeps the order ID, gets a new ClOrdID, and fills when the change makes it marketable
        PASS  A change is checked again like a new order: more shares than the cash allows are refused, the order stays as it was
        PASS  Halving a resting buy frees half of what it held back
        PASS  A filled order cannot be changed, and a change cannot switch the side
      
      Settlement
        PASS  A Monday sale settles on Tuesday (T+1)
        PASS  A Friday sale settles on Monday: settlement counts business days
        PASS  Sale proceeds join buying power when they settle, not before
      
      Money
        PASS  100 shares at $10.20 cost exactly $1,020.00
        PASS  Ten fills of $10.07 add up to $100.70
        PASS  0.3333 share at $42.10 rounds half up, once, at the end: $14.03
      
      Day trading
        PASS  The pattern day trader rule until the firm moves to intraday margin
        PASS  After October 20, 2027 the intraday standard applies, whatever the firm configured
        PASS  Four day trades across a weekend count: the window is 5 business days
        PASS  The pattern day trader test applies to margin accounts only
        PASS  A firm on the intraday standard does not count day trades toward a restriction
      
      Stock plan
        PASS  4,800 RSUs, one-year cliff: 1,200 vest on the anniversary, then 100 a month
        PASS  Nothing vests the day before the cliff; the cliff vests on the day
        PASS  A grant on January 31 vests on the last day of shorter months
        PASS  Supplemental wages are withheld at 22 percent up to $1 million in the year
        PASS  Above $1 million of supplemental wages in the year, the rate is 37 percent
        PASS  Sell-to-cover sells whole shares, rounded up, and never more than vested
        PASS  Exercising 1,000 options at a $12.50 strike costs $12,500.00
      
      FAST
        PASS  Stop-bit unsigned integers match the specification: 942755 is 39 45 a3
        PASS  Signed integers are two's complement: -7942755 is 7c 1b 1b 9d, -2 is fe, -5 is fb
        PASS  ASCII strings set the stop bit on the last character: "ABC" is 41 42 c3
        PASS  Every quote and trade in the sample survives FAST encoding and decoding unchanged
        PASS  FAST carries the same quotes and trades in under a third of the FIX bytes
      
      FIX
        PASS  CheckSum is the byte sum modulo 256, three digits; BodyLength counts the body
        PASS  A TOPS quote becomes a 35=X with a bid and an offer entry, prices in dollars
        PASS  A sequence gap is answered with a ResendRequest; the resend keeps the original numbers
        PASS  An order goes out as 35=D and comes back as 35=8 with the fill
        PASS  A cancel goes out as 35=F naming the order it cancels in 41; a filled one comes back as 35=9, too late to cancel
        PASS  A change goes out as 35=G with the new ClOrdID and the old one in 41, and is answered with ExecType 5, Replace
        PASS  A trailing stop goes out pegged: OrdType P, ExecInst a, a signed PegOffsetValue; good till date carries ExpireDate
        PASS  Lost heartbeats are not resent: one SequenceReset-GapFill skips them, and the next order arrives in sequence
      
      FIX checker
        PASS  A message the engine built has nothing wrong with it, written with SOH, |, ^A or <SOH>
        PASS  A limit order with no price and a wrong checksum: both found; mending fixes the frame, not the missing price
        PASS  An execution report whose CumQty and LeavesQty do not add up to OrderQty is flagged
        PASS  A log with a gap that a gap fill closed: the gap is noted, and the session counts as recovered
        PASS  The same gap, never filled: the checker says the messages are lost
      
      FIX
        PASS  A message is read into tag, field name, value and meaning
        PASS  An accepted order is ACKed, a rejected one is NACKed with the reason, and a heartbeat is neither
      
      Feed

      The engine is data/testlab/trading/engine.js and the suite is tests.js; the page runs both as they are. In a harness, the order-rules skill and the production guard on the Harness QA page are built for this kind of codebase.

      Sources

      Read on these pages, 2026-10-29

      Kitestring and its three companion symbols are invented. The ten popular tickers start at the closing prices read from the pages above; the moves after that are simulated. Nothing on this page is investment, tax or legal advice.