Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8af8adc3e7 | ||
|
|
adbffe133f | ||
|
|
718dd5a4e4 | ||
|
|
09bbc75729 | ||
|
|
d27758b7f4 | ||
|
|
89530d3a8c | ||
|
|
d76dd79df2 | ||
|
|
8f070432ab | ||
|
|
bf37712ac5 |
@@ -0,0 +1,70 @@
|
|||||||
|
import { addDecimalsFormatNumber, t } from '@vegaprotocol/react-helpers';
|
||||||
|
import { Tooltip } from '@vegaprotocol/ui-toolkit';
|
||||||
|
|
||||||
|
export interface MarginLevels {
|
||||||
|
initialLevel?: string;
|
||||||
|
searchLevel?: string;
|
||||||
|
maintenanceLevel?: string;
|
||||||
|
collateralReleaseLevel?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const MarginBreakdown = ({
|
||||||
|
marginLevels,
|
||||||
|
assetDecimalPlaces,
|
||||||
|
assetSymbol,
|
||||||
|
}: {
|
||||||
|
marginLevels?: MarginLevels;
|
||||||
|
assetDecimalPlaces: number;
|
||||||
|
assetSymbol: string;
|
||||||
|
}) => {
|
||||||
|
if (!marginLevels) return null;
|
||||||
|
const formatNumberWithAssetDp = (value: string | number | null | undefined) =>
|
||||||
|
value && !isNaN(Number(value))
|
||||||
|
? `${addDecimalsFormatNumber(value, assetDecimalPlaces)} ${assetSymbol}`
|
||||||
|
: '-';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<dl className="grid grid-cols-8">
|
||||||
|
<Tooltip
|
||||||
|
description={t(
|
||||||
|
'This is the minimum margin required for a party to place a new order on the network'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{<dt className="col-span-3">{t('Initial level')}</dt>}
|
||||||
|
</Tooltip>
|
||||||
|
<dd className="text-right col-span-5">
|
||||||
|
{formatNumberWithAssetDp(marginLevels.initialLevel)}
|
||||||
|
</dd>
|
||||||
|
<Tooltip
|
||||||
|
description={t(
|
||||||
|
'If the margin is between maintenance and search, the network will initiate a collateral search'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{<dt className="col-span-3">{t('Search level')}</dt>}
|
||||||
|
</Tooltip>
|
||||||
|
<dd className="text-right col-span-5">
|
||||||
|
{formatNumberWithAssetDp(marginLevels.searchLevel)}
|
||||||
|
</dd>
|
||||||
|
<Tooltip
|
||||||
|
description={t(
|
||||||
|
'Minimal margin for the position to be maintained in the network'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{<dt className="col-span-3">{t('Maintenance level')}</dt>}
|
||||||
|
</Tooltip>
|
||||||
|
<dd className="text-right col-span-5">
|
||||||
|
{formatNumberWithAssetDp(marginLevels.maintenanceLevel)}
|
||||||
|
</dd>
|
||||||
|
<Tooltip
|
||||||
|
description={t(
|
||||||
|
'If the margin of the party is greater than this level, then collateral will be released from the margin account into the general account of the party for the given asset.'
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{<dt className="col-span-3">{t('Collateral release level')}</dt>}
|
||||||
|
</Tooltip>
|
||||||
|
<dd className="text-right col-span-5">
|
||||||
|
{formatNumberWithAssetDp(marginLevels.collateralReleaseLevel)}
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -24,7 +24,35 @@ query EstimateOrder(
|
|||||||
liquidityFee
|
liquidityFee
|
||||||
}
|
}
|
||||||
marginLevels {
|
marginLevels {
|
||||||
|
market {
|
||||||
|
id
|
||||||
|
state
|
||||||
|
tradableInstrument {
|
||||||
|
instrument {
|
||||||
|
code
|
||||||
|
name
|
||||||
|
}
|
||||||
|
marginCalculator {
|
||||||
|
scalingFactors {
|
||||||
|
searchLevel
|
||||||
|
initialMargin
|
||||||
|
collateralRelease
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
asset {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
party {
|
||||||
|
id
|
||||||
|
}
|
||||||
initialLevel
|
initialLevel
|
||||||
|
searchLevel
|
||||||
|
maintenanceLevel
|
||||||
|
collateralReleaseLevel
|
||||||
|
timestamp
|
||||||
}
|
}
|
||||||
totalFeeAmount
|
totalFeeAmount
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-1
@@ -15,7 +15,7 @@ export type EstimateOrderQueryVariables = Types.Exact<{
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
|
||||||
export type EstimateOrderQuery = { __typename?: 'Query', estimateOrder: { __typename?: 'OrderEstimate', totalFeeAmount: string, fee: { __typename?: 'TradeFee', makerFee: string, infrastructureFee: string, liquidityFee: string }, marginLevels: { __typename?: 'MarginLevels', initialLevel: string } } };
|
export type EstimateOrderQuery = { __typename?: 'Query', estimateOrder: { __typename?: 'OrderEstimate', totalFeeAmount: string, fee: { __typename?: 'TradeFee', makerFee: string, infrastructureFee: string, liquidityFee: string }, marginLevels: { __typename?: 'MarginLevels', initialLevel: string, searchLevel: string, maintenanceLevel: string, collateralReleaseLevel: string, timestamp: any, market: { __typename?: 'Market', id: string, state: Types.MarketState, tradableInstrument: { __typename?: 'TradableInstrument', instrument: { __typename?: 'Instrument', code: string, name: string }, marginCalculator?: { __typename?: 'MarginCalculator', scalingFactors: { __typename?: 'ScalingFactors', searchLevel: number, initialMargin: number, collateralRelease: number } } | null } }, asset: { __typename?: 'Asset', id: string, name: string }, party: { __typename?: 'Party', id: string } } } };
|
||||||
|
|
||||||
|
|
||||||
export const EstimateOrderDocument = gql`
|
export const EstimateOrderDocument = gql`
|
||||||
@@ -36,7 +36,35 @@ export const EstimateOrderDocument = gql`
|
|||||||
liquidityFee
|
liquidityFee
|
||||||
}
|
}
|
||||||
marginLevels {
|
marginLevels {
|
||||||
|
market {
|
||||||
|
id
|
||||||
|
state
|
||||||
|
tradableInstrument {
|
||||||
|
instrument {
|
||||||
|
code
|
||||||
|
name
|
||||||
|
}
|
||||||
|
marginCalculator {
|
||||||
|
scalingFactors {
|
||||||
|
searchLevel
|
||||||
|
initialMargin
|
||||||
|
collateralRelease
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
asset {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
party {
|
||||||
|
id
|
||||||
|
}
|
||||||
initialLevel
|
initialLevel
|
||||||
|
searchLevel
|
||||||
|
maintenanceLevel
|
||||||
|
collateralReleaseLevel
|
||||||
|
timestamp
|
||||||
}
|
}
|
||||||
totalFeeAmount
|
totalFeeAmount
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import { useOrderCloseOut } from './use-order-closeout';
|
|||||||
import { useOrderMargin } from './use-order-margin';
|
import { useOrderMargin } from './use-order-margin';
|
||||||
import type { OrderMargin } from './use-order-margin';
|
import type { OrderMargin } from './use-order-margin';
|
||||||
import { getDerivedPrice } from '../utils/get-price';
|
import { getDerivedPrice } from '../utils/get-price';
|
||||||
|
import { Icon } from '@vegaprotocol/ui-toolkit';
|
||||||
|
import { MarginBreakdown } from '../components/margin-levels/margin-levels';
|
||||||
|
|
||||||
export const useFeeDealTicketDetails = (
|
export const useFeeDealTicketDetails = (
|
||||||
order: OrderSubmissionBody['orderSubmission'],
|
order: OrderSubmissionBody['orderSubmission'],
|
||||||
@@ -148,6 +150,7 @@ export const getFeeDetailsValues = ({
|
|||||||
`An estimate of the most you would be expected to pay in fees, in the market's settlement asset ${assetSymbol}.`
|
`An estimate of the most you would be expected to pay in fees, in the market's settlement asset ${assetSymbol}.`
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<FeesBreakdown
|
<FeesBreakdown
|
||||||
fees={estMargin?.fees}
|
fees={estMargin?.fees}
|
||||||
feeFactors={market.fees.factors}
|
feeFactors={market.fees.factors}
|
||||||
@@ -159,16 +162,31 @@ export const getFeeDetailsValues = ({
|
|||||||
symbol: assetSymbol,
|
symbol: assetSymbol,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('Margin'),
|
label: (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t('Margin')} </span>
|
||||||
|
<Icon name="chevron-down" size={3} />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
value:
|
value:
|
||||||
estMargin?.margin && `~${formatValueWithAssetDp(estMargin?.margin)}`,
|
estMargin?.margin && `~${formatValueWithAssetDp(estMargin?.margin)}`,
|
||||||
symbol: assetSymbol,
|
symbol: assetSymbol,
|
||||||
labelDescription: EST_MARGIN_TOOLTIP_TEXT(assetSymbol),
|
labelDescription: (
|
||||||
|
<>
|
||||||
|
<span>{EST_MARGIN_TOOLTIP_TEXT(assetSymbol)}</span>
|
||||||
|
{/* <span></span>
|
||||||
|
<MarginBreakdown
|
||||||
|
marginLevels={estMargin?.marginLevels}
|
||||||
|
assetDecimalPlaces={assetDecimals}
|
||||||
|
assetSymbol={assetSymbol}
|
||||||
|
/> */}
|
||||||
|
</>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('Liquidation'),
|
label: t('Liquidation'),
|
||||||
value: estCloseOut && `~${formatValueWithMarketDp(estCloseOut)}`,
|
value: estCloseOut && `~${formatValueWithMarketDp(estCloseOut)}`,
|
||||||
symbol: market.tradableInstrument.instrument.product.quoteName,
|
symbol: quoteName,
|
||||||
labelDescription: EST_CLOSEOUT_TOOLTIP_TEXT(quoteName),
|
labelDescription: EST_CLOSEOUT_TOOLTIP_TEXT(quoteName),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { useMarketPositions } from './use-market-positions';
|
|||||||
import { useEstimateOrderQuery } from './__generated__/EstimateOrder';
|
import { useEstimateOrderQuery } from './__generated__/EstimateOrder';
|
||||||
import type { Market, MarketData } from '@vegaprotocol/market-list';
|
import type { Market, MarketData } from '@vegaprotocol/market-list';
|
||||||
import { getDerivedPrice } from '../utils/get-price';
|
import { getDerivedPrice } from '../utils/get-price';
|
||||||
|
import type { MarginLevels } from './use-fee-deal-ticket-details';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
order: OrderSubmissionBody['orderSubmission'];
|
order: OrderSubmissionBody['orderSubmission'];
|
||||||
@@ -23,6 +24,7 @@ export interface OrderMargin {
|
|||||||
liquidityFee: string;
|
liquidityFee: string;
|
||||||
infrastructureFee: string;
|
infrastructureFee: string;
|
||||||
};
|
};
|
||||||
|
marginLevels: MarginLevels;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useOrderMargin = ({
|
export const useOrderMargin = ({
|
||||||
@@ -50,7 +52,12 @@ export const useOrderMargin = ({
|
|||||||
});
|
});
|
||||||
const { makerFee, liquidityFee, infrastructureFee } = data?.estimateOrder
|
const { makerFee, liquidityFee, infrastructureFee } = data?.estimateOrder
|
||||||
.fee || { makerFee: '', liquidityFee: '', infrastructureFee: '' };
|
.fee || { makerFee: '', liquidityFee: '', infrastructureFee: '' };
|
||||||
const { initialLevel } = data?.estimateOrder.marginLevels ?? {};
|
const {
|
||||||
|
initialLevel,
|
||||||
|
searchLevel,
|
||||||
|
maintenanceLevel,
|
||||||
|
collateralReleaseLevel,
|
||||||
|
} = data?.estimateOrder.marginLevels ?? {};
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (initialLevel) {
|
if (initialLevel) {
|
||||||
const margin = BigNumber.maximum(
|
const margin = BigNumber.maximum(
|
||||||
@@ -63,6 +70,12 @@ export const useOrderMargin = ({
|
|||||||
.toString();
|
.toString();
|
||||||
return {
|
return {
|
||||||
margin,
|
margin,
|
||||||
|
marginLevels: {
|
||||||
|
searchLevel,
|
||||||
|
maintenanceLevel,
|
||||||
|
collateralReleaseLevel,
|
||||||
|
initialLevel,
|
||||||
|
},
|
||||||
totalFees: fees,
|
totalFees: fees,
|
||||||
fees: {
|
fees: {
|
||||||
makerFee,
|
makerFee,
|
||||||
@@ -72,5 +85,14 @@ export const useOrderMargin = ({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}, [initialLevel, makerFee, liquidityFee, infrastructureFee, balance]);
|
}, [
|
||||||
|
initialLevel,
|
||||||
|
balance,
|
||||||
|
makerFee,
|
||||||
|
liquidityFee,
|
||||||
|
infrastructureFee,
|
||||||
|
searchLevel,
|
||||||
|
maintenanceLevel,
|
||||||
|
collateralReleaseLevel,
|
||||||
|
]);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user