Skip to content

Price calculate incorrect in buy side #104

@pgCanal

Description

@pgCanal

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions