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,
|
useStaticMarketData,
|
||||||
useMarketPrice,
|
useMarketPrice,
|
||||||
marketInfoProvider,
|
marketInfoProvider,
|
||||||
|
markPriceProvider,
|
||||||
} from '@vegaprotocol/markets';
|
} from '@vegaprotocol/markets';
|
||||||
import { AsyncRendererInline } from '@vegaprotocol/ui-toolkit';
|
import { AsyncRendererInline } from '@vegaprotocol/ui-toolkit';
|
||||||
import { DealTicket } from './deal-ticket';
|
import { DealTicket } from './deal-ticket';
|
||||||
@ -46,7 +47,11 @@ export const DealTicketContainer = ({
|
|||||||
loading: marketDataLoading,
|
loading: marketDataLoading,
|
||||||
reload,
|
reload,
|
||||||
} = useStaticMarketData(marketId);
|
} = 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);
|
const create = useVegaTransactionStore((state) => state.create);
|
||||||
return (
|
return (
|
||||||
<AsyncRendererInline
|
<AsyncRendererInline
|
||||||
@ -80,6 +85,7 @@ export const DealTicketContainer = ({
|
|||||||
}
|
}
|
||||||
market={market}
|
market={market}
|
||||||
marketPrice={marketPrice}
|
marketPrice={marketPrice}
|
||||||
|
markPrice={markPrice}
|
||||||
marketData={marketData}
|
marketData={marketData}
|
||||||
submit={(transaction) => create(transaction)}
|
submit={(transaction) => create(transaction)}
|
||||||
/>
|
/>
|
||||||
|
@ -16,17 +16,17 @@ export interface DealTicketFeeDetailsProps {
|
|||||||
assetSymbol: string;
|
assetSymbol: string;
|
||||||
order: OrderSubmissionBody['orderSubmission'];
|
order: OrderSubmissionBody['orderSubmission'];
|
||||||
market: Market;
|
market: Market;
|
||||||
isMarketInAuction?: boolean;
|
marketIsInAuction?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DealTicketFeeDetails = ({
|
export const DealTicketFeeDetails = ({
|
||||||
assetSymbol,
|
assetSymbol,
|
||||||
order,
|
order,
|
||||||
market,
|
market,
|
||||||
isMarketInAuction,
|
marketIsInAuction,
|
||||||
}: DealTicketFeeDetailsProps) => {
|
}: DealTicketFeeDetailsProps) => {
|
||||||
const t = useT();
|
const t = useT();
|
||||||
const feeEstimate = useEstimateFees(order, isMarketInAuction);
|
const feeEstimate = useEstimateFees(order, marketIsInAuction);
|
||||||
const asset = getAsset(market);
|
const asset = getAsset(market);
|
||||||
const { decimals: assetDecimals, quantum } = asset;
|
const { decimals: assetDecimals, quantum } = asset;
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ export interface DealTicketProps {
|
|||||||
market: Market;
|
market: Market;
|
||||||
marketData: StaticMarketData;
|
marketData: StaticMarketData;
|
||||||
marketPrice?: string | null;
|
marketPrice?: string | null;
|
||||||
|
markPrice?: string | null;
|
||||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||||
submit: (order: Transaction) => void;
|
submit: (order: Transaction) => void;
|
||||||
onDeposit: (assetId: string) => void;
|
onDeposit: (assetId: string) => void;
|
||||||
@ -151,6 +152,7 @@ export const DealTicket = ({
|
|||||||
onMarketClick,
|
onMarketClick,
|
||||||
marketData,
|
marketData,
|
||||||
marketPrice,
|
marketPrice,
|
||||||
|
markPrice,
|
||||||
submit,
|
submit,
|
||||||
onDeposit,
|
onDeposit,
|
||||||
}: DealTicketProps) => {
|
}: DealTicketProps) => {
|
||||||
@ -393,6 +395,7 @@ export const DealTicket = ({
|
|||||||
const disableIcebergCheckbox = nonPersistentOrder;
|
const disableIcebergCheckbox = nonPersistentOrder;
|
||||||
const featureFlags = useFeatureFlags((state) => state.flags);
|
const featureFlags = useFeatureFlags((state) => state.flags);
|
||||||
const sizeStep = determineSizeStep(market);
|
const sizeStep = determineSizeStep(market);
|
||||||
|
const marketIsInAuction = isMarketInAuction(marketData.marketTradingMode);
|
||||||
|
|
||||||
const maxSize = useMaxSize({
|
const maxSize = useMaxSize({
|
||||||
accountDecimals: accountDecimals ?? undefined,
|
accountDecimals: accountDecimals ?? undefined,
|
||||||
@ -401,7 +404,7 @@ export const DealTicket = ({
|
|||||||
marginAccountBalance,
|
marginAccountBalance,
|
||||||
marginFactor: margin?.marginFactor,
|
marginFactor: margin?.marginFactor,
|
||||||
marginMode: margin?.marginMode,
|
marginMode: margin?.marginMode,
|
||||||
marketPrice: marketPrice ?? undefined,
|
markPrice: markPrice ?? undefined,
|
||||||
price,
|
price,
|
||||||
riskFactors,
|
riskFactors,
|
||||||
scalingFactors,
|
scalingFactors,
|
||||||
@ -410,6 +413,7 @@ export const DealTicket = ({
|
|||||||
generalAccountBalance,
|
generalAccountBalance,
|
||||||
openVolume,
|
openVolume,
|
||||||
positionDecimalPlaces: market.positionDecimalPlaces,
|
positionDecimalPlaces: market.positionDecimalPlaces,
|
||||||
|
marketIsInAuction,
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = useCallback(
|
const onSubmit = useCallback(
|
||||||
@ -594,7 +598,7 @@ export const DealTicket = ({
|
|||||||
}
|
}
|
||||||
assetSymbol={assetSymbol}
|
assetSymbol={assetSymbol}
|
||||||
market={market}
|
market={market}
|
||||||
isMarketInAuction={isMarketInAuction(marketData.marketTradingMode)}
|
marketIsInAuction={marketIsInAuction}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Controller
|
<Controller
|
||||||
|
@ -13,7 +13,7 @@ export interface UseMaxSizeProps {
|
|||||||
marginAccountBalance: string;
|
marginAccountBalance: string;
|
||||||
marginFactor?: string;
|
marginFactor?: string;
|
||||||
marginMode?: MarginMode;
|
marginMode?: MarginMode;
|
||||||
marketPrice?: string;
|
markPrice?: string;
|
||||||
openVolume: string;
|
openVolume: string;
|
||||||
positionDecimalPlaces: number;
|
positionDecimalPlaces: number;
|
||||||
price?: string;
|
price?: string;
|
||||||
@ -26,6 +26,7 @@ export interface UseMaxSizeProps {
|
|||||||
>;
|
>;
|
||||||
side: Side;
|
side: Side;
|
||||||
type: OrderType;
|
type: OrderType;
|
||||||
|
marketIsInAuction: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMaxSize = ({
|
export const useMaxSize = ({
|
||||||
@ -43,7 +44,8 @@ export const useMaxSize = ({
|
|||||||
activeOrders,
|
activeOrders,
|
||||||
riskFactors,
|
riskFactors,
|
||||||
scalingFactors,
|
scalingFactors,
|
||||||
marketPrice,
|
markPrice,
|
||||||
|
marketIsInAuction,
|
||||||
}: UseMaxSizeProps) =>
|
}: UseMaxSizeProps) =>
|
||||||
useMemo(() => {
|
useMemo(() => {
|
||||||
let maxSize = new BigNumber(0);
|
let maxSize = new BigNumber(0);
|
||||||
@ -67,10 +69,12 @@ export const useMaxSize = ({
|
|||||||
.div(marginFactor)
|
.div(marginFactor)
|
||||||
.div(toBigNum(price, decimalPlaces));
|
.div(toBigNum(price, decimalPlaces));
|
||||||
} else {
|
} else {
|
||||||
|
const effectivePrice =
|
||||||
|
type === OrderType.TYPE_LIMIT && marketIsInAuction ? price : markPrice;
|
||||||
if (
|
if (
|
||||||
!scalingFactors?.initialMargin ||
|
!scalingFactors?.initialMargin ||
|
||||||
!riskFactors ||
|
!riskFactors ||
|
||||||
!marketPrice ||
|
!effectivePrice ||
|
||||||
accountDecimals === undefined
|
accountDecimals === undefined
|
||||||
) {
|
) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -87,7 +91,7 @@ export const useMaxSize = ({
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.div(scalingFactors.initialMargin)
|
.div(scalingFactors.initialMargin)
|
||||||
.div(toBigNum(marketPrice, decimalPlaces));
|
.div(toBigNum(effectivePrice, decimalPlaces));
|
||||||
maxSize = maxSize
|
maxSize = maxSize
|
||||||
.minus(
|
.minus(
|
||||||
// subtract remaining orders
|
// subtract remaining orders
|
||||||
@ -134,5 +138,6 @@ export const useMaxSize = ({
|
|||||||
activeOrders,
|
activeOrders,
|
||||||
riskFactors,
|
riskFactors,
|
||||||
scalingFactors,
|
scalingFactors,
|
||||||
marketPrice,
|
markPrice,
|
||||||
|
marketIsInAuction,
|
||||||
]);
|
]);
|
||||||
|
Loading…
Reference in New Issue
Block a user