From 4fc2b42f9967326caa0d5694e2d6478ef4e87ed6 Mon Sep 17 00:00:00 2001 From: tjs Date: Thu, 8 Dec 2022 14:00:12 -0500 Subject: [PATCH] add back function to parse perp fill events --- ts/client/src/accounts/perp.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ts/client/src/accounts/perp.ts b/ts/client/src/accounts/perp.ts index 6c5730c1b..bb412622b 100644 --- a/ts/client/src/accounts/perp.ts +++ b/ts/client/src/accounts/perp.ts @@ -4,6 +4,7 @@ import { PublicKey } from '@solana/web3.js'; import Big from 'big.js'; import { MangoClient } from '../client'; import { I80F48, I80F48Dto, ZERO_I80F48 } from '../numbers/I80F48'; +import { Modify } from '../types'; import { As, toNative, U64_MAX_BN } from '../utils'; import { OracleConfig, @@ -17,6 +18,14 @@ import { MangoAccount } from './mangoAccount'; export type PerpMarketIndex = number & As<'perp-market-index'>; +export type ParsedFillEvent = Modify< + FillEvent, + { + price: number; + quantity: number; + } +>; + export class PerpMarket { public name: string; public oracleConfig: OracleConfig; @@ -264,12 +273,25 @@ export class PerpMarket { public async loadFills( client: MangoClient, - lastSeqNum: BN, + lastSeqNum: BN = new BN(0), ): Promise<(OutEvent | FillEvent | LiquidateEvent)[]> { const eventQueue = await this.loadEventQueue(client); return eventQueue .eventsSince(lastSeqNum) - .filter((event) => event.eventType == PerpEventQueue.FILL_EVENT_TYPE); + .filter((event) => event.eventType == PerpEventQueue.FILL_EVENT_TYPE) + .map(this.parseFillEvent.bind(this)) as ParsedFillEvent[]; + } + + public parseFillEvent(event): ParsedFillEvent { + const quantity = this.baseLotsToUi(event.quantity); + const price = this.priceLotsToUi(event.price); + + return { + ...event, + quantity, + size: quantity, + price, + }; } public async logOb(client: MangoClient): Promise {