From 4368b79c03e9f41733ced31477c650248ca24430 Mon Sep 17 00:00:00 2001 From: tjs Date: Tue, 1 Nov 2022 17:19:19 +0000 Subject: [PATCH] cancel perp order client fn --- ts/client/src/client.ts | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index 6eef4d8dd..d20ab1e0e 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -1683,6 +1683,49 @@ export class MangoClient { .instruction(); } + public async perpCancelOrderIx( + group: Group, + mangoAccount: MangoAccount, + perpMarketIndex: PerpMarketIndex, + orderId: number, + ): Promise { + const perpMarket = group.getPerpMarketByMarketIndex(perpMarketIndex); + return await this.program.methods + .perpCancelOrder(new BN(orderId)) + .accounts({ + group: group.publicKey, + account: mangoAccount.publicKey, + owner: (this.program.provider as AnchorProvider).wallet.publicKey, + perpMarket: perpMarket.publicKey, + asks: perpMarket.asks, + bids: perpMarket.bids, + }) + .instruction(); + } + + public async perpCancelOrder( + group: Group, + mangoAccount: MangoAccount, + perpMarketIndex: PerpMarketIndex, + orderId: number, + ): Promise { + return await sendTransaction( + this.program.provider as AnchorProvider, + [ + await this.perpCancelOrderIx( + group, + mangoAccount, + perpMarketIndex, + orderId, + ), + ], + group.addressLookupTablesList, + { + postSendTxCallback: this.postSendTxCallback, + }, + ); + } + public async perpCancelAllOrders( group: Group, mangoAccount: MangoAccount,