You need to use a Broker API for that. Interactive Brokers is one of the most famous. This is their general information about their API:
Build Your Own Trading Application
IB API - Build a complete trading application that connects to our advanced order routing and trading system using our IB Application Programming Interface (API):
Choose from among several available IB API programming languages, including Java, .NET (C#), C++, ActiveX or DDE.
If you're a beginner API programmer, use our DDE for Excel API sample as the basis for your DDE-based trading application.
The IB API requires no additional technical overhead.
FIX CTCI – For clients with the knowledge of and resources to support FIX CTCI, a robust, industry-standard solution.
Get Market Data and Chart Data:
IB API – Subscribe to and view market data through your custom application while taking advantage of Trader Workstation, our innovative trading platform.
IB Gateway – Connect to IB market data in a seamless experience with a minimal interface.
WT Web API –Add market data and chart data to your custom trading interface or website.
Take a look to their website: IB API.