Repository navigation
Refactors to avoid code duplication - #35
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.