Skip to content

[codex] Add platform-aware small account order floors#154

Merged
Pigbibi merged 1 commit into
mainfrom
codex/platform-cost-aware-small-accounts
Jun 12, 2026
Merged

[codex] Add platform-aware small account order floors#154
Pigbibi merged 1 commit into
mainfrom
codex/platform-cost-aware-small-accounts

Conversation

@Pigbibi

@Pigbibi Pigbibi commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add LongBridge runtime support for LONGBRIDGE_MIN_ORDER_NOTIONAL_USD
  • default LongBridge's small-account order floor to USD 100 based on the USD 0.99 fixed platform fee
  • apply the platform floor to buys and ordinary rebalances while preserving target-zero risk exits
  • bump QuantPlatformKit, UsEquityStrategies, and HkEquityStrategies pins to the latest main commits

Why

Small accounts need broker-aware execution filters, but risk-reduction sells must not be blocked by a platform minimum order floor.

Validation

  • python -m py_compile runtime_config_support.py application/runtime_composer.py application/runtime_dependencies.py application/rebalance_service.py application/execution_service.py main.py tests/test_rebalance_service.py tests/test_runtime_config_support.py tests/test_runtime_composer.py
  • PYTHONPATH=/home/ubuntu/Projects/LongBridgePlatform:/home/ubuntu/Projects/QuantPlatformKit/src python -m pytest tests/test_runtime_composer.py::test_runtime_composer_builds_runtime_and_config_from_local_builders tests/test_rebalance_service.py::RebalanceServiceNotificationTests::test_min_order_notional_skips_small_buy tests/test_rebalance_service.py::RebalanceServiceNotificationTests::test_min_order_notional_does_not_block_zero_target_risk_sell
  • PYTHONPATH=/home/ubuntu/Projects/LongBridgePlatform:/home/ubuntu/Projects/QuantPlatformKit/src:/home/ubuntu/Projects/UsEquityStrategies/src:/home/ubuntu/Projects/HkEquityStrategies/src /tmp/qsl-platform-test-venv/bin/python -m pytest tests/test_runtime_config_support.py::RuntimeConfigSupportTests::test_min_order_notional_is_loaded_from_env tests/test_runtime_config_support.py::RuntimeConfigSupportTests::test_load_platform_runtime_settings_uses_defaults_with_explicit_strategy_profile

@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: 06ca98c88c

ℹ️ 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 +695 to +696
min_order_notional = max(0.0, float(min_order_notional_usd or 0.0))
current_min_trade = max(float(execution["current_min_trade"]), min_order_notional)

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 Convert USD floor before comparing with HKD trade values

For HK runtimes, this compares LONGBRIDGE_MIN_ORDER_NOTIONAL_USD directly against execution["current_min_trade"] and the target/market deltas, but those execution values are in the configured trading currency: runtime_config_support.py defaults HK to trading_currency="HKD", and application/longbridge_portfolio.py builds cash and market values from HKD cash/quotes. As a result the default USD 100 floor becomes only HKD 100 for .HK orders, so HK buys/sells between HKD 100 and roughly USD 100 equivalent are still submitted despite the intended USD floor. Please convert the USD floor into the portfolio currency before taking the max, or keep the configured floor currency-specific.

Useful? React with 👍 / 👎.

@Pigbibi Pigbibi force-pushed the codex/platform-cost-aware-small-accounts branch from 06ca98c to 7d3468b Compare June 12, 2026 11:47

@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: 7d3468b972

ℹ️ 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".

investable_cash = float(execution["investable_cash"])
current_min_trade = float(execution["current_min_trade"])
min_order_notional = max(0.0, float(min_order_notional_usd or 0.0))
current_min_trade = max(float(execution["current_min_trade"]), min_order_notional)

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 Check the buy budget against the notional floor

This raises the candidate threshold, but the actual buy size later comes from can_buy_value = min(diff, investable_cash). When a symbol is underweight by more than the floor but the remaining investable cash is below it (for example a $500 gap, $90 cash, and a $10 share price), the symbol passes this filter and the loop can still submit a ~$90 buy, defeating LONGBRIDGE_MIN_ORDER_NOTIONAL_USD. Please also reject buys whose available budget or final estimated order value is below the floor.

Useful? React with 👍 / 👎.

@Pigbibi Pigbibi force-pushed the codex/platform-cost-aware-small-accounts branch from 7d3468b to e80cd51 Compare June 12, 2026 11:49
@Pigbibi Pigbibi merged commit 10b5f82 into main Jun 12, 2026
1 check passed
@Pigbibi Pigbibi deleted the codex/platform-cost-aware-small-accounts branch June 12, 2026 11:51

@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: e80cd516d5

ℹ️ 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 +792 to +797
if _sell_delta_exceeds_floor(
current_value=market_values[symbol],
target_value=target_values[symbol],
threshold_value=threshold_value,
min_trade_value=current_min_trade,
):

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 Enforce the floor on floored sell quantities

For positive-target rebalances, this gate compares the pre-rounding dollar delta with current_min_trade, but the order sent later is the floored whole-share quantity from _sell_order_quantity. When the account is overweight by more than the new platform floor but one whole-share sale is below that floor (for example current $220, target $110, price $60), this branch still submits a ~$60 ordinary sell even though min_order_notional_usd is 100. Please recheck quantity * submitted_price (while still exempting target-zero exits) before submitting the sell.

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