Where do online stock brokers get their real-time data from?
As another answer started, this information comes straight from an exchange and generally costs a fortune . . . However things change: IEX, a new exchange, recently opened and they are offering real time bid/ask data for free. Here's the API description: https://www.iextrading.com/developer/ This data should be good for active securities, but for securities less actively traded the numbers might be stale.