I'm new to trading, and I can't figure out whether or not you can buy and sell stocks instantly. For instance, if I buy a number of stocks of a particular corporation, whose current trading price is 46.8, can I sell it at 46.9? If you take a deeper look into trading market depth, you'll find that there are multiple buy and sell prices. As far as I understand, those are the prices at which people are trading, right? And if there's even a minute difference between the highest and lowest price, I can make some decent profit by buying at the lowest buy price and selling at the highest sell price, right? I'm very new in this field, so I don't know much about it. Thanks in advance!
No, because the lower prices are prices at which you can sell (offers by others to buy), and the higher prices are prices at which you can buy (offers by others to sell). Any trader who offers to sell at a price lower than where someone has offered to buy, or vice versa, will be immediately matched by the exchange to execute the order; the prices will not sit there for you to make money by acting as a go-between for the exchange. And even if something like this happened (orders for the same stock on separate exchanges are not immediately matched), a professional arbitrage trader with lightning-fast computers would grab those pennies before you can blink.
The basic premise of you question is incorrect.
The bid price is the lower price and that is the price that traders are bidding to buy the security.
The ask price is the higher price and that is the price that traders are offering to sell the security at.
You cannot buy at the bid (the lower price) and sell at the ask (the higher price). It is the reverse (you buy at the ask and sell at the bid).
You can become the best bid and/or the best offer but that means that in order to get an execution you will sit there waiting until a counter party accepts your price. Otherwise, you get nothing.
The only guaranteed fills are at market prices, assuming you hit the bid or the ask before someone else. You will only get a fill for the number of shares available unless additional shares come in at the same price after you take out the NBBO quote.
In these strategies, computer scientists rely on speed to gain minuscule advantages in arbitraging price discrepancies in some particular security trading simultaneously on disparate markets
or flash trading:
This order type was available to all participants but since HFT's adapted to the changes in market structure more quickly than others, they were able to use it to "jump the queue" and place their orders before other order types were allowed to trade at the given price.
In order to do this, you need to have large servers that are physically close to stock exchanges.
The use of high-frequency trading is controversial.
Just to illustrate what others have said in their answers...
Here is the order book for a randomly picked stock:
(this is from a French site, because order books are public on many french sites, when they are often reserved to subscribers on US sites, but you probably have access to that with your trading account, and it works the same everywhere).
The three columns on the left are the orders to buy, which list the number of orders, the number of shares, and the price the buyer is willing to pay (highest first).
The three columns on the right are the orders to sell, which list the price the wants (lowest first), the number of shares, and the number of orders.
You can see that the highest buying price (9.534) is lower than the lowest selling price (9.556). This is the bid-ask spread. If nothing changes, no sale can occur, as people who want to buy are not willing to pay the price the people who want to sell ask for.
For a sale to occur, there needs to be a new order coming in which "matches" an order in the opposite direction (it could be a change to an existing order, of course).
So, if you want to sell your stock immediately, you need to sell it for 9.534 or less. At that price, you can sell 26 shares. If you want to sell more than that, you would need to sell for 9.526 or less. And so on.
Conversely, if you want to buy immediately, you need to pay at least 9.556 (for up to 260 shares), or 9.558 if you want more, and so on.
There's always a difference between the highest selling price and the lowest buying price (with the latter higher than the former). As soon as the two match (or the lowest buying price is lower than the highest selling price), the exchange will match the orders, the shares will be transferred, and the orders will either be removed from the order book (for the existing one) or just not added at all (for the new one) if the numbers of shares match.
If there is a mismatch in numbers of shares, then one of the two (the one with the lowest number of shares) will be completely fulfilled and be removed from the order book and the other will see its number of shares adjusted, but again, only one of the two will remain, and you still won't have two orders (in opposite directions) with the same price.
Other orders will just stay there until either someone makes a matching order (for instance someone really really wants to sell this stock right now, and is willing to go down to 9.5 rather than wait, then all the orders show here will be matched if the quantities allow), or they get changed (the people trying to buy at 9.5 realise they won't be able to do so at that price, so they change their limit to match current sell orders).
Here you can see how the order book for a given share evolves over time:
Buy orders are in green, sell orders are in red. As you see, green prices are always lower than red.
On exchanges with market makers (as opposed to auctions/specialists), the agent which actually executes the trades ensures a positive bid/ask spread, because that is their compensation. Obviously, if you were a market maker for such an exchange, you would never offer to sell a security for less than the price you are willing to buy it, because then you would incur a cost to yourself for providing liquidity to the market.
It helps to understand how a transaction normally completes. The exchange maintains a list of bids and asks by price point and security. This is called the order book. When you go to buy a security, you name a limit price (I want to buy 10 shares of XYZ for no more than $35.00) or specify a "market order" (I want to buy 10 shares of XYZ for the current best available price). If a sell order exists which matches the criteria for your limit (Alice offers 50 shares of XYZ for $34.85), then the trade executes immediately. Otherwise, the order goes into the book and waits for a matching bid (until it expires). Note that market orders are most likely to get filled immediately, because their constraint is only for a number of shares, and does not limit the price.
As you can see, if Alice places a sell order for 50 shares of XYZ at $48.80, and Bob places a buy order for 25 shares of XYZ at $48.90, you will never see that bid/ask spread on the order book, except in retrospect. That's because the exchange will see that these orders match, and the trade will execute for 25 shares@$48.80 as soon as the second order is received. You will literally have 0 time to insert yourself between Alice and Bob and arbitrage the difference. The exchange does that automatically by the very definition of a limit order.
Eric Duminil mentions a scenario where the above can happen, and that is when the same security is listed on multiple exchanges (e.g., NYSE + LSE + TSE). Because buy orders on one exchange cannot be filled by sell orders on another, the price matching across exchanges must occur via external market participants. It might seem like this is easy money, and it is, in a sense, which means that it will almost never happen (over a duration that a human can notice). Because this opportunity can be identified algorithmically, automated traders will execute these trades long before a human gets a chance at them. Of course, anyone, including you, can set up your own automated trading system to get a piece of this pie. But if another trader always beats you to the trade, then you just wasted money investing in your system. Because it's the closest thing to a sure bet, HFTs can essentially spend their profits ensuring that their trades are the fastest, by locating their servers closest to the exchanges and using dedicated, proprietary low-latency networks to move data between their servers faster than you or competitors.