use estimatedSize in fee estimation; use price of 1 for mkt close orders
This commit is contained in:
parent
9cb4ccf519
commit
3d274e64d7
|
@ -4,7 +4,7 @@ import { PerpMarket, ZERO_BN } from '@blockworks-foundation/mango-client'
|
|||
import Button, { LinkButton } from './Button'
|
||||
import { notify } from '../utils/notifications'
|
||||
import Loading from './Loading'
|
||||
import { calculateTradePrice, sleep } from '../utils'
|
||||
import { sleep } from '../utils'
|
||||
import Modal from './Modal'
|
||||
|
||||
interface MarketCloseModalProps {
|
||||
|
@ -26,7 +26,6 @@ const MarketCloseModal: FunctionComponent<MarketCloseModalProps> = ({
|
|||
const orderBookRef = useRef(useMangoStore.getState().selectedMarket.orderBook)
|
||||
const config = useMangoStore.getState().selectedMarket.config
|
||||
|
||||
const orderbook = orderBookRef.current
|
||||
useEffect(
|
||||
() =>
|
||||
useMangoStore.subscribe(
|
||||
|
@ -49,26 +48,11 @@ const MarketCloseModal: FunctionComponent<MarketCloseModalProps> = ({
|
|||
try {
|
||||
const perpAccount = mangoAccount.perpAccounts[marketIndex]
|
||||
const side = perpAccount.basePosition.gt(ZERO_BN) ? 'sell' : 'buy'
|
||||
const price = 1
|
||||
// send a large size to ensure we are reducing the entire position
|
||||
const size =
|
||||
Math.abs(market.baseLotsToNumber(perpAccount.basePosition)) * 2
|
||||
|
||||
const orderPrice = calculateTradePrice(
|
||||
'Market',
|
||||
orderbook,
|
||||
size,
|
||||
side,
|
||||
''
|
||||
)
|
||||
|
||||
if (!orderPrice) {
|
||||
notify({
|
||||
title: 'Price not available',
|
||||
description: 'Please try again',
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
const txid = await mangoClient.placePerpOrder(
|
||||
mangoGroup,
|
||||
mangoAccount,
|
||||
|
@ -76,7 +60,7 @@ const MarketCloseModal: FunctionComponent<MarketCloseModalProps> = ({
|
|||
market,
|
||||
wallet,
|
||||
side,
|
||||
orderPrice,
|
||||
price,
|
||||
size,
|
||||
'market',
|
||||
0, // client order id
|
||||
|
|
|
@ -59,7 +59,7 @@ const PositionsTable = () => {
|
|||
<div className="flex flex-col pb-2 pt-4">
|
||||
{unsettledPositions.length > 0 ? (
|
||||
<div className="border border-th-bkg-4 rounded-lg mb-6 p-4 sm:p-6">
|
||||
<div className="flex items-center justify-between pb-4">
|
||||
<div className="flex items-center justify-between pb-2">
|
||||
<div className="flex items-center sm:text-lg">
|
||||
<ExclamationIcon className="flex-shrink-0 h-5 mr-1.5 mt-0.5 text-th-primary w-5" />
|
||||
Unsettled Positions
|
||||
|
|
|
@ -448,7 +448,9 @@ export default function AdvancedTradeForm({
|
|||
const slippageRel = slippageAbs / markPrice
|
||||
|
||||
const takerFeeRel = takerFee
|
||||
const takerFeeAbs = takerFeeRel * estimatedPrice
|
||||
const takerFeeAbs = estimatedSize
|
||||
? takerFeeRel * estimatedPrice * estimatedSize
|
||||
: 0
|
||||
|
||||
priceImpact = {
|
||||
slippage: [slippageAbs, slippageRel],
|
||||
|
|
Loading…
Reference in New Issue