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

Display price impact of a swap #86

Open
secretshardul opened this issue Sep 20, 2021 · 0 comments
Open

Display price impact of a swap #86

secretshardul opened this issue Sep 20, 2021 · 0 comments

Comments

@secretshardul
Copy link
Contributor

secretshardul commented Sep 20, 2021

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

1 participant