vegaprotocol / frontend-monorepo

Toolkit for building apps that interact with Vega
https://vega.xyz
MIT License
23 stars 15 forks source link

Simple swap UI price tolerance issue #6548

Closed JonRay15 closed 6 days ago

JonRay15 commented 1 week ago

The Chore

Because we can only submit orders with a size and that size is always denoted in base asset terms ... it means that the behaviour of the swap is slightly different depending on whether you are paying the base or the quote.

The ideal behaviour would be:

This works fine if you are paying the base (ie. selling), because we set the size and if the book has some slippage you'll get somewhere between the amount purchased at your best bid price and the amount you can can purchase at your price tolerance.

But if you're paying the quote (ie. buying) it doesnt work, because we have to derive the size of the order in base terms before submitting it ... so you're a bit stuck, either you:

Neither option is really idea ... so I think until such time as Core gives us the ability to submit an order with the notional in quote asset terms the best we can do is some messaging.

If paying the quote and receiving the base asset

You are BUYING ... and your SIZE is DERIVED

"You will pay between quote asset amount based on best ask and quote asset amount at price tolerance to receive size in base asset based on your price tolerance of price tolerance"

eg.
"You will pay between 695.51 USDT and 702.4 USDT to receive 0.01 BTC based on your price tolerance of 1%"

If paying the base and receiving the quote asset

You are SELLING ... and your SIZE is SET in the form

"You will pay size in base asset to receive between quote asset amount based on best bid and quote asset amount at price tolerance based on your price tolerance of `price tolerance"

eg. "You will pay 0.01 BTC to receive between 695.51 USDT and 688.55 USDT based on your price tolerance of 1%"

NB. Both examples above for simplicity assume that best bid = best ask = 695.51 USDT, with price tolernance applied appropriately based on whether it is a buy or a sell.

Acceptance criteria

Additional details / background info

It is probably worth considering as part of this ticket whether traversing the book properly instead of just using best bid / ask and adding price impact tolerance would help with this. My assumption is it will not ... but if we wanted to move to using slippage properly we should at least do it AND this at the same time to avoid making life difficult and reworking things later.