feat(deal-ticket): fix margin calculations in DealTicketMarginDetails for isolated margin mode (#5709)
This commit is contained in:
parent
42a98b6a35
commit
516b3e5b93
@ -59,6 +59,9 @@ export const DealTicketMarginDetails = ({
|
||||
variables: { marketId: market.id, partyId: partyId || '' },
|
||||
skip: !partyId,
|
||||
});
|
||||
const isInIsolatedMode =
|
||||
positionEstimate?.margin.bestCase.marginMode ===
|
||||
Schema.MarginMode.MARGIN_MODE_ISOLATED_MARGIN;
|
||||
const liquidationEstimate = positionEstimate?.liquidation;
|
||||
const marginEstimate = positionEstimate?.margin;
|
||||
const totalMarginAccountBalance =
|
||||
@ -70,18 +73,25 @@ export const DealTicketMarginDetails = ({
|
||||
const { decimals: assetDecimals, quantum } = asset;
|
||||
let marginRequiredBestCase: string | undefined = undefined;
|
||||
let marginRequiredWorstCase: string | undefined = undefined;
|
||||
const marginEstimateBestCase =
|
||||
BigInt(marginEstimate?.bestCase.initialLevel ?? 0) +
|
||||
BigInt(marginEstimate?.bestCase.orderMarginLevel ?? 0);
|
||||
const marginEstimateWorstCase =
|
||||
BigInt(marginEstimate?.worstCase.initialLevel ?? 0) +
|
||||
BigInt(marginEstimate?.worstCase.orderMarginLevel ?? 0);
|
||||
if (marginEstimate) {
|
||||
if (currentMargins) {
|
||||
const currentMargin =
|
||||
BigInt(currentMargins.initialLevel) +
|
||||
BigInt(currentMargins.orderMarginLevel);
|
||||
|
||||
const collateralIncreaseEstimateBestCase = BigInt(
|
||||
positionEstimate?.collateralIncreaseEstimate.bestCase ?? '0'
|
||||
);
|
||||
const collateralIncreaseEstimateWorstCase = BigInt(
|
||||
positionEstimate?.collateralIncreaseEstimate.worstCase ?? '0'
|
||||
);
|
||||
const marginEstimateBestCase = isInIsolatedMode
|
||||
? totalMarginAccountBalance + collateralIncreaseEstimateBestCase
|
||||
: BigInt(marginEstimate?.bestCase.initialLevel ?? 0);
|
||||
const marginEstimateWorstCase = isInIsolatedMode
|
||||
? totalMarginAccountBalance + collateralIncreaseEstimateWorstCase
|
||||
: BigInt(marginEstimate?.worstCase.initialLevel ?? 0);
|
||||
if (isInIsolatedMode) {
|
||||
marginRequiredBestCase = collateralIncreaseEstimateBestCase.toString();
|
||||
marginRequiredWorstCase = collateralIncreaseEstimateWorstCase.toString();
|
||||
} else if (marginEstimate) {
|
||||
if (currentMargins) {
|
||||
const currentMargin = BigInt(currentMargins.initialLevel);
|
||||
marginRequiredBestCase = (
|
||||
marginEstimateBestCase - currentMargin
|
||||
).toString();
|
||||
|
Loading…
Reference in New Issue
Block a user