Skip to content

Conversation

@vcfgv
Copy link
Collaborator

@vcfgv vcfgv commented Nov 17, 2025

📝 Pull Request Template

1. Related Issue

Closes # (issue number)

Type of Change (select one)

Bug Fix, New Feature

3. Description

  • Composer — robust LLM parsing:

    • _call_llm now accepts agent results that are already a LlmPlanProposal, a dict, or a JSON/text string. It attempts to validate/parse into LlmPlanProposal and falls back to a minimal proposal that preserves the raw model output in rationale.
    • Why: many LLM providers sometimes return raw JSON strings or unwrapped dicts; this change avoids crashes and preserves the model output for debugging/retry logic.
  • Composer — safety for missing prices & conservative BP accounting:

    • _normalize_quantity now blocks exposure-increasing trades when no valid price is available, only allowing reduce-only (flattening) actions.
    • Consumed buying-power is computed using the same slippage-adjusted effective price used for the clamp (more conservative).
    • Why: prevents creating “free” leverage/large positions when price data is missing and avoids underestimating buying-power consumption that previously led to inflated portfolio values.
  • Portfolio settlement correctness:

    • Trade settlement and cash updates now prefer avg_exec_price, then exit_price, then entry_price (fallback to market snapshot) when computing notional and mark price.
    • Why: ensures cash reflects realized PnL at the actual execution price so equity (total_value) equals account_balance + net_exposure after closes; fixes the observed mismatch after full liquidation.
  • Logs & diagnostics: composer and portfolio code now emit clear warnings/errors when encountering missing/invalid model or price data and preserve raw LLM outputs in rationale for auditing.

    • Why: improves observability for debugging model/parsing and market data issues in production.

Summary: these changes make decision-time sizing and portfolio accounting safe and deterministic: they prevent exposure creation when market prices are unavailable, ensure buying-power is conservatively estimated, and make cash/realized PnL settle correctly — plus they add tests and better logging so the behaviors are observable and reproducible.

4. Testing

  • I have tested this locally.
  • I have updated or added relevant tests.

5. Checklist

@vcfgv vcfgv changed the title feature: structured trade history data and portfolio summary feature: structured trade history data, portfolio summary, bug fixes Nov 17, 2025
@su8su su8su merged commit 414f785 into main Nov 19, 2025
3 checks passed
@su8su su8su deleted the feature/refine-trade-history-data-structure branch November 19, 2025 07:51
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.

2 participants