Show-Portfolio
Display the current portfolio of a user on the Zerodha Trading Bot, enabling real-time tracking of holdings and assets for informed decision-making in automated trading.
Instructions
This tool shows the current portfolio of the given user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:97-109 (registration)Registration of the "Show-Portfolio" MCP tool, which has no input parameters and delegates to ZerodhaTrading.getAllHoldings() via an initialized trading instance.server.tool( "Show-Portfolio", "This tool shows the current portfolio of the given user", async () => { try { const trading = await initializeTrading(); const response = await trading.getAllHoldings(); return { content: [{ type: "text", text: String(response) }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } } );
- trading.js:60-77 (helper)Core implementation that retrieves positions using KiteConnect.getPositions() and formats them into a string representing the portfolio.async getAllHoldings() { try{ const holdings = await this.kc.getPositions(); let allHoldings = " "; for(const holdings of holdings) { allHoldings += `stock:{holding.tradingsymbol} qty:{holding.quantity} avg_price:{holding.average_price} current_price:{holding.last_price}` allHoldings += `\n` } return allHoldings; } catch(err) { throw new Error(`Error getting all holdings: ${err.message}`); } }
- index.js:16-24 (helper)Helper function to initialize the ZerodhaTrading instance with a valid access token, used by the Show-Portfolio handler.async function initializeTrading() { try { const accessToken = await tokenManager.getValidToken(); return new ZerodhaTrading(apiKey, accessToken); } catch (error) { console.error("Error initializing trading:", error.message); throw error; } }