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
baseDelta
andquoteDelta
,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
, andtakerFee
are zero.matchedOrder
isreduceOnly
.amountIsBase
is true for theincomingOrder
. ThebaseDelta
,quoteDelta
, andmatchedAmount
are calculated correctly.amountIsBase
is false for theincomingOrder
. ThebaseDelta
,quoteDelta
andmatchedAmount
are 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.