Unofficial CSE API Docs

Live-probed documentation for https://www.cse.lk/api. Not affiliated with the Colombo Stock Exchange.

Python — company quote

#!/usr/bin/env python3
"""Fetch a single-symbol quote from cse.lk (unofficial)."""

from __future__ import annotations

import json
import sys

import httpx

BASE = "https://www.cse.lk/api"
HEADERS = {
    "Origin": "https://www.cse.lk",
    "Referer": "https://www.cse.lk/",
    "User-Agent": "CSE-API-Docs-Example/1.0",
}


def main(symbol: str = "JKH.N0000") -> None:
    r = httpx.post(
        f"{BASE}/companyInfoSummery",
        data={"symbol": symbol},
        headers=HEADERS,
        timeout=30.0,
    )
    r.raise_for_status()
    info = r.json()["reqSymbolInfo"]
    print(json.dumps(info, indent=2))


if __name__ == "__main__":
    main(sys.argv[1] if len(sys.argv) > 1 else "JKH.N0000")

Python — trade summary (bulk)

#!/usr/bin/env python3
"""Bulk trade summary — prefer this for polling many symbols."""

from __future__ import annotations

import httpx

BASE = "https://www.cse.lk/api"
HEADERS = {
    "Origin": "https://www.cse.lk",
    "Referer": "https://www.cse.lk/",
    "User-Agent": "CSE-API-Docs-Example/1.0",
    "Content-Type": "application/json",
}


def main() -> None:
    r = httpx.post(f"{BASE}/tradeSummary", json={}, headers=HEADERS, timeout=45.0)
    r.raise_for_status()
    rows = r.json().get("reqTradeSummery") or []
    print(f"symbols: {len(rows)}")
    for row in rows[:5]:
        print(f"{row.get('symbol')}\t{row.get('price')}\t{row.get('percentageChange')}")


if __name__ == "__main__":
    main()

curl cheat sheet

#!/usr/bin/env bash
# Unofficial cse.lk API cheat sheet — polite use only.
set -euo pipefail
H=(-H 'Origin: https://www.cse.lk' -H 'Referer: https://www.cse.lk/' -H 'Accept: application/json')

echo '=== marketStatus ==='
curl -sS -X POST 'https://www.cse.lk/api/marketStatus' -H 'Content-Type: application/json' "${H[@]}" -d '{}'
echo

echo '=== companyInfoSummery ==='
curl -sS -X POST 'https://www.cse.lk/api/companyInfoSummery' \
  -H 'Content-Type: application/x-www-form-urlencoded' "${H[@]}" -d 'symbol=JKH.N0000' | head -c 400
echo

echo '=== tradeSummary (count) ==='
curl -sS -X POST 'https://www.cse.lk/api/tradeSummary' -H 'Content-Type: application/json' "${H[@]}" -d '{}' \
  | python3 -c "import sys,json; print(len(json.load(sys.stdin).get('reqTradeSummery',[])))"

echo '=== companyProfile ==='
curl -sS -X POST 'https://www.cse.lk/api/companyProfile' \
  -H 'Content-Type: application/x-www-form-urlencoded' "${H[@]}" -d 'symbol=JKH.N0000' \
  | python3 -c "import sys,json; d=json.load(sys.stdin); print(sorted(d.keys()))"