parsed trade history for perps

This commit is contained in:
Tyler Shipe 2021-06-24 16:57:11 -04:00
parent d44e6476b4
commit 619295d2e0
7 changed files with 43 additions and 43 deletions

View File

@ -96,7 +96,6 @@ export default function Orderbook({ depth = 8 }) {
const marketConfig = useMangoStore((s) => s.selectedMarket.config)
const orderbook = useMangoStore((s) => s.selectedMarket.orderBook)
const markPrice = useMarkPrice()
console.log('mark price', markPrice)
const currentOrderbookData = useRef(null)
const lastOrderbookData = useRef(null)

View File

@ -216,7 +216,7 @@ export default function TradeForm() {
const orderType = ioc ? 'ioc' : postOnly ? 'postOnly' : 'limit'
if (market instanceof Market) {
mangoClient.placeSpotOrder(
await mangoClient.placeSpotOrder(
mangoGroup,
mangoAccount,
mangoGroup.mangoCache,
@ -228,7 +228,7 @@ export default function TradeForm() {
orderType
)
} else {
mangoClient.placePerpOrder(
await mangoClient.placePerpOrder(
mangoGroup,
mangoAccount,
mangoGroup.mangoCache,

View File

@ -198,7 +198,7 @@ const TradeHistoryTable = () => {
<Tbody>
{items.map((trade, index) => (
<Tr
key={`${trade.orderId}${trade.side}${trade.uuid}`}
key={`${trade.price}${trade.side}${trade.uuid}`}
className={`border-b border-th-bkg-3
${index % 2 === 0 ? `bg-th-bkg-3` : `bg-th-bkg-2`}
`}

View File

@ -6,36 +6,24 @@ const byTimestamp = (a, b) => {
)
}
const parsedPerpEvent = (trade) => {
let side
if (trade.maker) {
side = trade.quoteChange === 0 ? 'buy' : 'sell'
} else {
side = trade.quoteChange === 0 ? 'sell' : 'buy'
}
const parsedPerpEvent = (event) => {
return {
...trade,
marketName: trade.marketName
? trade.marketName
: `${trade.baseCurrency}/${trade.quoteCurrency}`,
key: `${trade.orderId}-${trade.uuid}`,
liquidity: trade.maker,
value: trade.price * trade.size,
side,
...event,
key: `${event.orderId}-${event.uuid}`,
liquidity: event.maker ? 'Maker' : 'Taker',
value: event.price * event.size,
side: event.side,
feeCost: 0.0,
}
}
const parsedSerumEvent = (trade) => {
const parsedSerumEvent = (event) => {
return {
...trade,
marketName: trade.marketName
? trade.marketName
: `${trade.baseCurrency}/${trade.quoteCurrency}`,
key: `${trade.orderId}-${trade.uuid}`,
liquidity: trade.maker || trade?.eventFlags?.maker ? 'Maker' : 'Taker',
value: trade.price * trade.size,
side: trade.side,
...event,
key: `${event.maker}-${event.price}`,
liquidity: event?.eventFlags?.maker ? 'Maker' : 'Taker',
value: event.price * event.size,
side: event.side,
}
}
@ -66,7 +54,7 @@ export const useTradeHistory = () => {
const mangoAccountFills = fills
.filter((fill) => {
if (fill.eventFlags) {
if (fill.openOrders) {
return fill.openOrders.equals(openOrdersAccount.publicKey)
} else {
return fill.owner.equals(mangoAccount.publicKey)

View File

@ -31,7 +31,7 @@
}
},
"dependencies": {
"@blockworks-foundation/mango-client": "git+https://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:x-oauth-basic@github.com/blockworks-foundation/mango-client-v3.git#dd/megamerge",
"@blockworks-foundation/mango-client": "git+https://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:x-oauth-basic@github.com/blockworks-foundation/mango-client-v3.git",
"@emotion/react": "^11.1.5",
"@emotion/styled": "^11.1.5",
"@headlessui/react": "^1.2.0",

View File

@ -199,7 +199,7 @@ const useMangoStore = create<MangoStore>((set, get) => ({
mangoAccounts: [],
selectedMangoAccount: {
current: null,
initialLoad: false,
initialLoad: true,
},
tradeForm: {
side: 'buy',
@ -247,18 +247,11 @@ const useMangoStore = create<MangoStore>((set, get) => ({
},
async fetchMangoAccounts() {
const mangoGroup = get().selectedMangoGroup.current
const selectedMarginAcount = get().selectedMangoAccount.current
const wallet = get().wallet.current
const set = get().set
if (!wallet?.publicKey || !wallet.publicKey) return
if (!selectedMarginAcount) {
set((state) => {
state.selectedMangoAccount.initialLoad = true
})
}
return mangoClient
.getMarginAccountsForOwner(mangoGroup, wallet.publicKey, true)
.then((mangoAccounts) => {

View File

@ -986,9 +986,9 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@blockworks-foundation/mango-client@git+https://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:x-oauth-basic@github.com/blockworks-foundation/mango-client-v3.git#dd/megamerge":
version "3.0.0"
resolved "git+https://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:x-oauth-basic@github.com/blockworks-foundation/mango-client-v3.git#19b5d59c20351eb5fbaff14e2e8074c1fac1ce05"
"@blockworks-foundation/mango-client@git+https://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:x-oauth-basic@github.com/blockworks-foundation/mango-client-v3.git":
version "3.0.1"
resolved "git+https://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:x-oauth-basic@github.com/blockworks-foundation/mango-client-v3.git#c749b362dec7c2f60de1154d7167c0f6032d6999"
dependencies:
"@project-serum/serum" "^0.13.38"
"@project-serum/sol-wallet-adapter" "^0.2.0"
@ -1543,7 +1543,27 @@
tweetnacl "^1.0.0"
ws "^7.0.0"
"@solana/web3.js@^1.12.0", "@solana/web3.js@^1.18.0":
"@solana/web3.js@^1.12.0":
version "1.19.0"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.19.0.tgz#b4f0153844a137d03a23b03e478138c1deada232"
integrity sha512-tZ+Bk0sD6xvyHas13eRTl0fOtWGHoKithNjIHHYeUbZWwdxOKdutfv14SuD1eqkBdoiQs3KFJvVUkj3M7zTVDg==
dependencies:
"@babel/runtime" "^7.12.5"
bn.js "^5.0.0"
borsh "^0.4.0"
bs58 "^4.0.1"
buffer "6.0.1"
buffer-layout "^1.2.0"
crypto-hash "^1.2.2"
jayson "^3.4.4"
js-sha3 "^0.8.0"
node-fetch "^2.6.1"
rpc-websockets "^7.4.2"
secp256k1 "^4.0.2"
superstruct "^0.14.2"
tweetnacl "^1.0.0"
"@solana/web3.js@^1.18.0":
version "1.18.0"
resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.18.0.tgz#f4c422a843aa57a1366d98b06cb6b45441644d59"
integrity sha512-ijAoRd4Sje1QYoPAwDr7KYlDK40FE7tAUa2V3wT4PGKatWf4ETDXoyYlW89J6vrqOT+mV3GUuaVC76tOFlrXyA==