fix trade history
This commit is contained in:
parent
cf7cf1c037
commit
a0c24f11c5
|
@ -30,7 +30,7 @@ const byTimestamp = (a: any, b: any) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const reverseSide = (side: string) => (side === 'buy' ? 'sell' : 'buy')
|
const reverseSide = (side: string) => (side === 'long' ? 'short' : 'long')
|
||||||
|
|
||||||
const parsedPerpEvent = (mangoAccountAddress: string, event: any) => {
|
const parsedPerpEvent = (mangoAccountAddress: string, event: any) => {
|
||||||
const maker = event.maker.toString() === mangoAccountAddress
|
const maker = event.maker.toString() === mangoAccountAddress
|
||||||
|
@ -39,7 +39,8 @@ const parsedPerpEvent = (mangoAccountAddress: string, event: any) => {
|
||||||
const feeRate = maker
|
const feeRate = maker
|
||||||
? new I80F48(event.makerFee.val)
|
? new I80F48(event.makerFee.val)
|
||||||
: new I80F48(event.takerFee.val)
|
: new I80F48(event.takerFee.val)
|
||||||
const side = maker ? reverseSide(event.takerSide) : event.takerSide
|
const takerSide = event.takerSide === 0 ? 'long' : 'short'
|
||||||
|
const side = maker ? reverseSide(takerSide) : takerSide
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...event,
|
...event,
|
||||||
|
@ -145,16 +146,13 @@ const TradeHistory = () => {
|
||||||
const combinedTradeHistory = useMemo(() => {
|
const combinedTradeHistory = useMemo(() => {
|
||||||
let newFills = []
|
let newFills = []
|
||||||
if (eventQueueFillsForAccount?.length) {
|
if (eventQueueFillsForAccount?.length) {
|
||||||
console.log('eventQueueFillsForAccount', eventQueueFillsForAccount)
|
|
||||||
|
|
||||||
newFills = eventQueueFillsForAccount.filter((fill) => {
|
newFills = eventQueueFillsForAccount.filter((fill) => {
|
||||||
return !tradeHistory.find((t) => {
|
return !tradeHistory.find((t) => {
|
||||||
if (t.order_id) {
|
if ('order_id' in t) {
|
||||||
return t.order_id === fill.orderId?.toString()
|
return t.order_id === fill.orderId?.toString()
|
||||||
|
} else {
|
||||||
|
return t.seq_num === fill.seqNum?.toNumber()
|
||||||
}
|
}
|
||||||
// else {
|
|
||||||
// return t.seq_num === fill.seqNum?.toString()
|
|
||||||
// }
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -245,7 +243,7 @@ const TradeHistory = () => {
|
||||||
{formatDecimal(trade.price)}
|
{formatDecimal(trade.price)}
|
||||||
</Td>
|
</Td>
|
||||||
<Td className="text-right font-mono">
|
<Td className="text-right font-mono">
|
||||||
${formatFixedDecimals(trade.price * size, true)}
|
{formatFixedDecimals(trade.price * size, true)}
|
||||||
</Td>
|
</Td>
|
||||||
<Td className="text-right">
|
<Td className="text-right">
|
||||||
<span className="font-mono">{formatDecimal(fee)}</span>
|
<span className="font-mono">{formatDecimal(fee)}</span>
|
||||||
|
|
|
@ -38,7 +38,12 @@ import {
|
||||||
PAGINATION_PAGE_LENGTH,
|
PAGINATION_PAGE_LENGTH,
|
||||||
RPC_PROVIDER_KEY,
|
RPC_PROVIDER_KEY,
|
||||||
} from '../utils/constants'
|
} from '../utils/constants'
|
||||||
import { OrderbookL2, SpotBalances, SpotTradeHistory } from 'types'
|
import {
|
||||||
|
OrderbookL2,
|
||||||
|
PerpTradeHistory,
|
||||||
|
SpotBalances,
|
||||||
|
SpotTradeHistory,
|
||||||
|
} from 'types'
|
||||||
import spotBalancesUpdater from './spotBalancesUpdater'
|
import spotBalancesUpdater from './spotBalancesUpdater'
|
||||||
import { PerpMarket } from '@blockworks-foundation/mango-v4/'
|
import { PerpMarket } from '@blockworks-foundation/mango-v4/'
|
||||||
import perpPositionsUpdater from './perpPositionsUpdater'
|
import perpPositionsUpdater from './perpPositionsUpdater'
|
||||||
|
@ -72,7 +77,7 @@ const emptyWallet = new EmptyWallet(Keypair.generate())
|
||||||
const initMangoClient = (provider: AnchorProvider): MangoClient => {
|
const initMangoClient = (provider: AnchorProvider): MangoClient => {
|
||||||
return MangoClient.connect(provider, CLUSTER, MANGO_V4_ID[CLUSTER], {
|
return MangoClient.connect(provider, CLUSTER, MANGO_V4_ID[CLUSTER], {
|
||||||
// blockhashCommitment: 'confirmed',
|
// blockhashCommitment: 'confirmed',
|
||||||
prioritizationFee: 10000,
|
prioritizationFee: 50000,
|
||||||
idsSource: 'get-program-accounts',
|
idsSource: 'get-program-accounts',
|
||||||
postSendTxCallback: ({ txid }: { txid: string }) => {
|
postSendTxCallback: ({ txid }: { txid: string }) => {
|
||||||
notify({
|
notify({
|
||||||
|
@ -252,7 +257,10 @@ export type MangoStore = {
|
||||||
data: SwapHistoryItem[]
|
data: SwapHistoryItem[]
|
||||||
initialLoad: boolean
|
initialLoad: boolean
|
||||||
}
|
}
|
||||||
tradeHistory: { data: SpotTradeHistory[]; loading: boolean }
|
tradeHistory: {
|
||||||
|
data: Array<SpotTradeHistory | PerpTradeHistory>
|
||||||
|
loading: boolean
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mangoAccounts: MangoAccount[]
|
mangoAccounts: MangoAccount[]
|
||||||
markets: Serum3Market[] | undefined
|
markets: Serum3Market[] | undefined
|
||||||
|
|
|
@ -47,4 +47,23 @@ export interface SpotTradeHistory {
|
||||||
quote_symbol: string
|
quote_symbol: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PerpTradeHistory {
|
||||||
|
signature: string
|
||||||
|
slot: number
|
||||||
|
block_datetime: string
|
||||||
|
maker: string
|
||||||
|
maker_order_id: string
|
||||||
|
maker_fee: number
|
||||||
|
taker: string
|
||||||
|
taker_order_id: string
|
||||||
|
taker_client_order_id: string
|
||||||
|
taker_fee: number
|
||||||
|
taker_side: string
|
||||||
|
perp_market: string
|
||||||
|
market_index: number
|
||||||
|
price: number
|
||||||
|
quantity: number
|
||||||
|
seq_num: number
|
||||||
|
}
|
||||||
|
|
||||||
export type GenericMarket = Serum3Market | PerpMarket
|
export type GenericMarket = Serum3Market | PerpMarket
|
||||||
|
|
Loading…
Reference in New Issue