# Recovery and development ## Real orders `cross.py` records an entry intent before sending its first order. A working limit order stays pending until the exchange reports a terminal status; a cancel acknowledgement alone is insufficient. If the spot hedge is rejected, the remaining short is closed with reduce-only orders and the actual position is checked again. Failed and partial rollbacks survive restart and block further real entries while recovery is in progress. The saved instrument snapshot allows cancellation/rollback even before the market scanner rediscovers the pair. `real_mirror.py` records prepared, submitted and filled stages. A prepared entry is never replayed on restart. A confirmed fill is saved before requesting a take-profit. Saved positions are closed after restart, consistent with the previous simulator behaviour. Atomic JSON writes are shared through `persistence.py`; persistence failures block new entries and appear in the UI. An accepted submission whose response was lost may have no exchange order ID. A flat position snapshot does not prove that such an order cannot fill later. These intents remain blocked; the futures recovery path checks and reduces any remaining position without submitting another entry. Unknown spot submissions and interrupted spot-to-spot entries require manual reconciliation on the exchanges. The application does not provide a blind “forget pending order” button. The `/api/basis?ex=cross_real` response includes `recovery` details; the UI displays the reason for pausing. A supervised resolution must verify the exchange's open orders and fills, not just its current position. Automatic resolution by client order ID across every exchange is not implemented. ## Browser boundary Both the proxy and the engine validate the original loopback Host on GET and POST. A browser Origin, if present, must match that authority; POST also requires `X-Sim: 1`. The proxy preserves the validated Host when forwarding. Both listeners remain bound to loopback. This is local-app isolation, not user authentication for internet hosting. Static assets are served from an explicit allowlist. Responses for an earlier venue/coin selection cannot replace the current screen. Commands are disabled until the selected context has loaded, and row close actions carry their original venue or coin. Poll responses also have sequence numbers so a slower old response cannot overwrite a newer completed response. ## Code boundaries | Responsibility | Files | | --- | --- | | Web layout, styles, behaviour | `web_sim.html`, `web/app.css`, `web/app.js` | | HTTP routing and local browser policy | `web_sim.py`, `web_proxy.py`, `request_security.py` | | Desktop account models and chart | `desktop_models.py`, `desktop_chart.py` | | Desktop coordination | `main.py` | | Order execution and recovery | `cross.py`, `real_mirror.py` | | Exchange adapters | `live.py`, `bybit_live.py` | | Atomic snapshots | `persistence.py` | | Historical execution and risk metrics | `historical_backtest.py`, `strategy.py` | ## Verification Python 3.11+ is supported by the pinned dependencies in `requirements.txt`; the primary local validation uses Python 3.12. JavaScript regression tests use Node.js 22+ and its built-in test runner, with no npm dependencies. ```powershell python -m pip install -r requirements.txt python -B scripts/run_tests.py node --test tests/web_context.test.cjs ``` The Python runner blocks external connections and DNS while permitting loopback HTTP fixtures. Exchange orders are tested using fake clients. CI runs these suites on Windows with Python 3.11, 3.12 and 3.13; configuring the workflow does not imply that a remote CI run or a real exchange integration has been performed. Regression cases cover refused/partial rollback, uncertain cancellation and submission, restart before and after order acceptance, failed disk writes, hostile Host/Origin, response ordering, percentage drawdown and capital-floor ordering for long/short backtests including fees.