Skip to content

Commit

Permalink
Fetch all at the same slot at once
Browse files Browse the repository at this point in the history
  • Loading branch information
brittcyr committed May 16, 2024
1 parent da1c113 commit 37d1531
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions ts/client/src/accounts/openOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
Order,
OpenOrdersIndexer,
Market,
BookSide,
} from '..';

export interface OrderToPlace {
Expand Down Expand Up @@ -96,14 +97,32 @@ export class OpenOrders {
}

public async reload(): Promise<this> {
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.
await this.market.loadOrderBook();
// 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;
}
Expand Down

0 comments on commit 37d1531

Please sign in to comment.