From edd5c3cf11a704582a3ab2193ee2787b4b271503 Mon Sep 17 00:00:00 2001 From: saml33 Date: Mon, 28 Oct 2024 10:13:53 +1100 Subject: [PATCH] change perp reference price check to percentage difference --- components/trade/AdvancedTradeForm.tsx | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/components/trade/AdvancedTradeForm.tsx b/components/trade/AdvancedTradeForm.tsx index 00a2a460..9fee9ac0 100644 --- a/components/trade/AdvancedTradeForm.tsx +++ b/components/trade/AdvancedTradeForm.tsx @@ -714,6 +714,13 @@ const AdvancedTradeForm = () => { [oraclePrice, tradeForm.side, tradeForm.tradeType], ) + const percentagePriceDifference = (price1: number, price2: number) => { + const mean = (price1 + price2) / 2 + const diff = Math.abs(price1 - price2) + + return (diff / mean) * 100 + } + const handleStandardOrder = useCallback(async () => { const { client } = mangoStore.getState() const { group } = mangoStore.getState() @@ -797,12 +804,11 @@ const AdvancedTradeForm = () => { }) return } - const stddev = Math.sqrt( - ((orderPrice - (orderPrice + trafficApiPrice) / 2) ** 2 + - (trafficApiPrice - (orderPrice + trafficApiPrice) / 2) ** 2) / - 2, + const priceDifferencePercentage = percentagePriceDifference( + orderPrice, + trafficApiPrice, ) - if (stddev > 1) { + if (priceDifferencePercentage > MAX_PERP_SLIPPAGE * 100) { notify({ type: 'error', title: 'Price outside limit',