fix: liquidation est. should update on price change (#2649)
* fix: liquidation close out price needs to update when price updates on limit orders * fix(#2624): add test case on limit sell order
This commit is contained in:
parent
2640b7d77d
commit
2a9f3c7568
@ -74,6 +74,26 @@ describe('useOrderCloseOut', () => {
|
|||||||
expect(result.current).toEqual('1');
|
expect(result.current).toEqual('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return proper sell value on limit order', () => {
|
||||||
|
mockMarketMargin = '0';
|
||||||
|
const { result } = renderHook(
|
||||||
|
() =>
|
||||||
|
useOrderCloseOut({
|
||||||
|
order: {
|
||||||
|
...order,
|
||||||
|
price: '1000000',
|
||||||
|
type: 'TYPE_LIMIT',
|
||||||
|
side: 'SIDE_SELL',
|
||||||
|
} as OrderSubmissionBody['orderSubmission'],
|
||||||
|
market: market,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
wrapper: MockedProvider,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
expect(result.current).toEqual('1000000');
|
||||||
|
});
|
||||||
|
|
||||||
it('should return proper empty value', () => {
|
it('should return proper empty value', () => {
|
||||||
const { result } = renderHook(
|
const { result } = renderHook(
|
||||||
() =>
|
() =>
|
||||||
|
@ -40,14 +40,17 @@ export const useOrderCloseOut = ({ order, market }: Props): string | null => {
|
|||||||
const volume = new BigNumber(
|
const volume = new BigNumber(
|
||||||
addDecimal(openVolume || '0', market.positionDecimalPlaces)
|
addDecimal(openVolume || '0', market.positionDecimalPlaces)
|
||||||
)[order.side === Schema.Side.SIDE_BUY ? 'plus' : 'minus'](order.size);
|
)[order.side === Schema.Side.SIDE_BUY ? 'plus' : 'minus'](order.size);
|
||||||
const markPrice = new BigNumber(
|
const price =
|
||||||
|
order.type === Schema.OrderType.TYPE_LIMIT && order.price
|
||||||
|
? new BigNumber(order.price)
|
||||||
|
: new BigNumber(
|
||||||
addDecimal(market.data.markPrice || 0, market.decimalPlaces || 0)
|
addDecimal(market.data.markPrice || 0, market.decimalPlaces || 0)
|
||||||
);
|
);
|
||||||
// regarding formula (marginMaintenanceLevel - positionAccountBalance - generalAccountBalance) / volume + markPrice
|
// regarding formula (marginMaintenanceLevel - positionAccountBalance - generalAccountBalance) / volume + markPrice
|
||||||
const marginDifference = marginMaintenanceLevel
|
const marginDifference = marginMaintenanceLevel
|
||||||
.minus(positionAccountBalance)
|
.minus(positionAccountBalance)
|
||||||
.minus(generalAccountBalance);
|
.minus(generalAccountBalance);
|
||||||
const closeOut = marginDifference.div(volume).plus(markPrice);
|
const closeOut = marginDifference.div(volume).plus(price);
|
||||||
if (closeOut.isPositive()) {
|
if (closeOut.isPositive()) {
|
||||||
return closeOut.toString();
|
return closeOut.toString();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user