5paisa-ts-sdk
v1.0.0
Published
Modern TypeScript SDK for 5paisa Trading APIs
Maintainers
Readme
5paisa TypeScript SDK
A modern, lightweight, TypeScript-first SDK for interacting with 5paisa Trading APIs. Designed for Node.js 18+, with strong typing, modular services, and zero deprecated dependencies.
✨ Features
- ✅ TypeScript-first with
.d.tssupport - ✅ No deprecated libraries (
axios,request,node-pandasremoved) - ✅ Clean service-based API (
auth,orders,market) - ✅ Native
fetch(Node.js 18+) - ✅ Safe payload builders (no shared mutable state)
- ✅ GitHub & npm install support
📦 Installation
From GitHub (recommended during development)
npm install git+https://github.com/AmitManna99/5paisa-ts-sdk.gitFrom npm (once published)
npm install 5paisa-ts-sdk⚙️ Requirements
- Node.js >= 18
- 5paisa API credentials (Get them from: https://tradestation.5paisa.com/apidoc)
🚀 Quick Start
1️⃣ Create Client
import { FivePaisaClient } from "5paisa-ts-sdk";
const client = new FivePaisaClient({
appName: "my-app",
userId: "YOUR_USER_ID",
password: "YOUR_PASSWORD",
userKey: "YOUR_VENDOR_KEY",
encryptionKey: "YOUR_ENCRYPTION_KEY",
clientCode: "YOUR_CLIENT_CODE",
appSource: 1234,
});🔐 Authentication
Option 1: Login using TOTP + PIN
const requestToken = await client.auth.getRequestToken("TOTP_CODE", "PIN");
await client.auth.getAccessToken(requestToken);
// Client is now authenticatedOption 2: Login using Access Token (recommended for automation)
await client.auth.setAccessToken("EXISTING_ACCESS_TOKEN");Option 3: OAuth Login (Browser Flow)
- Redirect user to:
https://dev-openapi.5paisa.com/WebVendorLogin/VLogin/Index
?VendorKey=<YOUR_USER_KEY>
&ResponseURL=<YOUR_REDIRECT_URL>- Extract
RequestTokenfrom redirect URL - Exchange it for access token:
await client.auth.getAccessToken(requestToken);📊 Holdings & Positions
Fetch Holdings
const holdings = await client.orders.getHoldings();
console.log(holdings);Fetch Positions
const positions = await client.orders.getPositions();
console.log(positions);🧾 Orders
Place Order
await client.orders.placeOrder({
scripCode: 1660,
qty: 1,
orderType: "BUY",
exchange: "N",
price: 208,
});Modify Order
await client.orders.modifyOrder({
exchangeOrderID: "1100000007628729",
qty: 1,
price: 210,
exchange: "N",
exchangeType: "C",
isIntraday: false,
});Cancel Order
await client.orders.cancelOrder("1100000007973827");🧠 BO / CO Orders
Place BO-CO Order
await client.orders.placeBOCOOrder({
scripCode: 1660,
qty: 1,
limitPrice: 205,
triggerPrice: 0,
targetPrice: 217,
side: "BUY",
exchange: "N",
exchangeType: "C",
});Modify BO-CO Order (Profit / SL Leg)
await client.orders.modifyBOCOOrder({
exchOrderId: "1100000008697274",
price: 215,
});📈 Market Data
Market Feed
const feed = await client.market.getMarketFeed([
{
Exch: "N",
ExchType: "D",
Symbol: "NIFTY 27 MAY 2021 CE 14500.00",
Expiry: "20210527",
StrikePrice: "14500",
OptionType: "CE",
},
]);
console.log(feed);Market Feed by Scrip
const feed = await client.market.getMarketFeedByScrip([
{
Exch: "N",
ExchType: "C",
ScripCode: 1660,
ScripData: "RELIANCE_EQ",
},
]);Market Depth
const depth = await client.market.getMarketDepth([
{ Exchange: "N", ExchangeType: "C", ScripCode: 1660 },
]);⏱ Historical Data
const candles = await client.market.getHistoricalData({
exchange: "N",
exchangeType: "C",
scripCode: 1660,
timeframe: "1m",
from: "2021-05-31",
to: "2021-06-01",
});Supported timeframes:
['1m', '5m', '10m', '15m', '30m', '60m', '1d']📚 API Structure Overview
client.auth; // authentication & tokens
client.orders; // holdings, orders, positions
client.market; // market feed, depth, historical data🛡️ Notes & Best Practices
- Always store access tokens securely
- Prefer access-token login for long-running services
- SDK expects Node.js 18+
- This SDK does not manage retries / rate limits yet
🧪 Development
npm run dev📄 License
MIT
🚧 Roadmap
- Typed API responses
- Runtime validation (Zod)
- Retry & rate-limit handling
- WebSocket feed support
- npm public release
