Closed fredsnax closed 2 weeks ago
In getRequiredMarginWithNewPosition
, newRequiredMargin
is calculated with fillPrice. This is inaccurate as fillPrice includes a premium/discount, and therefore should only be used for PnL calculations.
Otherwise, a new position might be within the required margin (based on fillPrice) but immediately after settling it could be eligible for liquidation (which calculates margin based on oracle price).
This is also inconsistent with how oldRequiredMargin
is calculated in the next step, which uses currentPrice.
Recommendation
Use currentPrice to calculate newRequiredMargin
.
… price to match liquidations