PSX Market Data API: Live Data, History and Order Execution
By Muhammad Abbas · · 6 min read

A PSX market data API lets your code pull Pakistan Stock Exchange (PSX) prices, order book depth, company fundamentals and index data directly, instead of copying them from a website. At Bhayani Securities (BSL), our Market Data API serves live and historical data over REST and WebSocket, and our Execution API lets the same code place orders on PSX.
In short: you open a BSL account and build against our sandbox with real market data and simulated fills. Only live market data needs your own licence from PSX; delayed prices, history, technicals and fundamentals come without one. When you are ready, you go live with your own capital and risk limits.
What You Can Get Through the PSX Market Data API
Our API serves the same dataset that runs this website. REST lets your code request data when it needs it, and WebSocket keeps a live connection open and pushes each update to you as it happens.
| Dataset | What it includes | Typical use | PSX licence needed? |
| Level 2, live | Full order book depth, best bid and ask with spread, tick-by-tick trades, intraday OHLC and VWAP, session and halt status | Intraday and algorithmic trading | Yes, your own |
| Delayed prices | Prices delayed by 5 minutes | Dashboards and monitoring | No |
| Prices and history | End-of-day OHLC history, 52-week statistics, returns and technical data | Backtesting and charts | No |
| Corporate actions | Price history adjusted for splits and bonus shares | Clean backtests | No |
| Fundamentals | Annual and quarterly statements, EPS, and ratios such as P/E, P/B, ROE and dividend yield | Screens and valuation models | No |
| Indices | KSE-100, KSE-30, KMI-30 and KMI All Shares levels, history, constituents and weights | Benchmarks and index tracking | No |
| Market flows and rates | Margin financing data (MTS and MFS), T+1 settlement metrics, foreign and local investor flows, and KIBOR rates | Sentiment and funding analysis | No |
| Reference and events | Company profiles, announcements, board meetings, ex-dates and dividend records | Alerts and event-driven strategies | No |
A few terms from the table: OHLC is a period's open, high, low and close prices, and VWAP is the volume-weighted average price. MTS and MFS are PSX's margin trading and margin financing systems, which let investors buy with borrowed money, and KIBOR is the Karachi Interbank Offered Rate that prices much of that borrowing.
Live Level 2 data arrives over REST and per-symbol WebSocket subscriptions: you receive a full snapshot first, then each change as it happens. Historical and end-of-day data come over REST, so a backtest can pull years of adjusted prices in a few calls.
Trade on PSX Through the Execution API
Our Execution API lets your code place, amend and cancel PSX orders through BSL's own order management system (OMS), the software that checks each order and routes it to the exchange. We built it in-house, our own desk trades on it, and it is tuned for order handling under 30 milliseconds.
- Every common order type. Limit and market orders with DAY, GTC, IOC, FOK and GTD time-in-force, which sets how long an order stays open, across PSX boards including Regular, Futures, Negotiated Deals and Square-up.
- Cancel and replace. Amend the price or quantity of an open order, or cancel it, with every request tracked to a confirmed final state.
- A live status stream. A WebSocket pushes every change in an order's state as it happens.
- Positions, fills and buying power in real time, with capital reserved when you submit an order and settled on each fill.
- Scheduled orders that the OMS releases at a time you set.
- One entity per strategy, each with its own capital, risk limits and kill switch.
Every order passes pre-trade risk checks before it reaches the exchange, including buying-power checks, price collars against the last traded price, order-rate limits and a daily-loss stop. The API provides data and execution only, and your strategy makes every decision.
When You Need a PSX Licence
Only live market data needs a licence from PSX. Its Data Services and Vending page sells real-time feeds at three levels: Level 1, Level 1+, which adds the top 10 bid and ask levels of the order book, and Level 2, which adds tick-by-tick data.
To receive live data through our API, you sign your own data licensing agreement with PSX. It is a licence to use the data yourself, not to redistribute it, and PSX's Market Data Team handles requests at marketdatarequest@psx.com.pk. Once it is in place, we connect your access.
Everything else comes through our API with no PSX licence: prices delayed by 5 minutes, end-of-day history, adjusted prices, technical data, fundamentals, indices, market flows, rates and reference data. Most backtests, screens and dashboards run entirely on this data.
How to Get Started
- Open a BSL account. You need one to use the APIs, including the sandbox, and you can open it online.
- Request API access. Use Request API Access on our Trading APIs page or email info@bsl.com.pk. Tell us what you are building, the data you need and whether you plan to trade live.
- If you need live data, arrange your PSX data licence. Delayed and non-live data need no licence, so many projects skip this step.
- Get sandbox access. We send sandbox credentials, the integration guide and an OpenAPI specification, a machine-readable description of every endpoint, with your terms. Pricing depends on whether you need data only or data plus live execution, and on coverage.
- Build and test. The sandbox is a full copy of the API with real market data and simulated fills, so no live orders are placed.
- Go live. We set up your production entity, capital and risk limits.
Students and researchers can use the sandbox on the same terms as any other account holder.
Choosing the Right Data for Your Project
- Backtesting a daily or longer-term strategy. End-of-day history adjusted for splits and bonuses is usually enough, it avoids false signals around corporate actions, and it needs no PSX licence.
- Screens and dashboards. End-of-day or 5-minute delayed prices with fundamentals and index data cover most needs. Our market overview is built on the same data.
- Intraday or algorithmic trading. You need live data, under your own PSX licence, and the Execution API. Level 2 depth shows every price level in the order book, and our guide to the PSX order book explains how to read it.
In our view, start with the smallest dataset that answers your question, then add live depth and execution when your strategy needs them.
Getting Started With a PSX Market Data API
A market data API turns PSX prices, depth, fundamentals and index data into something your code can use, and an execution API lets the same code trade. With BSL, both come from one broker, on an order system we built ourselves, starting in a sandbox. See the full coverage on our Trading APIs page and request access when you are ready.
Disclaimer: This article is for educational purposes only and should not be treated as investment advice. Stock investments carry market risk, and investors should consult a licensed financial advisor before making investment decisions.
Frequently Asked Questions
Do I need a licence from PSX to use a market data API?
Only for live market data. For real-time prices and order book data, you sign your own data licensing agreement with PSX, a licence to use the data rather than to redistribute it. Delayed data and all non-live data, such as history, technicals and fundamentals, need no PSX licence.
Can I trade on PSX through an API?
Yes, through a broker that offers one. BSL's Execution API supports limit and market orders, cancel and replace, scheduled orders and a live order-status stream. Every integration starts in a sandbox, and live trading follows onboarding with BSL.
How much does API access cost?
It depends on whether you need data only or data plus live execution, and on the coverage involved. Tell us what you are building and we share terms when we set up your sandbox access.
Does the API give trading signals?
No. It provides market data and order execution only, and your own strategy decides what to buy and sell.

Written by
Muhammad Abbas
CEO, Bhayani Securities (Pvt) Ltd.
Need Guidance?
Book a free consultation with our licensed investment advisors.