Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make reload in open orders also reload the orderbook #264

Merged
merged 3 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading