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

Price calculate incorrect in buy side #104

Open
pgCanal opened this issue Jan 20, 2022 · 1 comment
Open

Price calculate incorrect in buy side #104

pgCanal opened this issue Jan 20, 2022 · 1 comment

Comments

@pgCanal
Copy link

pgCanal commented Jan 20, 2022

Hi team,

Thanks for the great package!

I found the current price and size calculation for the fill event (SIDE = BUY) in the below links may be wrong at least for Dex V3.

price = (price_before_fees * self.state.base_spl_token_multiplier()) / (
self.state.quote_spl_token_multiplier() * event.native_quantity_paid
)
size = event.native_quantity_paid / self.state.base_spl_token_multiplier()

The potential update will be. Reference from

https://github.com/project-serum/serum-ts/blob/4cdea04ffbc6fd68392d8f8608ba5c7524007d4e/packages/serum/src/market.ts#L1138-L1164

    if event.event_flags.bid:
        side = Side.BUY
        price_before_fees = (
            event.native_quantity_paid + event.native_fee_or_rebate
            if event.event_flags.maker
            else event.native_quantity_paid - event.native_fee_or_rebate
        )
        price = (price_before_fees * self.state.base_spl_token_multiplier()) / (
        self.state.quote_spl_token_multiplier() * event.native_quantity_released
        )
        size = event.native_quantity_released / self.state.base_spl_token_multiplier()

    else:
        side = Side.SELL
        price_before_fees = (
            event.native_quantity_released - event.native_fee_or_rebate
            if event.event_flags.maker
            else event.native_quantity_released + event.native_fee_or_rebate
        )
    
        price = (price_before_fees * self.state.base_spl_token_multiplier()) / (
            self.state.quote_spl_token_multiplier() * event.native_quantity_paid
        )
        size = event.native_quantity_paid / self.state.base_spl_token_multiplier()
@leofisG
Copy link
Contributor

leofisG commented Mar 22, 2022

Hey @pgCanal , do you mind creating a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants