PSX market data in JavaScript and Node.js
The API sends CORS headers, so the market endpoints work from the browser as well as from a server.
Quotes and history
const API = "https://api.psxlens.com";
const quote = await (await fetch(`${API}/v1/quotes/HUBC`)).json();
console.log(quote.price, quote.change_pct);
const { data: bars } = await (await fetch(`${API}/v1/prices/HUBC?limit=60`)).json();
console.log(bars.at(-1));A stock's full picture, including beta
const stock = await (await fetch(`${API}/v1/stocks/OGDC`)).json();
console.log(stock.derived.beta); // { value, raw, r2, observations, label, ... }Your users' watchlists
To read or change a person's watchlist or portfolios, let them sign in with PSX Lens. Your server then calls /v1/me/watchlist with their token. The full flow is in the Sign in with PSX Lens guide.
await fetch(`${API}/v1/me/watchlist`, {
method: "POST",
headers: { authorization: `Bearer ${userToken}`, "content-type": "application/json" },
body: JSON.stringify({ symbol: "OGDC" }),
});