diff --git a/libs/deal-ticket/src/hooks/use-order-closeout.spec.tsx b/libs/deal-ticket/src/hooks/use-order-closeout.spec.tsx index df16ea2ad..d7d843a3e 100644 --- a/libs/deal-ticket/src/hooks/use-order-closeout.spec.tsx +++ b/libs/deal-ticket/src/hooks/use-order-closeout.spec.tsx @@ -74,6 +74,26 @@ describe('useOrderCloseOut', () => { 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', () => { const { result } = renderHook( () => diff --git a/libs/deal-ticket/src/hooks/use-order-closeout.ts b/libs/deal-ticket/src/hooks/use-order-closeout.ts index f6f6dd32d..05ee81dba 100644 --- a/libs/deal-ticket/src/hooks/use-order-closeout.ts +++ b/libs/deal-ticket/src/hooks/use-order-closeout.ts @@ -40,14 +40,17 @@ export const useOrderCloseOut = ({ order, market }: Props): string | null => { const volume = new BigNumber( addDecimal(openVolume || '0', market.positionDecimalPlaces) )[order.side === Schema.Side.SIDE_BUY ? 'plus' : 'minus'](order.size); - const markPrice = new BigNumber( - addDecimal(market.data.markPrice || 0, market.decimalPlaces || 0) - ); + const price = + order.type === Schema.OrderType.TYPE_LIMIT && order.price + ? new BigNumber(order.price) + : new BigNumber( + addDecimal(market.data.markPrice || 0, market.decimalPlaces || 0) + ); // regarding formula (marginMaintenanceLevel - positionAccountBalance - generalAccountBalance) / volume + markPrice const marginDifference = marginMaintenanceLevel .minus(positionAccountBalance) .minus(generalAccountBalance); - const closeOut = marginDifference.div(volume).plus(markPrice); + const closeOut = marginDifference.div(volume).plus(price); if (closeOut.isPositive()) { return closeOut.toString(); }