diff --git a/components/trade/AdvancedTradeForm.tsx b/components/trade/AdvancedTradeForm.tsx index efacb80f..bae6f3c5 100644 --- a/components/trade/AdvancedTradeForm.tsx +++ b/components/trade/AdvancedTradeForm.tsx @@ -155,8 +155,6 @@ const AdvancedTradeForm = () => { return bank }, [selectedMarket]) - console.log(selectedMarket) - // check for available account token slots const tokenPositionsFull = useTokenPositionsFull([baseBank, quoteBank]) @@ -545,11 +543,27 @@ const AdvancedTradeForm = () => { } if (selectedMarket instanceof Serum3Market && price) { const numberPrice = parseFloat(price) - const priceDiff = (numberPrice - oraclePrice) / oraclePrice - if (Math.abs(priceDiff) > selectedMarket.oraclePriceBand) { - invalidFields.price = t('trade:error-limit-price-outside-band', { - band: (selectedMarket.oraclePriceBand * 100).toFixed(2), - }) + const priceBand = selectedMarket.oraclePriceBand + if (side === 'buy') { + const priceLimit = (oraclePrice / (100 * (0.98 + priceBand))) * 100 + if (numberPrice < priceLimit) { + invalidFields.price = t( + 'trade:error-limit-price-buy-outside-band', + { + limit: priceLimit.toFixed(tickDecimals), + }, + ) + } + } else { + const priceLimit = (oraclePrice / (100 / (0.98 + priceBand))) * 100 + if (numberPrice > priceLimit) { + invalidFields.price = t( + 'trade:error-limit-price-sell-outside-band', + { + limit: priceLimit.toFixed(tickDecimals), + }, + ) + } } } if (Object.keys(invalidFields).length) { @@ -567,6 +581,7 @@ const AdvancedTradeForm = () => { setFormErrors, baseSymbol, t, + tickDecimals, ], ) diff --git a/public/locales/en/trade.json b/public/locales/en/trade.json index 208eeade..90c974b7 100644 --- a/public/locales/en/trade.json +++ b/public/locales/en/trade.json @@ -24,7 +24,8 @@ "current-price": "Current Price", "depth": "Depth", "edit-order": "Edit Order", - "error-limit-price-outside-band": "Limit price must be within {{band}}% of oracle price", + "error-limit-price-buy-outside-band": "Limit price must be above {{limit}}", + "error-limit-price-sell-outside-band": "Limit price must be below {{limit}}", "error-no-long": "No long position to reduce", "error-no-route": "No route found. Try adjusting your size", "error-no-short": "No borrow position to reduce", diff --git a/public/locales/es/trade.json b/public/locales/es/trade.json index 13fe1efd..a858f59d 100644 --- a/public/locales/es/trade.json +++ b/public/locales/es/trade.json @@ -24,7 +24,8 @@ "current-price": "Current Price", "depth": "Depth", "edit-order": "Edit Order", - "error-limit-price-outside-band": "Limit price must be within {{band}}% of oracle price", + "error-limit-price-buy-outside-band": "Limit price must be above {{limit}}", + "error-limit-price-sell-outside-band": "Limit price must be below {{limit}}", "error-no-long": "No long position to reduce", "error-no-route": "No route found. Try adjusting your size", "error-no-short": "No borrow position to reduce", diff --git a/public/locales/ru/trade.json b/public/locales/ru/trade.json index 13fe1efd..a858f59d 100644 --- a/public/locales/ru/trade.json +++ b/public/locales/ru/trade.json @@ -24,7 +24,8 @@ "current-price": "Current Price", "depth": "Depth", "edit-order": "Edit Order", - "error-limit-price-outside-band": "Limit price must be within {{band}}% of oracle price", + "error-limit-price-buy-outside-band": "Limit price must be above {{limit}}", + "error-limit-price-sell-outside-band": "Limit price must be below {{limit}}", "error-no-long": "No long position to reduce", "error-no-route": "No route found. Try adjusting your size", "error-no-short": "No borrow position to reduce", diff --git a/public/locales/zh/trade.json b/public/locales/zh/trade.json index 37ec4d02..7395b85c 100644 --- a/public/locales/zh/trade.json +++ b/public/locales/zh/trade.json @@ -24,7 +24,8 @@ "current-price": "目前价格", "depth": "深度", "edit-order": "编辑订单", - "error-limit-price-outside-band": "Limit price must be within {{band}}% of oracle price", + "error-limit-price-buy-outside-band": "Limit price must be above {{limit}}", + "error-limit-price-sell-outside-band": "Limit price must be below {{limit}}", "error-no-long": "无做多持仓可减少", "error-no-route": "No route found. Try adjusting your size", "error-no-short": "无做空持仓可减少", diff --git a/public/locales/zh_tw/trade.json b/public/locales/zh_tw/trade.json index c0e445fd..655f6e5a 100644 --- a/public/locales/zh_tw/trade.json +++ b/public/locales/zh_tw/trade.json @@ -24,7 +24,8 @@ "current-price": "目前價格", "depth": "深度", "edit-order": "編輯訂單", - "error-limit-price-outside-band": "Limit price must be within {{band}}% of oracle price", + "error-limit-price-buy-outside-band": "Limit price must be above {{limit}}", + "error-limit-price-sell-outside-band": "Limit price must be below {{limit}}", "error-no-long": "無做多持倉可減少", "error-no-route": "No route found. Try adjusting your size", "error-no-short": "無做空持倉可減少",