Skip to content

fix(tui): report autoslice slices that Kite rejected - #7

Merged
mr-karan merged 1 commit into
zerodha:mainfrom
jay-tau:fix/tui-autoslice-slices
Nov 16, 2026
Merged

mr-karan merged 1 commit into
zerodha:mainfrom
jay-tau:fix/tui-autoslice-slices

Conversation

@jay-tau

@jay-tau jay-tau commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Follows up #5, which fixed this for kite orders place --autoslice and left the TUI for a separate PR.

What was wrong

When an order placed from the TUI order ticket is autosliced, the TUI shows [ OK ] order placed: <order_id> even if Kite rejected some of the slices. spawn_place_order keeps only order_id from the reply, so children is never read. The ticket also sends autoslice=true by itself when the quantity is above the freeze quantity (autoslice_forced), so this can happen even if the user never turned autoslice on.

With mock_responses/autoslice_response.json, where slice 4 of 5 fails with a MarginException, the toast row at 160 columns was:

 [ OK ] order placed: 1914227164488687616                                                                                                            Ctrl-L log

Fix

spawn_place_order now reads the reply's slices with the CLI's code from #5. If a slice failed, or non-null children isn't an array, the toast becomes an error toast, as for a bulk cancel where some orders failed. It gives the CLI's headline warning, then each failed slice:

 [ERR ] order placed: 1914227164488687616, 1 of 5 slices failed; Slice 4 failed: Insufficient funds. Required margin is 228365.92 but available      Ctrl-L log
        margin is 228358.50. (MarginException)
  • Slice numbering is the same as in fix(orders): list autoslice slices and flag failed ones #5: the top-level order is slice 1, and children are slices 2 onwards.
  • Wording: the toast reuses the CLI's phrases: N of M slices failed, could not read slice results, and failed: <message> (<error_type>) with sanitize_error applied.
  • Shared code: in src/app/render.rs, the CLI headline's count/unreadable check moves into slice_warning. The new slice_problems joins that warning with each failed slice into one line for the TUI. CLI output doesn't change; fix(orders): list autoslice slices and flag failed ones #5's golden files and unit tests pass as they are.
  • No change when nothing failed: if every slice was placed, or there are no children, the toast is the same as before. The orders refresh that follows a placement lists the placed slices.
  • Long messages: a toast shows at most three rows. The event log (Ctrl-L) keeps the full line.
  • AMO: the reply from the AMO retry in place_with_amo_fallback is read the same way.

I also added an [Unreleased] changelog entry.

What this assumes about Kite's reply

Open questions

  1. Does Kite list a slice that failed placement in the orderbook, for example as REJECTED? The docs only say that placed slices appear there. If failed slices don't, this toast and the event log are the only places the TUI shows the rejection.
  2. Does POST /orders/amo autoslice, and reply in the same shape? The AMO retry resends the original form, including autoslice=true. This PR reads children from whichever reply comes back, so it needs no change either way. The AMO test triggers the retry with the existing tests' switch_to_amo reply, and uses the regular-order fixture as the AMO reply.

Testing

  • New test a_rejected_autoslice_slice_is_reported in src/tui/app/regressions.rs.
    • It drives the ticket through test_support (open_and_review, then y), with the Kite client pointed at an httpmock server through a new mock_app helper.
    • The ticket has a freeze quantity of 1800, quantity 9000 and autoslice off. The mock matches only a form with autoslice=true.
    • Case 1, the fixture as it is: an error toast with the count and slice 4's reason.
    • Case 2, the fixture with the failed child removed: the same success toast as before.
    • With only the test applied at ee3bf08, it fails: left: (Success, "order placed: 1914227164488687616").
  • an_amo_retry_reports_failed_autoslice_slices_too in src/tui/data.rs. A regular order gets a 400 with the switch_to_amo hint, and the AMO retry, matched on autoslice=true and tag=switch_to_amo, returns the fixture. The failed slice is still reported.
  • slice_problems_number_failed_slices_from_two in src/app/render.rs. It covers absent, null and empty children, all slices placed, non-array children, and two failed slices numbered 2 and 4.
  • Local checks: cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, TERM=xterm-256color cargo test --workspace (1,650 + 47 + 12 passed, one ignored) and scripts/test-release-tools.sh all pass.
  • Mocks only: tests use only httpmock servers and fixture responses. I haven't placed a live autoslice order.

Fixes #6

When an order from the TUI ticket is autosliced, show an error toast
if Kite rejects any slice. The toast gives the failed slice count and
each failed slice's reason. Slices are numbered as in the CLI: the
top-level order is slice 1 and children are slices 2 onwards.

Share the CLI's slice reading and wording from src/app/render.rs. The
AMO retry reply is read the same way.
@mr-karan
mr-karan force-pushed the fix/tui-autoslice-slices branch from ab385fb to 885c85f Compare November 16, 2026 07:08
@mr-karan
mr-karan merged commit b09ef34 into zerodha:main Nov 16, 2026
3 checks passed
@jay-tau
jay-tau deleted the fix/tui-autoslice-slices branch November 16, 2026 13:17
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.

TUI order ticket shows [ OK ] for an autoslice order and hides slices that Kite rejected

2 participants