Implement the following plan: Plan: Global Risk Parameters Overlay in TUI Context The…
- User
Implement the following plan:
Plan: Global Risk Parameters Overlay in TUI
Context
The trading platform currently has Rust-enforced risk limits (
risk.json) but no way for the operator to define advisory risk parameters from the TUI. The operator needs to set global risk parameters — trades per month, intraday flag, trade size in EUR, and stop-loss in EUR — that apply across all trading pairs. These parameters are communicated to Python trading agents (not enforced by the Rust risk guard).Parameters
Parameter Type Description trades_per_monthu32Maximum trades allowed per calendar month intradayboolWhether intraday trading is permitted trade_size_eurDecimalStandard trade size in EUR stop_loss_eurDecimalMaximum loss per trade in absolute EUR Approach
- Centered overlay/modal opened with
rkey in normal mode (follows existing confirm overlay pattern) - Navigate fields with
j/k, toggle bool withSpace, edit numeric fields withEnter→ type →Enter ssaves and closes,Esccancels (two-stage: first cancels field edit, then closes overlay)- Persisted to
agent_risk.json(separate fromrisk.jsonwhich lacksSerializeand has a different lifecycle) - On save, updated parameters are re-sent to all running agents via
AgentCommand::RiskLimits
File Changes
1.
src/risk/config.rs— AddAgentRiskParamsstruct- New struct with
Serialize,Deserialize,Clone,Debug Defaultimpl with conservative values (10 trades/month, no intraday, 100 EUR trade size, 20 EUR stop-loss)load(path)— reads from JSON file, returnsDefaultif file missingsave(path)— writes pretty-printed JSON- — human-readable string for agent system prompts
- Centered overlay/modal opened with
Assistant
I'll start by exploring the relevant files to understand the existing patterns before implementing.
Assistant
Good, I have a thorough understanding of the codebase. Let me read the specific files I'll be modifying.
Assistant
Let me also check the agent tab's keybindings rendering and the lib.rs module declarations.
Assistant
Now I have a thorough understanding of the codebase. Let me also check the trading pair tab's keybindings for the Mode match pattern.
Assistant
Now I have all the context I need. Let me create the task list and start implementing.
Assistant
Step 1: Add
AgentRiskParamstosrc/risk/config.rsAssistant
Now add the
AgentRiskParamsstruct after theRiskConfigimpl block (before the tests):Assistant
Now add the unit tests for
AgentRiskParamsat the end of the tests module:Assistant
Check if
tempfileis in Cargo.toml:Assistant
I need to add
tempfileas a dev dependency:Assistant
Step 2: Add
RiskEditmode and state toapp.rsAssistant
Now add the fields to the
Appstruct:Assistant
Add
Mode::RiskEditvariant:Assistant
Now add the
RiskEditStatestruct afterPendingOrder:Assistant
Now initialize the new fields in
App::new():Assistant
Step 3: Add key handling in
event.rsFirst, add the
Action::SaveRiskParamsvariant:Assistant
Add the action variant:
Assistant
Now update
handle_keyto handleEscdifferently forRiskEditmode and add theRiskEditdispatch:Assistant
Now add the
rkey binding inhandle_normal_mode. It should be a global key, not tab-specific:Assistant
Now add the
handle_risk_edit_modeandhandle_risk_field_editfunctions. I'll add them afterhandle_confirm_mode:Assistant
Now update the keybindings help text in both tab renderers. First the agent tab:
Assistant
Now the trading pair tab:
Assistant
Let me check if Mode is imported in the trading_pair module:
Assistant
Need to add
Modeto the import:Assistant
Step 4: Add risk edit overlay rendering in
ui.rsAssistant
Add the risk edit overlay call in
render():Assistant
Now add the
render_risk_edit_overlayfunction beforecentered_rect:Assistant
Step 5: Wire up persistence and agent communication in
main.rsAssistant
Now load agent risk params at startup and store in app:
Assistant
Now update the
AgentReadyhandler to include agent risk params in the description:Assistant
Now handle the
Action::SaveRiskParamsin the action dispatch:Assistant
Step 6: Build, test, and lint
Assistant
Compiles clean. Now run tests:
Assistant
All 104 tests pass. Now clippy:
Assistant
One clippy warning. Let me fix it:
Assistant
Let me also verify formatting:
Assistant
Now verify everything is clean:
Assistant
Everything is clean — formatting passes, clippy has zero warnings, all 104 tests pass.
Assistant
All done. Here's a summary of what was implemented:
Files changed
File Changes src/risk/config.rsAdded AgentRiskParamsstruct withSerialize/Deserialize/Clone/Debug,Default(10 trades/month, no intraday, 100 EUR trade size, 20 EUR stop-loss),load()/save()/describe()methods, and 4 unit testssrc/tui/app.rsAdded Mode::RiskEditvariant,RiskEditStatestruct (selected field, editing flag, input buffer, cursor, working copy),agent_risk_paramsandrisk_editfields onApp