feat(deal-ticket): use order price if markPrice is not available in useMaxSize (#6057)
This commit is contained in:
parent
05debbd777
commit
0a70c0ea49
@ -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 (
|
||||
<AsyncRendererInline
|
||||
@ -80,6 +85,7 @@ export const DealTicketContainer = ({
|
||||
}
|
||||
market={market}
|
||||
marketPrice={marketPrice}
|
||||
markPrice={markPrice}
|
||||
marketData={marketData}
|
||||
submit={(transaction) => create(transaction)}
|
||||
/>
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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}
|
||||
/>
|
||||
</div>
|
||||
<Controller
|
||||
|
@ -13,7 +13,7 @@ export interface UseMaxSizeProps {
|
||||
marginAccountBalance: string;
|
||||
marginFactor?: string;
|
||||
marginMode?: MarginMode;
|
||||
marketPrice?: string;
|
||||
markPrice?: string;
|
||||
openVolume: string;
|
||||
positionDecimalPlaces: number;
|
||||
price?: string;
|
||||
@ -26,6 +26,7 @@ export interface UseMaxSizeProps {
|
||||
>;
|
||||
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,
|
||||
]);
|
||||
|
Loading…
Reference in New Issue
Block a user