For developers and quants trading the Pakistan Stock Exchange

Backtest and automate PSX strategies in Python.

10 years of PSX history, live market data, and a full paper-trading engine, in one pip install. Free sandbox. No broker account. No scraper to maintain.

install
pip install pypsx pytrader-sdk
get_data.py
import pypsx

# Ten years of OGDC daily bars, one line, no scraper.
df = pypsx.download("OGDC", period="10y")

print(df.tail())
#             open   high    low  close    volume
# 2026-07-08  92.1   93.4   91.8  93.0   4_812_305
# 2026-07-09  93.2   94.7   92.9  94.5   5_104_221
# 2026-07-10  94.6   95.1   93.7  94.0   3_998_120
Free Python library10 years of historyEvery listed PSX symbolPaper trading includedPyPI: pypsx · pytrader-sdkMIT-licensed client

You've already tried scraping dps.psx.com.pk. You know how that ends.

// pain
The scraper breaks.

PSX changes their markup and your parser dies. You spend Saturday fixing a scraper instead of testing your idea. There's no versioned API, no contract, nothing to depend on.

// pain
There's no history to test against.

You can get today's price. You cannot get 2016. So you can't backtest, which means you can't know if your idea works. You're guessing, and then you're guessing with real money.

// pain
So you gave up and used yfinance.

You backtested SPY instead of OGDC, because the data was there. You wrote off the market you actually live in, trade in, and understand, because nobody built the plumbing.

Solution

The Alpaca of the Pakistan Stock Exchange.

pyPSX is an algorithmic trading API for PSX. Two Python libraries. pypsx gives you market data: historical OHLCV, intraday, fundamentals, dividends, and index constituents. pytrader handles execution: backtesting, paper trading, and strategies that run on a schedule.

Data is free. The sandbox is free too. Live broker execution is coming. join the waitlist.

idea, tested, running
pypsx
data
run_backtest()
validate
TradingClient
paper
live
soon
01Data that doesn't break

Ten years of PSX, in one line.

Every listed symbol. Daily and intraday bars. Fundamentals, dividend history, announcements, index constituents, full market watch. Returns pandas DataFrames, no parsing, no cleanup. Free.

Explore the data API →
python
import pypsx

df = pypsx.download("OGDC", period="10y")
02Find out if it works, before it costs you

Backtest against real PSX history.

Realistic commission and slippage. Grid-search your parameters. Per-symbol breakdown. Stop paying tuition to the market to discover your idea was bad.

See strategies we've backtested →
python
from pytrader import run_backtest

results = run_backtest(
    "rsi_momentum",
    symbols=kse100,
    start="2016-01-01",
)

print(results.sharpe, results.max_drawdown)
03Then let it run

Paper trade it. Then automate it.

Market, limit, stop, stop-limit. Live WebSocket fills. A Strategy class that runs on a cycle, locally or as a cloud bot, whether or not you're at your screen. Paper today; live broker execution is next.

See the algo-trading platform →
python
client = TradingClient.from_env(paper=True)

client.place_manual_order(
    symbol="OGDC", side="BUY",
    quantity=100, order_type="MARKET",
)
Strategy Copilot

Describe it in English. Get a runnable bot.

Type a strategy the way you'd explain it to a friend. Copilot renders a runnable pytrader config you can launch to a paper account, or download and run yourself.

Browse prompt library
copilot_config.py
config = None  # Click "Generate config"
# to preview your strategy as
# runnable pytrader code.
Broker API · early access

Building an investing product for Pakistan?

A separate product: accounts, KYC, order routing, custody, and settlement to embed PSX investing in your app, without becoming a broker. Sandbox coming soon.

Explore the Broker API →
Free forever
The pypsx library is genuinely free.

No credit card. No rate-limit tricks. Install it and pull ten years of PSX history in a single line.

install
pip install pypsx
Built with AI tools?

Your Copilot already knows pyPSX.

Paste markets.pypsx.com/llms.txt into Claude, ChatGPT, or Cursor and it knows the entire API: every endpoint, every parameter, every return shape. Your assistant writes working pyPSX code on the first try.

claude prompt
Read: markets.pypsx.com/llms.txt

Now write me a script that:
- pulls 5 years of daily bars for every bank in KSE-100
- computes 20/50 EMA crossovers
- backtests it with 15bps commission
- prints Sharpe per symbol

Questions people ask.

Grouped by product. Still stuck? The docs go deeper.

Market Data API
How do I get PSX historical data in Python?+

Install pypsx and call pypsx.download(symbol, period='10y'). No scraper. You get a pandas DataFrame of OHLCV bars for every listed symbol.

Is the data really free?+

Yes, the pypsx market-data library is free. No credit card, no rate-limit tricks.

What data is available: fundamentals, dividends, indices?+

10 years of daily OHLCV, intraday (research), company fundamentals, full dividend history, corporate announcements, index constituents (KSE-100 / KMI-30 / KSE-30), sector lists, and a full market watch.

Can I use the data commercially?+

Personal and research use is free. For commercial redistribution, talk to us, we don't want to gate builders.

Algo Trading
Is algorithmic trading legal in Pakistan?+

Yes. Individuals may build and run automated strategies against PSX. Live execution requires routing orders through a licensed broker. pyPSX today ships free market data and a paper-trading engine; live broker execution is in development.

Is there an Alpaca alternative for PSX?+

pyPSX is that alternative. Same mental model (keys, paper trading, REST + WebSocket, backtests), built for the Pakistan Stock Exchange.

Is the paper-trading sandbox free?+

Yes. Sign up at markets.pypsx.com, generate a key (it starts with PK_), and you get a free paper account with a real fill engine and FIFO lot accounting.

Can I backtest a custom strategy?+

Yes, the pytrader SDK's run_backtest() backtests any custom Strategy class on 10+ years of PSX history with realistic commission and slippage. (The website Backtest page covers six built-in templates; Strategy Copilot configs launch to paper and aren't backtested.)

Do I need a broker account to use it?+

No. Everything available today (data, backtesting, paper trading, Copilot) works without a broker account.

Broker API
What is the Broker API, and how is it different from algo trading?+

The Broker API is a separate product for companies: accounts, KYC, order routing, custody, and settlement to embed PSX investing in your own app. Algo Trading is for you to trade your own account; the Broker API is for you to offer investing to your users.

When does live / real-money trading launch?+

Real-money execution runs through the Broker API, which is in development with design partners. A sandbox is coming soon, join early access to help shape it and get first access.

Do I need a brokerage license to use the Broker API?+

The point is that you don't. You embed investing through our infrastructure instead of becoming a broker yourself. Tell us what you're building on the Broker API page.