Ts/client fixes (#471)

* fix bug with marking perp orders as expired

* support passing in perp books to find mango account orders

* support force reloading of acct perp open orders

* make perp market _bids and _asks public

* dont fetch open order accts if no serum3active
This commit is contained in:
tylersssss 2023-02-22 02:07:06 -05:00 committed by GitHub
parent 5c7f23adb1
commit f41f2ab337
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View File

@ -9,7 +9,13 @@ import { toNativeI80F48, toUiDecimals, toUiDecimalsForQuote } from '../utils';
import { Bank, TokenIndex } from './bank'; import { Bank, TokenIndex } from './bank';
import { Group } from './group'; import { Group } from './group';
import { HealthCache } from './healthCache'; import { HealthCache } from './healthCache';
import { PerpMarket, PerpMarketIndex, PerpOrder, PerpOrderSide } from './perp'; import {
BookSide,
PerpMarket,
PerpMarketIndex,
PerpOrder,
PerpOrderSide,
} from './perp';
import { MarketIndex, Serum3Side } from './serum3'; import { MarketIndex, Serum3Side } from './serum3';
export class MangoAccount { export class MangoAccount {
public name: string; public name: string;
@ -588,9 +594,11 @@ export class MangoAccount {
public async loadSerum3OpenOrdersAccounts( public async loadSerum3OpenOrdersAccounts(
client: MangoClient, client: MangoClient,
): Promise<OpenOrders[]> { ): Promise<OpenOrders[]> {
const openOrderPks = this.serum3Active().map((s) => s.openOrders);
if (!openOrderPks.length) return [];
const response = const response =
await client.program.provider.connection.getMultipleAccountsInfo( await client.program.provider.connection.getMultipleAccountsInfo(
this.serum3Active().map((s) => s.openOrders), openOrderPks,
); );
const accounts = response.filter((a): a is AccountInfo<Buffer> => const accounts = response.filter((a): a is AccountInfo<Buffer> =>
Boolean(a), Boolean(a),
@ -940,15 +948,16 @@ export class MangoAccount {
client: MangoClient, client: MangoClient,
group: Group, group: Group,
perpMarketIndex: PerpMarketIndex, perpMarketIndex: PerpMarketIndex,
forceReload?: boolean,
): Promise<PerpOrder[]> { ): Promise<PerpOrder[]> {
const perpMarket = group.getPerpMarketByMarketIndex(perpMarketIndex); const perpMarket = group.getPerpMarketByMarketIndex(perpMarketIndex);
const [bids, asks] = await Promise.all([ const [bids, asks] = await Promise.all([
perpMarket.loadBids(client), perpMarket.loadBids(client, forceReload),
perpMarket.loadAsks(client), perpMarket.loadAsks(client, forceReload),
]); ]);
return [...Array.from(bids.items()), ...Array.from(asks.items())].filter( return [...bids.items(), ...asks.items()].filter((order) =>
(order) => order.owner.equals(this.publicKey), order.owner.equals(this.publicKey),
); );
} }

View File

@ -49,14 +49,13 @@ export class PerpMarket {
public _price: I80F48; public _price: I80F48;
public _uiPrice: number; public _uiPrice: number;
public _oracleLastUpdatedSlot: number; public _oracleLastUpdatedSlot: number;
public _bids: BookSide;
public _asks: BookSide;
private priceLotsToUiConverter: number; private priceLotsToUiConverter: number;
private baseLotsToUiConverter: number; private baseLotsToUiConverter: number;
private quoteLotsToUiConverter: number; private quoteLotsToUiConverter: number;
private _bids: BookSide;
private _asks: BookSide;
static from( static from(
publicKey: PublicKey, publicKey: PublicKey,
obj: { obj: {
@ -683,7 +682,7 @@ export class BookSide {
this.perpMarket, this.perpMarket,
leafNode, leafNode,
this.type, this.type,
now.lt(expiryTimestamp), now.gt(expiryTimestamp),
); );
} }
} }
@ -713,7 +712,7 @@ export class BookSide {
this.perpMarket, this.perpMarket,
leafNode, leafNode,
this.type, this.type,
now.lt(expiryTimestamp), now.gt(expiryTimestamp),
true, true,
); );
} }