Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record take volume after matching #72

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
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
39 changes: 8 additions & 31 deletions programs/openbook-v2/src/state/open_orders_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,32 +446,6 @@ impl<
Ok(())
}

pub fn execute_taker(&mut self, market: &mut Market, fill: &FillEvent) -> Result<()> {
let pa = &mut self.fixed_mut().position;

// Replicate the base_quote_change function but subtracting the fees for an Ask
// let (base_change, quote_change) = fill.base_quote_change(fill.taker_side());
let _base_change: i64;
let quote_change: i64;
match fill.taker_side() {
Side::Bid => {
_base_change = fill.quantity;
quote_change = -fill.price * fill.quantity;
}
Side::Ask => {
// remove fee from quote_change
_base_change = -fill.quantity;
quote_change = fill.price * fill.quantity * (1 - market.taker_fee.to_num::<i64>());
}
};

// fees are assessed at time of trade; no need to assess fees here
let quote_change_native = I80F48::from(market.quote_lot_size) * I80F48::from(quote_change);
pa.taker_volume += quote_change_native.abs().to_num::<u64>();

Ok(())
}

/// Release funds and apply taker fees to the taker account. Account fees for referrer
pub fn release_funds_apply_fees(
&mut self,
Expand All @@ -482,18 +456,21 @@ impl<
taker_fees: u64,
) -> Result<()> {
let pa = &mut self.fixed_mut().position;
// Update free_native
match taker_side {
Side::Bid => pa.base_free_native += base_native,
Side::Ask => pa.quote_free_native += quote_native - taker_fees,
Side::Bid => {
pa.base_free_native += base_native;
pa.taker_volume += quote_native + taker_fees;
}
Side::Ask => {
pa.quote_free_native += quote_native - taker_fees;
pa.taker_volume += quote_native;
}
};

// Referrer rebates
pa.referrer_rebates_accrued += market.referrer_taker_rebate(quote_native);
market.referrer_rebates_accrued += market.referrer_taker_rebate(quote_native);

pa.taker_volume += taker_fees;

Ok(())
}

Expand Down
4 changes: 0 additions & 4 deletions programs/openbook-v2/src/state/orderbook/book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@ impl<'a> Orderbook<'a> {
process_fill_event(fill, market, event_queue, remaining_accs)?;

limit -= 1;

if let Some(open_orders_acc) = open_orders_acc.as_mut() {
open_orders_acc.execute_taker(market, &fill)?
}
}

let total_quote_lots_taken = order_max_quote_lots - remaining_quote_lots;
Expand Down