Buy-Stock
Execute stock purchases on Zerodha platform for specified quantity and stock name at market price, enabling automated trading through the Zerodha Trading Bot.
Instructions
This tool buys a stock in the zerodha trading platform for the given quantity and stock name at the current market price for the given user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- index.js:67-80 (registration)MCP tool registration for 'Buy-Stock', including description, input schema {stock: z.string(), qty: z.number()}, and inline handler function that initializes ZerodhaTrading and calls placeOrder with 'BUY'.server.tool( "Buy-Stock", "This tool buys a stock in the zerodha trading platform for the given quantity and stock name at the current market price for the given user", { stock: z.string(), qty: z.number() }, async ({ stock, qty }) => { try { const trading = await initializeTrading(); const response = await trading.placeOrder(stock, qty, "BUY"); return { content: [{ type: "text", text: String(response) }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } } );
- trading.js:15-40 (handler)Core handler logic for buying stock: ZerodhaTrading.placeOrder method executes market order via KiteConnect for NSE CNC product.async placeOrder(tradingsymbol, quantity, type) { if (!tradingsymbol || !quantity || !type) { throw new Error( "Please provide all required parameters: tradingsymbol, quantity, and type" ); } try { const response = await this.kc.placeOrder("regular", { exchange: "NSE", tradingsymbol: tradingsymbol, transaction_type: type, quantity: quantity, product: "CNC", order_type: "MARKET", }); return response; } catch (err) { if (err.error_type === "InputException") { throw new Error( `Invalid trading symbol or order parameters: ${err.message}` ); } throw err; } }