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:
parent
5c7f23adb1
commit
f41f2ab337
|
@ -9,7 +9,13 @@ import { toNativeI80F48, toUiDecimals, toUiDecimalsForQuote } from '../utils';
|
|||
import { Bank, TokenIndex } from './bank';
|
||||
import { Group } from './group';
|
||||
import { HealthCache } from './healthCache';
|
||||
import { PerpMarket, PerpMarketIndex, PerpOrder, PerpOrderSide } from './perp';
|
||||
import {
|
||||
BookSide,
|
||||
PerpMarket,
|
||||
PerpMarketIndex,
|
||||
PerpOrder,
|
||||
PerpOrderSide,
|
||||
} from './perp';
|
||||
import { MarketIndex, Serum3Side } from './serum3';
|
||||
export class MangoAccount {
|
||||
public name: string;
|
||||
|
@ -588,9 +594,11 @@ export class MangoAccount {
|
|||
public async loadSerum3OpenOrdersAccounts(
|
||||
client: MangoClient,
|
||||
): Promise<OpenOrders[]> {
|
||||
const openOrderPks = this.serum3Active().map((s) => s.openOrders);
|
||||
if (!openOrderPks.length) return [];
|
||||
const response =
|
||||
await client.program.provider.connection.getMultipleAccountsInfo(
|
||||
this.serum3Active().map((s) => s.openOrders),
|
||||
openOrderPks,
|
||||
);
|
||||
const accounts = response.filter((a): a is AccountInfo<Buffer> =>
|
||||
Boolean(a),
|
||||
|
@ -940,15 +948,16 @@ export class MangoAccount {
|
|||
client: MangoClient,
|
||||
group: Group,
|
||||
perpMarketIndex: PerpMarketIndex,
|
||||
forceReload?: boolean,
|
||||
): Promise<PerpOrder[]> {
|
||||
const perpMarket = group.getPerpMarketByMarketIndex(perpMarketIndex);
|
||||
const [bids, asks] = await Promise.all([
|
||||
perpMarket.loadBids(client),
|
||||
perpMarket.loadAsks(client),
|
||||
perpMarket.loadBids(client, forceReload),
|
||||
perpMarket.loadAsks(client, forceReload),
|
||||
]);
|
||||
|
||||
return [...Array.from(bids.items()), ...Array.from(asks.items())].filter(
|
||||
(order) => order.owner.equals(this.publicKey),
|
||||
return [...bids.items(), ...asks.items()].filter((order) =>
|
||||
order.owner.equals(this.publicKey),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,14 +49,13 @@ export class PerpMarket {
|
|||
public _price: I80F48;
|
||||
public _uiPrice: number;
|
||||
public _oracleLastUpdatedSlot: number;
|
||||
public _bids: BookSide;
|
||||
public _asks: BookSide;
|
||||
|
||||
private priceLotsToUiConverter: number;
|
||||
private baseLotsToUiConverter: number;
|
||||
private quoteLotsToUiConverter: number;
|
||||
|
||||
private _bids: BookSide;
|
||||
private _asks: BookSide;
|
||||
|
||||
static from(
|
||||
publicKey: PublicKey,
|
||||
obj: {
|
||||
|
@ -683,7 +682,7 @@ export class BookSide {
|
|||
this.perpMarket,
|
||||
leafNode,
|
||||
this.type,
|
||||
now.lt(expiryTimestamp),
|
||||
now.gt(expiryTimestamp),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -713,7 +712,7 @@ export class BookSide {
|
|||
this.perpMarket,
|
||||
leafNode,
|
||||
this.type,
|
||||
now.lt(expiryTimestamp),
|
||||
now.gt(expiryTimestamp),
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue