renegade_sdk/renegade_wallet_client/actions/
update_order.rs1use renegade_circuit_types::Amount;
4use renegade_external_api::{
5 http::order::{UPDATE_ORDER_ROUTE, UpdateOrderRequest, UpdateOrderResponse},
6 types::{ApiOrder, ApiOrderCore},
7};
8use uuid::Uuid;
9
10use crate::{RenegadeClientError, actions::construct_http_path, client::RenegadeClient};
11
12impl RenegadeClient {
13 pub async fn update_order(
18 &self,
19 order_update_config: OrderUpdateConfig,
20 ) -> Result<ApiOrder, RenegadeClientError> {
21 let request = self.build_update_order_request(order_update_config).await?;
22 let path = construct_http_path!(UPDATE_ORDER_ROUTE, "account_id" => self.get_account_id(), "order_id" => request.order.id);
23 let UpdateOrderResponse { order } = self.relayer_client.post(&path, request).await?;
24
25 Ok(order)
26 }
27
28 async fn build_update_order_request(
30 &self,
31 order_update_config: OrderUpdateConfig,
32 ) -> Result<UpdateOrderRequest, RenegadeClientError> {
33 let mut order = match order_update_config.initial_order {
34 Some(initial_order) => initial_order,
35 None => self.get_order(order_update_config.order_id).await?.order,
36 };
37
38 if let Some(min_fill_size) = order_update_config.min_fill_size {
39 order.min_fill_size = min_fill_size;
40 }
41
42 if let Some(allow_external_matches) = order_update_config.allow_external_matches {
43 order.allow_external_matches = allow_external_matches;
44 }
45
46 Ok(UpdateOrderRequest { order })
47 }
48}
49
50#[derive(Debug, Default)]
56pub struct OrderUpdateConfig {
57 order_id: Uuid,
59 initial_order: Option<ApiOrderCore>,
62 min_fill_size: Option<Amount>,
64 allow_external_matches: Option<bool>,
66}
67
68impl OrderUpdateConfig {
69 pub fn new(order_id: Uuid) -> Self {
71 Self { order_id, ..Default::default() }
72 }
73
74 pub fn with_initial_order(
76 mut self,
77 initial_order: ApiOrderCore,
78 ) -> Result<Self, RenegadeClientError> {
79 if initial_order.id != self.order_id {
80 return Err(RenegadeClientError::invalid_order_update(format!(
81 "Initial order ID does not match the order ID to update: {} != {}",
82 initial_order.id, self.order_id
83 )));
84 }
85
86 self.initial_order = Some(initial_order);
87 Ok(self)
88 }
89
90 pub fn with_min_fill_size(mut self, min_fill_size: Amount) -> Self {
92 self.min_fill_size = Some(min_fill_size);
93 self
94 }
95
96 pub fn with_allow_external_matches(mut self, allow_external_matches: bool) -> Self {
98 self.allow_external_matches = Some(allow_external_matches);
99 self
100 }
101}