Skip to main content
Glama

Sell-Stock

Execute market sell orders for stocks on Zerodha by specifying stock name and quantity to liquidate positions.

Instructions

This tool sells 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
stockYes
qtyYes

Implementation Reference

  • index.js:82-95 (registration)
    MCP tool registration for 'Sell-Stock', including name, description, Zod input schema, and inline handler function that initializes trading client and calls placeOrder for SELL.
    server.tool( "Sell-Stock", "This tool sells 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, "SELL"); return { content: [{ type: "text", text: String(response) }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } } );
  • index.js:86-94 (handler)
    The core handler function executed when Sell-Stock tool is called, handling input params, initializing ZerodhaTrading, placing SELL order, and returning response or error.
    async ({ stock, qty }) => { try { const trading = await initializeTrading(); const response = await trading.placeOrder(stock, qty, "SELL"); return { content: [{ type: "text", text: String(response) }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } }
  • Input validation schema using Zod for stock name (string) and quantity (number).
    { stock: z.string(), qty: z.number() },
  • Helper method in ZerodhaTrading class that performs the actual order placement via KiteConnect API, used by Sell-Stock handler for SELL transactions.
    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; }
  • Utility function to initialize ZerodhaTrading instance with a valid access token from TokenManager, called by Sell-Stock 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; } }

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