So the ASK price of BTC is constantly moving -- every second. I'm trying to build out a simple UI where the user can enter in the amount of BTC they want to buy, and then display how much that will cost them in USD. But when the user finally presses the 'Buy' button, the price of BTC might have changed slightly, and the user will be charged a different value of USD than what was displayed in checkout. WTF? Is there a way around this? How are other exchanges handling this? I know this can be achieved with limit orders and such, but I'm trying to accomplish this with simple market orders.
There is not a way around this unless you are using an exchange. But, even exchanges have a disclaimer:
Market orders may be partially filled at several prices. Each part of your order will be shown in the fills panel. See Coinbase Pro - overview of order types
The way exchanges work is sellers place limit orders, which show up on the order book. When a buyer does a market order, it will buy up the lowest priced volume that is already on the order book. Basically, you have to remember there is a seller for every buyer, and everyone is choosing their price. Things happen fast, if your order is placed right after someone else buys all the volume at the price you wanted, you might get a different price.