From db28205489fccdd4694151d23edf40a42b8c1b96 Mon Sep 17 00:00:00 2001 From: Britt Cyr Date: Fri, 17 May 2024 10:52:46 -0400 Subject: [PATCH] Make reload in open orders also reload the orderbook (#264) * Make reload in open orders also reload the orderbook * add await * Fetch all at the same slot at once --- ts/client/src/accounts/openOrders.ts | 32 ++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/ts/client/src/accounts/openOrders.ts b/ts/client/src/accounts/openOrders.ts index 375ef36da..5dbc1be4b 100644 --- a/ts/client/src/accounts/openOrders.ts +++ b/ts/client/src/accounts/openOrders.ts @@ -24,6 +24,7 @@ import { Order, OpenOrdersIndexer, Market, + BookSide, } from '..'; export interface OrderToPlace { @@ -96,10 +97,33 @@ export class OpenOrders { } public async reload(): Promise { - this.account = - await this.market.client.program.account.openOrdersAccount.fetch( - this.pubkey, - ); + // Need to reload orderbooks because not all information about orders, like + // size, is stored on the open orders account. Do all fetches together to + // ensure they are synced to the same slot. + const [bidsAi, asksAi, ooAi] = await this.market.client.connection.getMultipleAccountsInfo( + [ + this.market.account.bids, + this.market.account.asks, + this.pubkey, + ] + ); + this.market.bids = new BookSide( + this.market, + this.market.account.bids, + BookSide.decodeAccountfromBuffer(bidsAi!.data), + SideUtils.Bid + ); + this.market.asks = new BookSide( + this.market, + this.market.account.asks, + BookSide.decodeAccountfromBuffer(asksAi!.data), + SideUtils.Ask + ); + this.account = this.market.client.program.coder.accounts.decode( + "openOrdersAccount", + ooAi!.data + ); + return this; }