diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index 8a715483c..eebac353d 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -329,6 +329,16 @@ export class OpenBookV2Client { return await this.sendAndConfirmTransaction([ix]); } + public async getOrCreateOpenOrders(market: PublicKey, accountIndex: BN, name: string): Promise { + const openOrders = this.findOpenOrders(market, accountIndex); + + if ((await this.connection.getAccountInfo(openOrders)) != null) { + return openOrders; + } + + return await this.createOpenOrders(market, accountIndex, name); + } + public findOpenOrders(market: PublicKey, accountIndex: BN): PublicKey { const [openOrders] = PublicKey.findProgramAddressSync( [