add back function to parse perp fill events
This commit is contained in:
parent
3e7f5487b7
commit
4fc2b42f99
|
@ -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<string> {
|
||||
|
|
Loading…
Reference in New Issue