From 939a31e771425b44686c0f0c1de933bf6adaefa2 Mon Sep 17 00:00:00 2001 From: Lou-Kamades Date: Sat, 30 Dec 2023 13:50:29 -0600 Subject: [PATCH] add cancel functions to rust client --- lib/client/src/client.rs | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/lib/client/src/client.rs b/lib/client/src/client.rs index b1eee5adb..0cf3fbc19 100644 --- a/lib/client/src/client.rs +++ b/lib/client/src/client.rs @@ -492,6 +492,64 @@ impl OpenBookClient { self.send_and_confirm_owner_tx(vec![ix]).await } + #[allow(clippy::too_many_arguments)] + pub async fn cancel_order( + &self, + market: Market, + market_address: Pubkey, + order_id: u128, + ) -> anyhow::Result { + let ix = Instruction { + program_id: openbook_v2::id(), + accounts: { + anchor_lang::ToAccountMetas::to_account_metas( + &openbook_v2::accounts::CancelOrder { + open_orders_account: self.open_orders_account, + signer: self.owner(), + market: market_address, + bids: market.bids, + asks: market.asks, + }, + None, + ) + }, + data: anchor_lang::InstructionData::data(&openbook_v2::instruction::CancelOrder { + order_id + }), + }; + self.send_and_confirm_owner_tx(vec![ix]).await + } + + #[allow(clippy::too_many_arguments)] + pub async fn cancel_all_orders( + &self, + market: Market, + market_address: Pubkey, + side_option: Option, + limit: u8, + ) -> anyhow::Result { + let ix = Instruction { + program_id: openbook_v2::id(), + accounts: { + anchor_lang::ToAccountMetas::to_account_metas( + &openbook_v2::accounts::CancelOrder { + open_orders_account: self.open_orders_account, + signer: self.owner(), + market: market_address, + bids: market.bids, + asks: market.asks, + }, + None, + ) + }, + data: anchor_lang::InstructionData::data(&openbook_v2::instruction::CancelAllOrders { + side_option, + limit + }), + }; + self.send_and_confirm_owner_tx(vec![ix]).await + } + #[allow(clippy::too_many_arguments)] pub async fn deposit( &self,