Skip to content

Commit

Permalink
fix: Only return trade errors to the user in case of a manual order
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed May 6, 2024
1 parent 47e4588 commit 5bc7cd3
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions coordinator/src/orderbook/trading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ pub fn start(
"Processing new order",
);

if let Err(error) = match new_order.order_type {
if let Err(error) = match &new_order.order_type {
OrderType::Market => {
process_new_market_order(
node,
notifier.clone(),
trade_notifier.clone(),
new_order,
&new_order,
network,
oracle_pk,
channel_opening_params
Expand All @@ -114,22 +114,25 @@ pub fn start(
process_new_limit_order(
node,
tx_orderbook_feed,
new_order,
new_order.clone(),
)
.await
}
} {
// TODO(holzeis): the maker is currently not subscribed to the websocket
// api, hence it wouldn't receive the error message.
if let Err(e) = trade_notifier
.send(OrderbookMessage::TraderMessage {
trader_id,
message: TradeError { order_id, error },
notification: None,
})
.await
{
tracing::error!(%trader_id, %order_id, "Failed to send trade error. Error: {e:#}");

if new_order.order_reason == OrderReason::Manual {
// TODO(holzeis): the maker is currently not subscribed to the websocket
// api, hence it wouldn't receive the error message.
if let Err(e) = trade_notifier
.send(OrderbookMessage::TraderMessage {
trader_id,
message: TradeError { order_id, error },
notification: None,
})
.await
{
tracing::error!(%trader_id, %order_id, "Failed to send trade error. Error: {e:#}");
}
}
}
}
Expand Down Expand Up @@ -183,7 +186,7 @@ pub async fn process_new_market_order(
node: Node,
notifier: mpsc::Sender<Notification>,
trade_notifier: mpsc::Sender<OrderbookMessage>,
order: Order,
order: &Order,
network: Network,
oracle_pk: XOnlyPublicKey,
channel_opening_params: Option<ChannelOpeningParams>,
Expand Down Expand Up @@ -229,7 +232,7 @@ pub async fn process_new_market_order(
%fee_discount, total_fee_percent = %fee_percent, "Fee discount calculated");

let matched_orders = match match_order(
&order,
order,
opposite_direction_limit_orders,
network,
oracle_pk,
Expand Down

0 comments on commit 5bc7cd3

Please sign in to comment.