Skip to content

portfolio: additional tests for edge cases. - #33

Merged
MathisWellmann merged 4 commits into
mainfrom
more-tests-again
Nov 25, 2026
Merged

MathisWellmann merged 4 commits into
mainfrom
more-tests-again

Conversation

@MathisWellmann

Copy link
Copy Markdown
Owner

No description provided.

…hecks

In PortfolioExchange::check_portfolio_market_order, flipping a position can
invalidate the position offset of resting limit orders on that market, so
post_req must recompute order_margin against the post-flip position rather
than keeping the pre-flip order margin.

Add boundary and sign tests for check_portfolio_market_order (same-direction,
flip with profit/loss/fees/other-market uPnL, flip with resting order offset
loss) and check_portfolio_limit_order (order margin delta + maker fee reserve).
…in reconciliation

Cover PortfolioExchange's collateral accounting and margin-call victim selection:
- reserved_maker_fees and required_collateral summing bids and asks
- largest_collateral_contributor across bids, asks, maker fees, and multiple markets
- reconcile_portfolio_margin and update_market at exact zero excess and maintenance
  margin boundaries.
…liquidation ledger

Cover remaining PortfolioExchange order lifecycle and margin/stop edge cases:
- amend_limit_order (OrderIdNotFound vs OrderNoLongerActive boundary, CBOE
  leaves-qty arithmetic, AmendQtyAlreadyFilled cancellation, post-only crossing)
- submit_limit_order rate limiting and post-only rejection
- add_market stop capacity accumulation, delisted market stop draining,
  stop-protection collar rejection, and strictly-reducing checks on both sides
- liquidation clearance fee ledger reconciliation.
@github-actions

Copy link
Copy Markdown

Summary

The PR fixes the position-flip pre-trade check in check_portfolio_market_order to recompute the flip market's resting-order margin at the post-flip position (removing the stale current order margin from other_req and adding post_order_margin), and adds ~15 integration tests covering margin/fee boundaries, margin-call order selection, maintenance-margin edges, amend/reduce-only semantics, stop capacity growth, and ledger reconciliation. I verified the fix against the canonical order_margin math in src/account/utils.rs and required_collateral in portfolio_exchange.rs, and re-derived the boundary arithmetic in the new flip tests; all checks are consistent.

Issues

None

@MathisWellmann
MathisWellmann merged commit 5430698 into main Nov 25, 2026
2 checks passed
@MathisWellmann
MathisWellmann deleted the more-tests-again branch November 25, 2026 22:01
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