Skip to content

Commit

Permalink
Make reload in open orders also reload the orderbook (#264)
Browse files Browse the repository at this point in the history
* Make reload in open orders also reload the orderbook

* add await

* Fetch all at the same slot at once
  • Loading branch information
brittcyr authored May 17, 2024
1 parent 2289b95 commit db28205
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 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,10 +97,33 @@ 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. 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 db28205

Please sign in to comment.