{"_id":"5paisa-ts","name":"5paisa-ts","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"5paisa-ts","version":"0.1.0","description":"TypeScript SDK for 5paisa APIs","type":"module","main":"./dist/index.js","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build":"tsc -p tsconfig.json","watch":"tsc -w -p tsconfig.json","test":"bun test","prepublishOnly":"npm run build"},"engines":{"node":">=18.0.0"},"keywords":["5paisa","sdk","trading","typescript","stock","broker","api","india","nse","bse"],"author":{"name":"bshada"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/bshada/5paisa-ts.git"},"bugs":{"url":"https://github.com/bshada/5paisa-ts/issues"},"homepage":"https://github.com/bshada/5paisa-ts#readme","sideEffects":false,"devDependencies":{"typescript":"^5.6.3"},"_id":"5paisa-ts@0.1.0","_nodeVersion":"22.20.0","_npmVersion":"11.6.4","dist":{"integrity":"sha512-4JJh3SbzlriZglshKuTl4ZsgADc5GLSIi8dlsNRzdtjaw7Qaz3f3t/pcLep0DivXfXXrq68dALCcRwmKIjeS6g==","shasum":"c414978ec0368c7f7527524f2ff1edd813228d3d","tarball":"https://registry.npmjs.org/5paisa-ts/-/5paisa-ts-0.1.0.tgz","fileCount":26,"unpackedSize":166825,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCJz+O0lFXOdi0hrVQ4MAfAy4DXS/S9uBr5jlLEoJv15wIhAJdMKe+TZtkbiu50QRFdhjg4S8Qf65Rwcmw6uFQJRYRf"}]},"_npmUser":{"name":"bshada","email":"bshada@snipy.in"},"directories":{},"maintainers":[{"name":"bshada","email":"bshada@snipy.in"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/5paisa-ts_0.1.0_1764505512823_0.9558599791254767"},"_hasShrinkwrap":false}},"time":{"created":"2025-11-30T12:25:12.822Z","0.1.0":"2025-11-30T12:25:13.034Z","modified":"2025-11-30T12:25:13.311Z"},"maintainers":[{"name":"bshada","email":"bshada@snipy.in"}],"description":"TypeScript SDK for 5paisa APIs","homepage":"https://github.com/bshada/5paisa-ts#readme","keywords":["5paisa","sdk","trading","typescript","stock","broker","api","india","nse","bse"],"repository":{"type":"git","url":"git+https://github.com/bshada/5paisa-ts.git"},"author":{"name":"bshada"},"bugs":{"url":"https://github.com/bshada/5paisa-ts/issues"},"license":"MIT","readme":"# 5paisa TypeScript SDK\n\nTypeScript SDK for 5paisa APIs.\n\n---\n\n## Installation\n\n```sh\nnpm install 5paisa-ts\n# or\npnpm add 5paisa-ts\n# or\nbun add 5paisa-ts\n```\n\nThe package targets Node.js 18+ (or compatible runtimes such as Bun) where `fetch` and `WebSocket` are available globally.\n\n---\n\n## Getting started\n\n```ts\nimport {\n  FivePaisaClient,\n  type FivePaisaCredentials,\n} from '5paisa-ts';\n\nconst credentials: FivePaisaCredentials = {\n  APP_NAME: 'YOUR_APP_NAME',\n  APP_SOURCE: 'YOUR_APP_SOURCE',\n  USER_ID: 'YOUR_USER_ID',\n  PASSWORD: 'YOUR_PASSWORD',\n  USER_KEY: 'YOUR_USER_KEY',\n  ENCRYPTION_KEY: 'YOUR_ENCRYPTION_KEY',\n};\n\nconst client = new FivePaisaClient(credentials);\n\n// Example: authenticate using an OAuth request token from 5paisa\nconst accessToken = await client.getOauthSession('REQUEST_TOKEN_FROM_5PAISA');\n\n// Or: if you already have an access token\nclient.setAccessToken(accessToken, 'CLIENT_CODE');\n\n// Fetch basic information\nconst holdings = await client.holdings();\nconst margin = await client.margin();\n\nconsole.log('Holdings', holdings);\nconsole.log('Margin', margin);\n```\n\nFor full API authentication details, see the sections below.\n\n---\n\n## Credentials and authentication\n\n### 1. Configure API keys\n\nGet your API keys from the 5paisa developer portal and keep them outside of source control (for example in env files):\n\n```conf\n[KEYS]\nAPP_NAME=YOUR_APP_NAME\nAPP_SOURCE=YOUR_APP_SOURCE\nUSER_ID=YOUR_USER_ID\nPASSWORD=YOUR_PASSWORD\nUSER_KEY=YOUR_USER_KEY\nENCRYPTION_KEY=YOUR_ENCRYPTION_KEY\n```\n\n### 2. Create a client\n\n```ts\nimport {\n  FivePaisaClient,\n  type FivePaisaCredentials,\n} from '5paisa-ts';\n\nconst credentials: FivePaisaCredentials = {\n  APP_NAME: process.env.APP_NAME!,\n  APP_SOURCE: process.env.APP_SOURCE!,\n  USER_ID: process.env.USER_ID!,\n  PASSWORD: process.env.PASSWORD!,\n  USER_KEY: process.env.USER_KEY!,\n  ENCRYPTION_KEY: process.env.ENCRYPTION_KEY!,\n};\n\nconst client = new FivePaisaClient(credentials);\n```\n\n### 3. OAuth request token flow\n\nThis is the recommended flow and mirrors the `py5paisa` behaviour.\n\n1. Log in to the vendor login url from a browser and obtain a short lived request token.\n2. Exchange the request token for an access token.\n\n```ts\n// After you obtain `requestToken` from the 5paisa login redirect url:\nconst accessToken = await client.getOauthSession(requestToken);\n\n// You can also call getAccessToken(requestToken) directly\n// const accessToken = await client.getAccessToken(requestToken);\n\nconsole.log('Access token', accessToken);\n```\n\nOnce you have the token, you can reuse it on a new process without repeating the browser flow:\n\n```ts\nclient.setAccessToken(accessToken, 'CLIENT_CODE');\n```\n\n### 4. TOTP + PIN flow\n\nThe client also exposes the TOTP login flow equivalent to the Python SDK.\n\n```ts\n// Step 1: request token via TOTP + PIN\nconst requestToken = await client.getRequestToken(\n  'CLIENT_CODE',\n  'TOTP_VALUE',\n  'PIN',\n);\n\n// Step 2: exchange the request token for access token\nif (requestToken) {\n  const accessToken = await client.getAccessToken(requestToken);\n  console.log('Access token', accessToken);\n}\n\n// Or use the convenience helper which does both steps internally\nconst accessTokenFromTotp = await client.getTotpSession(\n  'CLIENT_CODE',\n  'TOTP_VALUE',\n  'PIN',\n);\n```\n\n### 5. Session helpers\n\nThe following helpers are available for session management and diagnostics:\n\n- `getAccessToken(requestToken?)`  get or refresh the current access token\n- `getOauthSession(requestToken)`  convenience wrapper around `getAccessToken`\n- `getTotpSession(clientCode, totp, pin)`  run the full TOTP login flow\n- `setAccessToken(accessToken, clientCode)`  set an existing token and client code\n- `loginCheck()`  validate an existing session for the current client code\n- `jwtValidate()`  validate the current JWT token and get the message from the server\n\n---\n\n## Working with scrip master and symbols\n\nThe TypeScript client provides the same scrip master utilities as `py5paisa`.\n\n### Fetch the full scrip master\n\n```ts\nconst scrips = await client.getScrips();\nconsole.log('Total scrips', scrips.length);\n```\n\n### Query a specific scrip\n\nThe arguments map to the Python `query_scrips` function: exchange, exchangeType, symbol, strike, type, expiry.\n\n```ts\n// Example: cash equity\nconst cash = await client.queryScrips(\n  'N',      // exchange\n  'C',      // exchange type\n  'ITC',    // symbol\n  '0',      // strike, 0 for cash stocks\n  'XX',     // type: XX for cash and futures, EQ for indices, CE or PE for options\n  '',       // expiry (empty for cash)\n);\n\n// Example: options\nconst options = await client.queryScrips(\n  'N',\n  'D',\n  'NIFTY',\n  '22300',\n  'CE',\n  '2024-04-25',\n);\n```\n\n---\n\n## User information, reports and portfolio\n\nThese methods give you holdings, positions, margins and reports.\n\n```ts\n// Holdings\nconst holdings = await client.holdings();\n\n// Margin\nconst margin = await client.margin();\n\n// Net positions (current positions)\nconst positions = await client.positions();\n\n// Day-wise net positions\nconst intradayPositions = await client.positionsDay();\n\n// Order book\nconst orderBook = await client.orderBook();\n\n// Trade book\nconst tradeBook = await client.getTradebook();\n\n// Idea buy and trade recommendations\nconst buyIdeas = await client.getBuy();\nconst tradeIdeas = await client.getTrade();\n\n// Tax report\nconst taxReport = await client.taxReport('2024-01-01', '2024-06-26');\n\n// Ledger report\nconst ledger = await client.fetchLedger('2024-01-01', '2024-06-26');\n```\n\nThe `taxReport` and `fetchLedger` helpers validate the date format and ensure that `fromDate` is not later than `toDate`.\n\n---\n\n## Market data and option chain\n\n### Market feed (snapshot)\n\n```ts\n// Example option instruments for NIFTY\nconst reqList = [\n  {\n    Exch: 'N',\n    ExchType: 'D',\n    Symbol: 'NIFTY 22 APR 2021 CE 15200.00',\n    Expiry: '20210422',\n    StrikePrice: '15200',\n    OptionType: 'CE',\n  },\n  {\n    Exch: 'N',\n    ExchType: 'D',\n    Symbol: 'NIFTY 22 APR 2021 PE 15200.00',\n    Expiry: '20210422',\n    StrikePrice: '15200',\n    OptionType: 'PE',\n  },\n];\n\nconst feed = await client.fetchMarketFeed(reqList);\nconsole.log(feed);\n```\n\n### Market feed by scrip\n\nWhen you already know the scrip code, you can use `fetchMarketFeedScrip`.\n\n```ts\nconst scripFeed = await client.fetchMarketFeedScrip([\n  { Exch: 'N', ExchType: 'C', ScripCode: 2885 },\n]);\n```\n\n### Market status\n\n```ts\nconst marketStatus = await client.getMarketStatus();\nconsole.log(marketStatus);\n```\n\n### Market depth and snapshot\n\n```ts\n// Market depth from the V3 endpoint\nconst depth = await client.fetchMarketDepth([\n  { Exch: 'N', ExchType: 'C', ScripCode: 1660 },\n]);\n\n// Market depth by symbol\nconst depthBySymbol = await client.fetchMarketDepthBySymbol([\n  {\n    Exch: 'N',\n    ExchType: 'C',\n    Symbol: 'RELIANCE',\n  },\n]);\n\n// Market depth by scrip convenience helper\nconst depthByScrip = await client.fetchMarketDepthByScrip({\n  Exchange: 'N',\n  ExchangeType: 'C',\n  ScripCode: '1660',\n});\n\n// Full market snapshot for multiple scrips\nconst snapshot = await client.fetchMarketSnapshot([\n  { Exchange: 'N', ExchangeType: 'C', ScripCode: '2885' },\n  { Exchange: 'N', ExchangeType: 'C', ScripData: 'ITC_EQ' },\n]);\n```\n\n### Option chain\n\n```ts\n// Get all active expiries for a symbol\nconst expiries = await client.getExpiry('N', 'NIFTY');\n\n// Pick one expiry timestamp from the response and fetch the option chain\nconst someExpiryTs = 1647507600000;\nconst optionChain = await client.getOptionChain('N', 'NIFTY', someExpiryTs);\n```\n\n### Historical OHLC data\n\n```ts\n// historicalData(exch, exchangeSegment, scripCode, timeframe, from, to)\nconst candles = await client.historicalData(\n  'N',\n  'C',\n  1660,\n  '15m',\n  '2021-05-25',\n  '2021-06-16',\n);\n\nconsole.log(candles);\n```\n\nAccepted time frames: `1m`, `3m`, `5m`, `10m`, `15m`, `30m`, `60m`, `1d`.\n\n---\n\n## Placing, modifying and cancelling orders\n\nThe core order placement APIs mirror those from `py5paisa`.\n\n### Basic cash order\n\n```ts\nimport {\n  FivePaisaClient,\n  type FivePaisaCredentials,\n  Exchange,\n  ExchangeSegment,\n} from '5paisa-ts';\n\n// ... create credentials and client as shown earlier\n\nawait client.placeOrder({\n  Exchange: Exchange.NSE,            // or 'N'\n  ExchangeType: ExchangeSegment.CASH, // or 'C'\n  ScripCode: 1660,\n  Qty: 1,\n  Price: 205,\n  OrderType: 'B',                    // B for buy, S for sell\n  IsIntraday: true,\n});\n```\n\n### Stop loss order\n\n```ts\nawait client.placeOrder({\n  Exchange: Exchange.NSE,\n  ExchangeType: ExchangeSegment.CASH,\n  ScripCode: 1660,\n  Qty: 1,\n  Price: 208,\n  OrderType: 'B',\n  IsIntraday: true,\n  IsStopLossOrder: true,\n  StopLossPrice: 207.5,\n});\n```\n\n### After market orders\n\nPass `AHPlaced: AHPlaced.AFTER_MARKET_CLOSED` for offline orders.\n\n```ts\nimport { AHPlaced } from '5paisa-ts';\n\nawait client.placeOrder({\n  Exchange: Exchange.NSE,\n  ExchangeType: ExchangeSegment.CASH,\n  ScripCode: 1660,\n  Qty: 1,\n  Price: 205,\n  OrderType: 'B',\n  IsIntraday: false,\n  AHPlaced: AHPlaced.AFTER_MARKET_CLOSED,\n});\n```\n\n### Modify and cancel\n\n```ts\n// Modify an order\nawait client.modifyOrder({\n  ExchOrderID: '1100000017861430',\n  Price: 261,\n});\n\n// Cancel an order\nawait client.cancelOrder('1100000017795041');\n\n// Cancel multiple regular orders in bulk\nawait client.cancelBulkOrder([\n  { ExchOrderID: 'ORDER_ID_1' },\n  { ExchOrderID: 'ORDER_ID_2' },\n]);\n```\n\n### Bracket and cover orders\n\n```ts\n// Bracket order\nawait client.boOrder({\n  Exchange: 'N',\n  ExchangeType: 'C',\n  ScripCode: 1660,\n  OrderType: 'B',\n  Qty: 1,\n  LimitPriceInitialOrder: 330,\n  TriggerPriceInitialOrder: 0,\n  LimitPriceProfitOrder: 345,\n  TriggerPriceForSL: 320,\n  RequestType: 'P',\n  AtMarket: false,\n});\n\n// Modify bracket order\nawait client.modifyBoOrder({\n  ExchangeOrderID: '1100000017861430',\n  LimitPriceInitialOrder: 331,\n  LimitPriceProfitOrder: 346,\n});\n\n// Cancel a bracket order leg\nawait client.cancelBoOrder({\n  ExchangeOrderID: '1100000017861430',\n});\n\n// Cover order\nawait client.coverOrder({\n  Exchange: 'N',\n  ExchangeType: 'C',\n  ScripCode: 1660,\n  OrderType: 'B',\n  Qty: 1,\n  LimitPriceInitialOrder: 330,\n  TriggerPriceForSL: 320,\n});\n\n// Modify cover order\nawait client.modifyCoverOrder({\n  ExchangeOrderID: '1100000017861430',\n  TriggerPriceForSL: 321,\n});\n\n// Cancel cover order leg\nawait client.cancelCoverOrder({\n  ExchangeOrderID: '1100000017861430',\n});\n```\n\n> Note: for cover orders, using `LimitPriceProfitOrder: 0` is equivalent to the Python behaviour.\n\n### Order margin calculation\n\nSingle order margin:\n\n```ts\nconst marginResponse = await client.orderMargin({\n  AtMarket: 'Y',\n  LimitRate: 0,\n  // other fields as per 5paisa order margin api\n});\n```\n\nMulti leg margin for strategies:\n\n```ts\nconst marginForMultipleOrders = await client.multiOrderMargin({\n  CoverPositions: 'Y',\n  Orders: [\n    {\n      Exch: 'N',\n      ExchType: 'C',\n      ScripCode: 2885,\n      PlaceModifyCancel: 'P',\n      OrderType: 'B',\n      Price: 0,\n      Qty: 1,\n      IsIntraday: false,\n    },\n    {\n      Exch: 'B',\n      ExchType: 'C',\n      ScripCode: 512070,\n      PlaceModifyCancel: 'P',\n      OrderType: 'S',\n      Price: 0,\n      Qty: 1,\n      IsIntraday: true,\n    },\n  ],\n});\n```\n\n### Square off and position conversion\n\n```ts\n// Convert an existing position\nawait client.positionConversion(\n  'N',          // Exch\n  'C',          // ExchType\n  'BPCL_EQ',    // ScripData\n  'B',          // TradeType (B or S)\n  5,            // ConvertQty\n  'D',          // ConvertFrom (D or I)\n  'I',          // ConvertTo (D or I)\n);\n\n// Square off all open positions\nawait client.squareoffAll();\n```\n\n### Bulk order placement\n\n```ts\nconst bulkOrderPayload = {\n  Exchange: 'N',\n  ExchangeType: 'C',\n  OrderList: [\n    {\n      Exchange: 'N',\n      ExchangeType: 'C',\n      ScripCode: 0,\n      ScripData: 'ITC_EQ',\n      Price: '440',\n      OrderType: 'Buy',\n      Qty: 1,\n      DisQty: '0',\n      StopLossPrice: '0',\n      IsIntraday: true,\n      iOrderValidity: '0',\n      RemoteOrderID: '50000091_220620',\n    },\n    {\n      Exchange: 'N',\n      ExchangeType: 'C',\n      ScripCode: 0,\n      ScripData: 'IDEA_EQ',\n      Price: '15',\n      OrderType: 'Buy',\n      Qty: 1,\n      DisQty: '0',\n      StopLossPrice: '0',\n      IsIntraday: true,\n      iOrderValidity: '0',\n      RemoteOrderID: '50000091_220620',\n    },\n  ],\n};\n\nawait client.placeOrderBulk(bulkOrderPayload);\n```\n\n---\n\n## Basket orders\n\nThe SDK exposes a `BasketOrder` class and a family of basket helper methods.\n\n```ts\nimport { BasketOrder } from '5paisa-ts';\n\n// Create a new basket\nawait client.createBasket('My strategy basket');\n\n// Get all baskets\nconst baskets = await client.getBasket();\n\n// Rename a basket\nawait client.renameBasket('Renamed strategy basket', 1234);\n\n// Clone an existing basket\nawait client.cloneBasket(1234);\n\n// Delete baskets in bulk\nawait client.deleteBasket([\n  { BasketID: '1234' },\n  { BasketID: '5678' },\n]);\n\n// Add an order to one or more baskets\nconst orderToBasket = new BasketOrder({\n  Exchange: 'N',\n  ExchangeType: 'C',\n  Price: 23000,\n  OrderType: 'BUY',\n  Qty: 1,\n  ScripCode: '1660',\n  DelvIntra: 'I',\n});\n\nconst basketList = [\n  { BasketID: '1234' },\n  { BasketID: '5678' },\n];\n\nawait client.addBasketOrder(orderToBasket, basketList);\n\n// Execute a basket\nawait client.executeBasket(1234);\n\n// Get orders inside a basket\nconst ordersInBasket = await client.getOrderInBasket(1234);\n\n// Margin required for a basket\nconst basketMargin = await client.basketMargin('1234', 'Y');\n```\n\n---\n\n## Order status, trades and history\n\n```ts\n// Trade information\nconst tradeInfoRequest = [\n  {\n    Exch: 'N',\n    ExchType: 'C',\n    ScripCode: 20374,\n    ExchOrderID: '1000000015310807',\n  },\n];\n\nconst tradeInfo = await client.fetchTradeInfo(tradeInfoRequest);\n\n// Order status\nconst orderStatusRequest = [\n  {\n    Exch: 'N',\n    ExchType: 'C',\n    ScripCode: 20374,\n    RemoteOrderID: '90980441',\n  },\n];\n\nconst orderStatus = await client.fetchOrderStatus(orderStatusRequest);\n\n// Trade history by exchange order id\nconst history = await client.getTradeHistory('1000000015310807');\n```\n\n---\n\n## WebSocket streaming\n\nWebSocket streaming closely follows the Python `Request_Feed`, `connect` and `receive_data` helpers.\n\n### Subscribe to one or more scrips\n\n```ts\nimport {\n  FivePaisaClient,\n  type FivePaisaCredentials,\n} from '5paisa-ts';\n\nconst credentials: FivePaisaCredentials = {\n  APP_NAME: 'YOUR_APP_NAME',\n  APP_SOURCE: 'YOUR_APP_SOURCE',\n  USER_ID: 'YOUR_USER_ID',\n  PASSWORD: 'YOUR_PASSWORD',\n  USER_KEY: 'YOUR_USER_KEY',\n  ENCRYPTION_KEY: 'YOUR_ENCRYPTION_KEY',\n};\n\nconst client = new FivePaisaClient(credentials);\n\n// Authenticate first using OAuth or TOTP so that jwtToken and clientCode are set\nawait client.getOauthSession('REQUEST_TOKEN');\n\nconst subscribeList = [\n  { Exch: 'N', ExchType: 'C', ScripCode: 1660 },\n  { Exch: 'N', ExchType: 'D', ScripCode: 61211 },\n];\n\nconst payload = client.requestFeed('mf', 's', subscribeList);\n\nclient.connect(payload);\n\nclient.receiveData((event) => {\n  const data = JSON.parse(event.data as string);\n  console.log('Tick', data);\n});\n```\n\n### Unsubscribe and close\n\n```ts\n// Unsubscribe from specific scrips\nconst unsubscribePayload = client.requestFeed('mf', 'u', [\n  { Exch: 'N', ExchType: 'C', ScripCode: 1660 },\n]);\n\nclient.connect(unsubscribePayload);\n\n// Close websocket\nclient.closeData();\n```\n\nYou can also use `sendData` to attach a custom `onopen` handler and `errorData` to attach an error handler.\n\n### 20 depth market data\n\nThe `socket20Depth` helper maps to the Python `socket_20_depth` utility.\n\n```ts\nconst depthPayload = {\n  method: 'subscribe',\n  operation: '20depth',\n  instruments: ['NC2885'],\n};\n\nawait client.socket20Depth(depthPayload);\n\nclient.receiveData((event) => {\n  const data = JSON.parse(event.data as string);\n  console.log('Depth 20 tick', data);\n});\n```\n\n---\n\n## Strategy execution (Strategies class)\n\nThe `Strategies` class is a TypeScript port of `py5paisa.strategy.strategies`. It executes multi leg strategies as market orders; use it with care.\n\n```ts\nimport {\n  Strategies,\n  type FivePaisaCredentials,\n} from '5paisa-ts';\n\nconst credentials: FivePaisaCredentials = {\n  APP_NAME: 'YOUR_APP_NAME',\n  APP_SOURCE: 'YOUR_APP_SOURCE',\n  USER_ID: 'YOUR_USER_ID',\n  PASSWORD: 'YOUR_PASSWORD',\n  USER_KEY: 'YOUR_USER_KEY',\n  ENCRYPTION_KEY: 'YOUR_ENCRYPTION_KEY',\n};\n\n// Use either requestToken or clientCode + TOTP + PIN\nconst strategy = new Strategies(credentials, 'CLIENT_CODE', 'TOTP_VALUE', 'PIN');\n\n// Each of the following executes a full strategy at market\nawait strategy.shortStraddle('banknifty', '37000', 50, '20210610', 'I', {\n  tag: 'MyShortStraddle',\n});\n\nawait strategy.shortStrangle('banknifty', ['35300', '37000'], 50, '20210610', 'D', {\n  tag: 'MyShortStrangle',\n});\n\nawait strategy.longStraddle('banknifty', '37000', 50, '20210610', 'I', {\n  tag: 'MyLongStraddle',\n});\n\nawait strategy.longStrangle('banknifty', ['35300', '37000'], 50, '20210610', 'D', {\n  tag: 'MyLongStrangle',\n});\n\nawait strategy.ironCondor('NIFTY', ['15000', '15200'], ['15100', '15150'], 75, '20210603', 'I', {\n  tag: 'MyIronCondor',\n});\n\nawait strategy.ironFly('NIFTY', ['15000', '15200'], '15100', 75, '20210610', 'I', {\n  tag: 'MyIronFly',\n});\n\nawait strategy.callCalendar('nifty', '15600', 75, ['20210603', '20210610'], 'I', {\n  tag: 'MyCallCalendar',\n});\n\nawait strategy.putCalendar('nifty', '15600', 75, ['20210603', '20210610'], 'I', {\n  tag: 'MyPutCalendar',\n});\n\n// Square off all legs that were tagged with a given strategy tag\nawait strategy.squareoff('MyIronCondor');\n```\n\n**Strategies methods covered:**\n\n- `shortStraddle`\n- `shortStrangle`\n- `longStraddle`\n- `longStrangle`\n- `ironFly`\n- `ironCondor`\n- `callCalendar`\n- `putCalendar`\n- `squareoff`\n\n---\n\n## Types, enums and helper classes\n\nThe SDK exports several enums and classes to help you build strongly typed payloads.\n\n### Order related enums\n\n```ts\nimport {\n  Exchange,\n  ExchangeSegment,\n  OrderFor,\n  OrderSide,\n  OrderValidity,\n  AHPlaced,\n  RequestType,\n} from '5paisa-ts';\n\n// Examples\nconst ex = Exchange.NSE;            // 'N'\nconst seg = ExchangeSegment.DERIVATIVE; // 'D'\nconst side = OrderSide.BUY;        // 'BUY'\nconst validity = OrderValidity.DAY; // 0\n```\n\n### Order, BoCoOrder and BasketOrder classes\n\n```ts\nimport {\n  Order,\n  BoCoOrder,\n  BasketOrder,\n} from '5paisa-ts';\n\nconst order = new Order({\n  exchange: Exchange.NSE,\n  exchangeSegment: ExchangeSegment.CASH,\n  price: 205,\n  orderType: 'B',\n  quantity: 1,\n  scripCode: 1660,\n  isIntraday: true,\n});\n\nconst bracket = new BoCoOrder({\n  scripCode: 1660,\n  qty: 1,\n  limitPriceInitialOrder: 330,\n  triggerPriceInitialOrder: 0,\n  limitPriceProfitOrder: 345,\n  buySell: 'B',\n  exch: 'N',\n  exchType: 'C',\n  requestType: 'P',\n  limitPriceForSL: 320,\n  triggerPriceForSL: 320,\n});\n\nconst basketOrder = new BasketOrder({\n  Exchange: 'N',\n  ExchangeType: 'C',\n  Price: 23000,\n  OrderType: 'BUY',\n  Qty: 1,\n  ScripCode: '1660',\n  DelvIntra: 'I',\n});\n```\n\nThese classes mirror the structure of the Python SDK and are primarily useful for building complex orders or reusing payloads.\n\n### Low level constants\n\nAdvanced users can also import the following from `5paisa-ts` for custom integrations:\n\n- `HEADERS`, `GENERIC_PAYLOAD`, `LOGIN_PAYLOAD`, `LOGIN_CHECK_PAYLOAD`\n- `WS_PAYLOAD`, `JWT_HEADERS`, `JWT_PAYLOAD`, `SOCKET_DEPTH_PAYLOAD`\n- `VTT_TYPE`, `SUBSCRIPTION_KEY`, `TODAY_TIMESTAMP`, `NEXT_DAY_TIMESTAMP`\n- All route constants from `urlconst.ts` such as `BASE_URL`, `LOGIN_ROUTE`, `SCRIP_MASTER_ROUTE`, `ORDER_PLACEMENT_ROUTE`, `HISTORICAL_DATA_ROUTE`, `MARKET_FEED_ROUTE`, etc.\n\nThese are not required for normal usage, but are exported for completeness and advanced scenarios.\n\n---\n\n## Complete FivePaisaClient api overview\n\nFor quick reference, the public methods on `FivePaisaClient` are:\n\n- **Authentication and session**\n  - `getRequestToken`\n  - `getOauthSession`\n  - `getAccessToken`\n  - `getTotpSession`\n  - `setAccessToken`\n  - `loginCheck`\n  - `jwtValidate`\n\n- **Scrip master**\n  - `getScrips`\n  - `queryScrips`\n\n- **User information and reports**\n  - `holdings`\n  - `margin`\n  - `orderBook`\n  - `positions`\n  - `positionsDay`\n  - `getTradebook`\n  - `getBuy`\n  - `getTrade`\n  - `taxReport`\n  - `fetchLedger`\n\n- **Market data**\n  - `fetchMarketFeed`\n  - `fetchMarketFeedScrip`\n  - `fetchMarketDepth`\n  - `fetchMarketDepthBySymbol`\n  - `fetchMarketDepthByScrip`\n  - `fetchMarketSnapshot`\n  - `getMarketStatus`\n  - `historicalData`\n  - `getExpiry`\n  - `getOptionChain`\n\n- **Orders and positions**\n  - `placeOrder`\n  - `modifyOrder`\n  - `cancelOrder`\n  - `cancelBulkOrder`\n  - `orderMargin`\n  - `multiOrderMargin`\n  - `placeOrderBulk`\n  - `positionConversion`\n  - `squareoffAll`\n  - `vttOrder`\n\n- **Basket orders**\n  - `getBasket`\n  - `createBasket`\n  - `renameBasket`\n  - `deleteBasket`\n  - `cloneBasket`\n  - `executeBasket`\n  - `getOrderInBasket`\n  - `addBasketOrder`\n  - `basketMargin`\n\n- **Order status, trades and history**\n  - `fetchOrderStatus`\n  - `fetchTradeInfo`\n  - `getTradeHistory`\n\n- **WebSocket and streaming**\n  - `requestFeed`\n  - `connect`\n  - `sendData`\n  - `receiveData`\n  - `closeData`\n  - `errorData`\n  - `socket20Depth`\n\nThis README, combined with the examples above, provides usage coverage for all of these methods as well as all exported strategy functions and helper types.\n","readmeFilename":"README.md","_rev":"1-94ac334714c53f491cf25fad0bb49fbf"}