Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions programs/clobby/src/instructions/place_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const MAX_ORDERS_TO_MATCH:usize = 5;
struct EditOrders {
pub order_id : u64,
pub base_amount_to_set: u64,
pub base_amount_matched: u64, // FIX: Added field to track matched amount
pub total_quote_amount: u64
}

Expand Down Expand Up @@ -104,7 +105,13 @@ pub fn place_order(ctx:Context<PlaceOrder>, args:PlaceOrderArgs) -> Result<()> {
}
else{
let base_amount_to_set = opposing_order.base_amount - base_amount_eaten;
orders_to_edit.push(EditOrders { order_id: opposing_order.order_id, base_amount_to_set, total_quote_amount});
// FIX: Store base_amount_eaten for correct event recording
orders_to_edit.push(EditOrders {
order_id: opposing_order.order_id,
base_amount_to_set,
base_amount_matched: base_amount_eaten, // FIX: Track matched amount
total_quote_amount
});
}

match taker_side.get_side_in_enum()? {
Expand Down Expand Up @@ -170,7 +177,8 @@ pub fn place_order(ctx:Context<PlaceOrder>, args:PlaceOrderArgs) -> Result<()> {
partial_matched_order.base_amount = order.base_amount_to_set;

market_events.add_event(EventParams{
base_amount: order.base_amount_to_set,
// FIX: Use base_amount_matched (actual matched amount) instead of base_amount_to_set (remaining)
base_amount: order.base_amount_matched,
order_id: partial_matched_order.order_id,
maker: partial_matched_order.order_authority,
quote_amount: order.total_quote_amount,
Expand Down Expand Up @@ -344,4 +352,4 @@ pub struct PlaceOrderArgs {
pub base_lots: u16, // Number of base lots to buy or sell
pub quote_amount: u64,
pub ioc: bool, // ImmediateOrCancel
}
}