Skip to content

Refactors to avoid code duplication - #35

Merged
MathisWellmann merged 7 commits into
mainfrom
refactors
Nov 26, 2026
Merged

MathisWellmann merged 7 commits into
mainfrom
refactors

Conversation

@MathisWellmann

Copy link
Copy Markdown
Owner

No description provided.

Exchange and PortfolioExchange each had a private copy of the check whether a
limit order crosses (or locks) the top of book. Keep it once, on LimitOrder, so a
fix cannot land in only one venue.
Exchange::clamp_resting_reduce_only and an inline copy in PortfolioExchange both
clamped a resting reduce-only order to the room the other resting reduce-only
orders leave within the position. Keep it once as
LimitOrder::clamp_to_reduce_only_room. The portfolio now also asserts that the
order was clamped to the position before, like the exchange did.

Exchange::is_strictly_reducing was only used by that assert and is removed.
Both amend_limit_order implementations computed the new remaining quantity with
the cboe/binance delta rule. Keep it once as LimitOrder::amended_leaves_qty, so
both venues amend and cancel partially filled orders the same way.
PortfolioExchange::apply_funding re-implemented Account::funding_cashflow inline.
Move the formula to Position::funding_cashflow, which both use.

PortfolioExchange::apply_funding now validates the market id before the mark
price, so an unknown market with a non-positive mark price returns an error
instead of panicking.
…olio

MarketSlot re-implemented the largest collateral contributor search and the
reserved maker fees of Account. ActiveLimitOrders::largest_collateral_contributor
now also returns the freed amount, which the portfolio needs, and
ActiveLimitOrders::reserved_maker_fees serves both. Iteration order and
max_by_key are unchanged, so the margin call cancels the same order.
Pure path shortening (crate::execution_rules:: -> execution_rules::), kept
separate so the refactor revisions stay focused.
@MathisWellmann MathisWellmann self-assigned this Nov 26, 2026
@MathisWellmann
MathisWellmann merged commit bfa9b04 into main Nov 26, 2026
1 of 2 checks passed
@MathisWellmann
MathisWellmann deleted the refactors branch November 26, 2026 18:00
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