The `smartapi-javascript` package provides a client-side SDK for programmatic interaction with the SmartAPI platform, an initiative by Angel One (formerly Angel Broking) for the Indian stock market. It offers a comprehensive suite of functionalities, including user authentication and session management, fetching profile and real-time margin (RMS) details, executing various order types (place, modify, cancel, order book, trade book), managing portfolio holdings and positions, converting positions, and handling Good Till Triggered (GTT) orders. Additionally, it provides access to historical candle data and includes WebSocket functionality for real-time market updates. The current stable version is 1.0.27. As an official client library for a specific financial service, its release cadence typically aligns with updates to the SmartAPI platform itself. A key differentiator is its direct and tailored integration with Angel One's trading ecosystem, simplifying development for users targeting this platform. The library currently emphasizes CommonJS `require` syntax for module imports, as demonstrated in its official documentation.
npm install smartapi-javascriptVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the SmartAPI client, securely generate a user session with credentials (client code, password, TOTP), and then use the authenticated session to fetch the user's profile details. It also includes commented-out examples for various trading operations like placing orders and retrieving the order book, along with a custom session expiry hook to manage re-authentication.
Store credentials in environment variables (e.g., `process.env.SMARTAPI_API_KEY`) and access them at runtime. Never commit sensitive data to version control.
Implement the `setSessionExpiryHook` callback to catch session expiry events. Within this hook, trigger your re-authentication flow (e.g., by calling `generateSession` again) or inform the user.
Ensure your Node.js project is configured for CommonJS if using `require`. If you intend to use `import`, ensure your project is set up for ES Modules (e.g., by setting `"type": "module"` in `package.json` and potentially using transpilers) or verify if a dual package is provided.
Consult the official SmartAPI documentation or SDK source code to understand the differences between `WebSocket` and `WebSocketV2` and determine which is the most current or appropriate for your specific real-time data needs.
Double-check all credentials (API key, client code, password, TOTP) for correctness. Ensure your session has not expired; if so, trigger re-authentication. Verify that the API key is active for your account.
For this SDK version, switch to CommonJS by ensuring your file is `.js` and your `package.json` does not declare `"type": "module"`. If you must use ESM, you might need to dynamically `import()` the SDK or find an ESM-compatible wrapper.
Ensure that `smart_api.generateSession()` successfully completes before attempting any further API calls. Handle the `.catch()` block of `generateSession` to debug credential issues.
No dependency data recorded yet.