Skip to content

Commit

Permalink
properly log fill fees
Browse files Browse the repository at this point in the history
  • Loading branch information
Lou-Kamades committed Jan 10, 2024
1 parent a0f4d8c commit 4f527af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions programs/openbook-v2/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ pub struct FillLog {

pub maker: Pubkey,
pub maker_client_order_id: u64,
pub maker_fee: i64,
pub maker_fee: u64, // native quote

// Timestamp of when the maker order was placed; copied over from the LeafNode
pub maker_timestamp: u64,

pub taker: Pubkey,
pub taker_client_order_id: u64,
pub taker_fee: i64,
pub taker_fee: u64, // native quote

pub price: i64,
pub quantity: i64, // number of base lots
Expand Down
11 changes: 9 additions & 2 deletions programs/openbook-v2/src/state/open_orders_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ impl OpenOrdersAccount {
}
}

// calculate taker fee for logging, ignoring self trades
let taker_fees = if quote_native > 0 && fill.maker != fill.taker {
market.taker_fees_ceil(quote_native)
} else {
0
};

emit!(FillLog {
market: self.market,
taker_side: fill.taker_side,
Expand All @@ -196,11 +203,11 @@ impl OpenOrdersAccount {
seq_num: fill.seq_num,
maker: fill.maker,
maker_client_order_id: fill.maker_client_order_id,
maker_fee: market.maker_fee,
maker_fee: maker_fees,
maker_timestamp: fill.maker_timestamp,
taker: fill.taker,
taker_client_order_id: fill.taker_client_order_id,
taker_fee: market.taker_fee,
taker_fee: taker_fees,
price: fill.price,
quantity: fill.quantity,
});
Expand Down

0 comments on commit 4f527af

Please sign in to comment.