Skip to content

Display price impact of a swap #86

@secretshardul

Description

@secretshardul

I plan on working on this. Any resources / API on how price impact can be found? Currently plan on looking at the bid / ask slab. Will traverse down bids until order size is filled. The price tick of this bid will be the new price, from which price impact will be calculated.

Pseudocode:

let unfilled_order_size = toAmount
let bids = [b1, b2, b3, ...]
let current_bid
for bid in bids {
  current_bid = bid
  unfilled_order_size -= bid.size
  if unfilled_order_size <= 0 {
    break
  }
}

price_impact = mid_price - current_bid.price
price_impact_percentage = 100 * price_impact / mid_price

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