Function: _matchIncomingOrder(PerpBook ds, Order matchedOrder, Order incomingOrder, bool amountIsBase)
This internal function handles a single match between an incoming taker order and a matched maker order during the _matchIncomingBid or _matchIncomingAsk functions' execution. This function executes the maker fill logic and performs cleanup or updates to the matched maker order. This function prevents self-trade by removing an order if the maker is the same user.
Additionally, this function
calculates the matched
baseDeltaandquoteDelta,executes maker-side fill logic,
updates or removes the maker order in the order book, and
returns the
MatchData, which containsmatchedAmount,baseDelta,quoteDelta, andtakerFee.
Branches and code coverage
Intended branches
The order book contains only the opposite order of the same account. The order was removed, and
matchedAmount,baseDelta,quoteDelta, andtakerFeeare zero.matchedOrderisreduceOnly.amountIsBaseis true for theincomingOrder. ThebaseDelta,quoteDelta, andmatchedAmountare calculated correctly.amountIsBaseis false for theincomingOrder. ThebaseDelta,quoteDeltaandmatchedAmountare calculated correctly.When
baseDelta > 0, themakerFee, maker’s position, and margin are updated correctly.Fully matches
matchedOrder, and it is removed from the order book.Partially matches
matchedOrder, and the amount is updated.