Skip to content

Commit 11f9215

Browse files
committed
fix(perps): use markPrice fallback when limit price not yet entered
When order type is limit but no limit price is set, margin calculation now falls back to markPrice (oracle) instead of mid price via effectivePrice. Addresses bugbot review feedback.
1 parent fa373e6 commit 11f9215

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,15 @@ const PerpsOrderViewContentBase: React.FC<PerpsOrderViewContentProps> = ({
567567

568568
const marginRequired = useMemo(() => {
569569
if (!isLoadingMarketData && orderForm.amount) {
570-
// For limit orders, use the limit price (via effectivePrice) for margin calculation.
571-
// For market orders, use markPrice (oracle price) which is the standard margin basis.
572-
const priceForMargin =
573-
orderForm.type === 'limit' ? effectivePrice : assetData.markPrice;
570+
// For limit orders with a valid limit price, use that price for margin calculation.
571+
// Otherwise use markPrice (oracle price) which is the standard margin basis.
572+
const hasValidLimitPrice =
573+
orderForm.type === 'limit' &&
574+
orderForm.limitPrice &&
575+
parseFloat(orderForm.limitPrice) > 0;
576+
const priceForMargin = hasValidLimitPrice
577+
? effectivePrice
578+
: assetData.markPrice;
574579
return calculateMarginRequired({
575580
amount: BigNumber(priceForMargin).times(positionSize).toString(),
576581
leverage: orderForm.leverage,
@@ -579,6 +584,7 @@ const PerpsOrderViewContentBase: React.FC<PerpsOrderViewContentProps> = ({
579584
}, [
580585
orderForm.amount,
581586
orderForm.type,
587+
orderForm.limitPrice,
582588
effectivePrice,
583589
assetData.markPrice,
584590
orderForm.leverage,

0 commit comments

Comments
 (0)