diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-container.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-container.tsx index 71d1d2588..b1deab59e 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-container.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-container.tsx @@ -8,6 +8,7 @@ import { useStaticMarketData, useMarketPrice, marketInfoProvider, + markPriceProvider, } from '@vegaprotocol/markets'; import { AsyncRendererInline } from '@vegaprotocol/ui-toolkit'; import { DealTicket } from './deal-ticket'; @@ -46,7 +47,11 @@ export const DealTicketContainer = ({ loading: marketDataLoading, reload, } = useStaticMarketData(marketId); - const { data: marketPrice } = useMarketPrice(market?.id); + const { data: marketPrice } = useMarketPrice(marketId); + const { data: markPrice } = useDataProvider({ + dataProvider: markPriceProvider, + variables: { marketId }, + }); const create = useVegaTransactionStore((state) => state.create); return ( create(transaction)} /> diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-fee-details.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-fee-details.tsx index bcefdb6e5..f2ddd4ef1 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket-fee-details.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket-fee-details.tsx @@ -16,17 +16,17 @@ export interface DealTicketFeeDetailsProps { assetSymbol: string; order: OrderSubmissionBody['orderSubmission']; market: Market; - isMarketInAuction?: boolean; + marketIsInAuction?: boolean; } export const DealTicketFeeDetails = ({ assetSymbol, order, market, - isMarketInAuction, + marketIsInAuction, }: DealTicketFeeDetailsProps) => { const t = useT(); - const feeEstimate = useEstimateFees(order, isMarketInAuction); + const feeEstimate = useEstimateFees(order, marketIsInAuction); const asset = getAsset(market); const { decimals: assetDecimals, quantum } = asset; diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx index 24452d05e..f5333f73d 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx @@ -97,6 +97,7 @@ export interface DealTicketProps { market: Market; marketData: StaticMarketData; marketPrice?: string | null; + markPrice?: string | null; onMarketClick?: (marketId: string, metaKey?: boolean) => void; submit: (order: Transaction) => void; onDeposit: (assetId: string) => void; @@ -151,6 +152,7 @@ export const DealTicket = ({ onMarketClick, marketData, marketPrice, + markPrice, submit, onDeposit, }: DealTicketProps) => { @@ -393,6 +395,7 @@ export const DealTicket = ({ const disableIcebergCheckbox = nonPersistentOrder; const featureFlags = useFeatureFlags((state) => state.flags); const sizeStep = determineSizeStep(market); + const marketIsInAuction = isMarketInAuction(marketData.marketTradingMode); const maxSize = useMaxSize({ accountDecimals: accountDecimals ?? undefined, @@ -401,7 +404,7 @@ export const DealTicket = ({ marginAccountBalance, marginFactor: margin?.marginFactor, marginMode: margin?.marginMode, - marketPrice: marketPrice ?? undefined, + markPrice: markPrice ?? undefined, price, riskFactors, scalingFactors, @@ -410,6 +413,7 @@ export const DealTicket = ({ generalAccountBalance, openVolume, positionDecimalPlaces: market.positionDecimalPlaces, + marketIsInAuction, }); const onSubmit = useCallback( @@ -594,7 +598,7 @@ export const DealTicket = ({ } assetSymbol={assetSymbol} market={market} - isMarketInAuction={isMarketInAuction(marketData.marketTradingMode)} + marketIsInAuction={marketIsInAuction} /> ; side: Side; type: OrderType; + marketIsInAuction: boolean; } export const useMaxSize = ({ @@ -43,7 +44,8 @@ export const useMaxSize = ({ activeOrders, riskFactors, scalingFactors, - marketPrice, + markPrice, + marketIsInAuction, }: UseMaxSizeProps) => useMemo(() => { let maxSize = new BigNumber(0); @@ -67,10 +69,12 @@ export const useMaxSize = ({ .div(marginFactor) .div(toBigNum(price, decimalPlaces)); } else { + const effectivePrice = + type === OrderType.TYPE_LIMIT && marketIsInAuction ? price : markPrice; if ( !scalingFactors?.initialMargin || !riskFactors || - !marketPrice || + !effectivePrice || accountDecimals === undefined ) { return 0; @@ -87,7 +91,7 @@ export const useMaxSize = ({ ) ) .div(scalingFactors.initialMargin) - .div(toBigNum(marketPrice, decimalPlaces)); + .div(toBigNum(effectivePrice, decimalPlaces)); maxSize = maxSize .minus( // subtract remaining orders @@ -134,5 +138,6 @@ export const useMaxSize = ({ activeOrders, riskFactors, scalingFactors, - marketPrice, + markPrice, + marketIsInAuction, ]);