Skip to content

Commit

Permalink
add cancel functions to rust client
Browse files Browse the repository at this point in the history
  • Loading branch information
Lou-Kamades committed Dec 30, 2023
1 parent 71375c3 commit 939a31e
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions lib/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Signature> {
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<Side>,
limit: u8,
) -> anyhow::Result<Signature> {
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,
Expand Down

0 comments on commit 939a31e

Please sign in to comment.