Skip to content

Handle zero-equity Firstrade strategy runs#61

Merged
Pigbibi merged 1 commit into
mainfrom
fix/firstrade-zero-equity-execution
Jun 3, 2026
Merged

Handle zero-equity Firstrade strategy runs#61
Pigbibi merged 1 commit into
mainfrom
fix/firstrade-zero-equity-execution

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • parse Firstrade account balances from broader total-equity field shapes and account-list totals
  • preserve zero-equity account runs by no-executing weight-target decisions instead of raising during execution translation
  • support Firstrade-style formatted money strings in account payload parsing

Tests

  • uv run --no-project --with pytest --with pandas --with requests --with google-cloud-storage --with firstrade==0.0.38 python -m pytest tests/test_runtime_broker_adapters.py tests/test_firstrade_client.py tests/test_rebalance_service.py
  • uv run --no-project --with ruff ruff check decision_mapper.py application/account_payload_utils.py application/firstrade_client.py application/runtime_broker_adapters.py tests/test_firstrade_client.py tests/test_runtime_broker_adapters.py tests/test_rebalance_service.py

@Pigbibi Pigbibi merged commit 6f9d0e8 into main Jun 3, 2026
1 check passed
@Pigbibi Pigbibi deleted the fix/firstrade-zero-equity-execution branch June 3, 2026 04:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be3beb5128

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +93 to +95
balance_total = _positive_or_none(
_first_numeric_by_keyword_groups(balances, _TOTAL_EQUITY_KEYWORD_GROUPS)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve explicit non-positive account equity

When Firstrade returns an authoritative non-positive total/account value, such as a margin-deficit balance formatted as ($50.00), _positive_or_none treats it as missing and falls through to cash/position fallbacks. If the positions endpoint still reports positive market values, the snapshot becomes positive and weight targets can be translated and executed instead of hitting the total_equity <= 0 no-execute guard. Only absent/unparseable totals should fall back; parsed <= 0 totals should be preserved so the execution block remains effective.

Useful? React with 👍 / 👎.

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.

1 participant