Skip to content

Commit

Permalink
Merge pull request #2266 from get10101/chore/do-not-spawn-on-trade-ex…
Browse files Browse the repository at this point in the history
…ecution

chore: Do not spawn on trade execution
  • Loading branch information
holzeis authored Mar 18, 2024
2 parents 81d49ef + 90b9a34 commit 1ce3059
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
31 changes: 14 additions & 17 deletions coordinator/src/orderbook/async_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,20 @@ async fn process_pending_match(

tracing::info!(trader_id = %order.trader_id, order_id = %order.id, order_reason = ?order.order_reason, "Executing trade for match");
let trade_executor = TradeExecutor::new(node, notifier);

tokio::spawn(async move {
trade_executor
.execute(&TradeAndChannelParams {
trade_params: TradeParams {
pubkey: trader_id,
contract_symbol: ContractSymbol::BtcUsd,
leverage: order.leverage,
quantity: order.quantity.to_f32().expect("to fit into f32"),
direction: order.direction,
filled_with,
},
trader_reserve: channel_opening_params.map(|c| c.trader_reserve),
coordinator_reserve: channel_opening_params.map(|c| c.coordinator_reserve),
})
.await;
});
trade_executor
.execute(&TradeAndChannelParams {
trade_params: TradeParams {
pubkey: trader_id,
contract_symbol: ContractSymbol::BtcUsd,
leverage: order.leverage,
quantity: order.quantity.to_f32().expect("to fit into f32"),
direction: order.direction,
filled_with,
},
trader_reserve: channel_opening_params.map(|c| c.trader_reserve),
coordinator_reserve: channel_opening_params.map(|c| c.coordinator_reserve),
})
.await;
}

Ok(())
Expand Down
31 changes: 14 additions & 17 deletions coordinator/src/orderbook/trading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,23 +321,20 @@ pub async fn process_new_market_order(
if node.inner.is_connected(order.trader_id) {
tracing::info!(trader_id = %order.trader_id, order_id = %order.id, order_reason = ?order.order_reason, "Executing trade for match");
let trade_executor = TradeExecutor::new(node.clone(), notifier);

tokio::spawn(async move {
trade_executor
.execute(&TradeAndChannelParams {
trade_params: TradeParams {
pubkey: order.trader_id,
contract_symbol: ContractSymbol::BtcUsd,
leverage: order.leverage,
quantity: order.quantity.to_f32().expect("to fit into f32"),
direction: order.direction,
filled_with: matched_orders.taker_match.filled_with,
},
trader_reserve: channel_opening_params.map(|p| p.trader_reserve),
coordinator_reserve: channel_opening_params.map(|p| p.coordinator_reserve),
})
.await;
});
trade_executor
.execute(&TradeAndChannelParams {
trade_params: TradeParams {
pubkey: order.trader_id,
contract_symbol: ContractSymbol::BtcUsd,
leverage: order.leverage,
quantity: order.quantity.to_f32().expect("to fit into f32"),
direction: order.direction,
filled_with: matched_orders.taker_match.filled_with,
},
trader_reserve: channel_opening_params.map(|p| p.trader_reserve),
coordinator_reserve: channel_opening_params.map(|p| p.coordinator_reserve),
})
.await;
} else {
match order.order_reason {
OrderReason::Manual => {
Expand Down

0 comments on commit 1ce3059

Please sign in to comment.