Skip to content

Commit

Permalink
Merge pull request #209 from Lou-Kamades/lou/client-cancel
Browse files Browse the repository at this point in the history
Add cancel functions + consume events to rust client
  • Loading branch information
binyebarwe authored Dec 31, 2023
2 parents 095e569 + af8a88a commit 3576811
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions lib/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,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 Expand Up @@ -561,6 +619,32 @@ impl OpenBookClient {
self.send_and_confirm_owner_tx(vec![ix]).await
}

#[allow(clippy::too_many_arguments)]
pub async fn consume_events(
&self,
market: Market,
market_address: Pubkey,
limit: usize,
) -> anyhow::Result<Signature> {
let ix = Instruction {
program_id: openbook_v2::id(),
accounts: {
anchor_lang::ToAccountMetas::to_account_metas(
&openbook_v2::accounts::ConsumeEvents {
consume_events_admin: market.consume_events_admin.into(),
market: market_address,
event_heap: market.event_heap,
},
None,
)
},
data: anchor_lang::InstructionData::data(&openbook_v2::instruction::ConsumeEvents {
limit,
}),
};
self.send_and_confirm_owner_tx(vec![ix]).await
}

pub async fn send_and_confirm_owner_tx(
&self,
instructions: Vec<Instruction>,
Expand Down

0 comments on commit 3576811

Please sign in to comment.