Skip to main content
Glama

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
NameRequiredDescriptionDefault

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}` }] }; } } );
  • 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; } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yogendhra9/ZerodhaMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server