Submitted by carlitox477, also found by koxuan
https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L178-L179 
https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L734-L738
When initiateMarketOrder is called, _marginAfterFees are calculated and then used to calculate _positionSize:
The problem is that _handleOpenFees does not consider referrer fees when it calculates its output (paidFees), leading to open a position greater than expected.
For a referred trade, initiateMarketOrder always opens a position greater than the one supposed, by allowing the use of more margin than the one expected.
The output of _handleOpenFees is _feePaid, which is calculated once, and it does not consider referralFees:
Then we can notice that, if the output of _handleOpenFees did not consider referral fees, neither would \_marginAfterFees do:
Consider referral fees when _feePaid is calculated in _handleOpenFees:
TriHaz (Tigris Trade) confirmed 
Alex the Entreprenerd (judge) commented:
