Skip to content

fix(sandbox): accept decimal position values - #390

Merged
brokermr810 merged 59 commits into
mainfrom
test
Nov 19, 2026
Merged

brokermr810 merged 59 commits into
mainfrom
test

Conversation

@brokermr810

Copy link
Copy Markdown
Collaborator

Summary

  • normalize PostgreSQL NUMERIC position values before they cross the Strategy API V2 runtime boundary
  • add exact, JSON-only Decimal transport support in both parent and sandbox worker directions
  • preserve fail-closed behavior for unsupported objects and normalize non-finite decimal values consistently with floats
  • add transport, live-position, and isolated-process regression coverage

Root cause

The isolated live strategy process introduced a JSON-only IPC boundary. Live position snapshots still carried PostgreSQL NUMERIC values as Python Decimal objects, but the transport contract did not support that type. Each affected strategy failed during synchronize_positions() before its callback ran; after five consecutive failures, the runtime safety guard stopped it.

Production logs confirmed 255 failed cycles across 51 strategies, followed by 51 repeated-runtime stops. No second unsupported sandbox input type was observed.

Validation

  • Ruff checks passed for all changed files
  • 85 focused strategy runtime, sandbox, portfolio, and hedged-position tests passed in the Linux container
  • full isolated-process regression covers Decimal position synchronization

Deployment impact

  • no database migration
  • no frontend or API contract change
  • no exchange adapter or order-sizing behavior change
  • strategies already stopped by the incident remain stopped; operators must verify venue positions and restart them deliberately after deployment

tianhe added 30 commits November 1, 2026 17:17
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/app/routes/community.py
tianhe and others added 27 commits November 7, 2026 00:48
#362 normalized the Binance protection orders, but Bitget (UTA and
classic) and Bybit still sent percentage-derived prices with str(), e.g.
stopLoss=77951.14749999999 for a 2.5% stop on a 76049.9 short. Those are
off the contract tick, so the venue rejects the protection order.

Run the stop-loss, take-profit and trailing activation prices (and the
Bybit trailingStop distance) through each client's _normalize_price, the
same way #362 does for Binance, and raise when the result falls below the
minimum.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: aliassar <[email protected]>
Signed-off-by: TIANHE <[email protected]>

# Conflicts:
#	backend_api_python/tests/test_safe_exec.py
#	backend_api_python/tests/test_strategy_runtime_process_isolation.py
@sonarqubecloud

Copy link
Copy Markdown

@brokermr810
brokermr810 merged commit efd7914 into main Nov 19, 2026
14 checks passed
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

3 participants