add back function to parse perp fill events

This commit is contained in:
tjs 2022-12-08 14:00:12 -05:00
parent 3e7f5487b7
commit 4fc2b42f99
1 changed files with 24 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import { PublicKey } from '@solana/web3.js';
import Big from 'big.js'; import Big from 'big.js';
import { MangoClient } from '../client'; import { MangoClient } from '../client';
import { I80F48, I80F48Dto, ZERO_I80F48 } from '../numbers/I80F48'; import { I80F48, I80F48Dto, ZERO_I80F48 } from '../numbers/I80F48';
import { Modify } from '../types';
import { As, toNative, U64_MAX_BN } from '../utils'; import { As, toNative, U64_MAX_BN } from '../utils';
import { import {
OracleConfig, OracleConfig,
@ -17,6 +18,14 @@ import { MangoAccount } from './mangoAccount';
export type PerpMarketIndex = number & As<'perp-market-index'>; export type PerpMarketIndex = number & As<'perp-market-index'>;
export type ParsedFillEvent = Modify<
FillEvent,
{
price: number;
quantity: number;
}
>;
export class PerpMarket { export class PerpMarket {
public name: string; public name: string;
public oracleConfig: OracleConfig; public oracleConfig: OracleConfig;
@ -264,12 +273,25 @@ export class PerpMarket {
public async loadFills( public async loadFills(
client: MangoClient, client: MangoClient,
lastSeqNum: BN, lastSeqNum: BN = new BN(0),
): Promise<(OutEvent | FillEvent | LiquidateEvent)[]> { ): Promise<(OutEvent | FillEvent | LiquidateEvent)[]> {
const eventQueue = await this.loadEventQueue(client); const eventQueue = await this.loadEventQueue(client);
return eventQueue return eventQueue
.eventsSince(lastSeqNum) .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<string> { public async logOb(client: MangoClient): Promise<string> {