Skip to main content
Glama
jjmerri

E*TRADE MCP Server

by jjmerri

etrade_get_option_chains

Retrieve option chains for stocks to analyze available strikes and expiration dates for calls and puts using E*TRADE market data.

Instructions

Get option chains for a symbol.

Args: symbol: Underlying stock symbol (e.g., "AAPL") expiry_year: Expiration year (4-digit, e.g., 2024) expiry_month: Expiration month (1-12) expiry_day: Expiration day (1-31) strike_price_near: Strike price near this value no_of_strikes: Number of strikes to return include_weekly: Include weekly options skip_adjusted: Skip adjusted options option_category: STANDARD, ALL, or MINI chain_type: CALL, PUT, or CALLPUT price_type: ATNM (at the money) or ALL

Returns: Option chain data with available strikes and expiration dates

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYes
expiry_yearNo
expiry_monthNo
expiry_dayNo
strike_price_nearNo
no_of_strikesNo
include_weeklyNo
skip_adjustedNo
option_categoryNo
chain_typeNo
price_typeNo

Implementation Reference

  • The primary MCP tool handler for 'etrade_get_option_chains', registered via @mcp.tool() decorator. Handles input parameters and delegates to MarketClient.get_option_chains.
    @mcp.tool()
    def etrade_get_option_chains(symbol: str, expiry_year: Optional[int] = None,
                                expiry_month: Optional[int] = None, expiry_day: Optional[int] = None,
                                strike_price_near: Optional[float] = None, no_of_strikes: Optional[int] = None,
                                include_weekly: bool = False, skip_adjusted: bool = False,
                                option_category: Optional[str] = None, chain_type: Optional[str] = None,
                                price_type: Optional[str] = None) -> dict:
        """
        Get option chains for a symbol.
        
        Args:
            symbol: Underlying stock symbol (e.g., "AAPL")
            expiry_year: Expiration year (4-digit, e.g., 2024)
            expiry_month: Expiration month (1-12)
            expiry_day: Expiration day (1-31)
            strike_price_near: Strike price near this value
            no_of_strikes: Number of strikes to return
            include_weekly: Include weekly options
            skip_adjusted: Skip adjusted options
            option_category: STANDARD, ALL, or MINI
            chain_type: CALL, PUT, or CALLPUT
            price_type: ATNM (at the money) or ALL
            
        Returns:
            Option chain data with available strikes and expiration dates
        """
        client = get_market_client()
        return client.get_option_chains(
            symbol, expiry_year, expiry_month, expiry_day,
            strike_price_near, no_of_strikes, include_weekly, skip_adjusted,
            option_category, chain_type, price_type
        )
  • Core helper method in MarketClient that constructs the API request to E*TRADE's optionchains endpoint and returns the JSON response.
    def get_option_chains(self, symbol: str, expiry_year: Optional[int] = None,
                         expiry_month: Optional[int] = None, expiry_day: Optional[int] = None,
                         strike_price_near: Optional[float] = None, no_of_strikes: Optional[int] = None,
                         include_weekly: bool = False, skip_adjusted: bool = False,
                         option_category: Optional[str] = None, chain_type: Optional[str] = None,
                         price_type: Optional[str] = None) -> Dict[str, Any]:
        """
        Get option chains for a symbol
        
        Args:
            symbol: Underlying symbol
            expiry_year: Expiration year (4-digit)
            expiry_month: Expiration month (1-12)
            expiry_day: Expiration day (1-31)
            strike_price_near: Strike price near value
            no_of_strikes: Number of strikes
            include_weekly: Include weekly options
            skip_adjusted: Skip adjusted options
            option_category: Option category (STANDARD, ALL, MINI)
            chain_type: Chain type (CALL, PUT, CALLPUT)
            price_type: Price type (ATNM, ALL)
            
        Returns:
            Option chains response data
        """
        url = f"{self.base_url}/v1/market/optionchains.json"
        
        params = {"symbol": symbol}
        
        if expiry_year:
            params["expiryYear"] = expiry_year
        if expiry_month:
            params["expiryMonth"] = expiry_month
        if expiry_day:
            params["expiryDay"] = expiry_day
        if strike_price_near:
            params["strikePriceNear"] = strike_price_near
        if no_of_strikes:
            params["noOfStrikes"] = no_of_strikes
        if include_weekly:
            params["includeWeekly"] = "true"
        if skip_adjusted:
            params["skipAdjusted"] = "true"
        if option_category:
            params["optionCategory"] = option_category
        if chain_type:
            params["chainType"] = chain_type
        if price_type:
            params["priceType"] = price_type
        
        response = self.session.get(url, params=params)
        response.raise_for_status()
        
        return response.json()
    
    def get_option_expire_dates(self, symbol: str, expiry_type: Optional[str] = None) -> Dict[str, Any]:
        """
        Get option expiration dates for a symbol
        
        Args:
            symbol: Underlying symbol
            expiry_type: Expiry type (WEEKLY, MONTHLY, QUARTERLY, ALL)
            
        Returns:
            Expiration dates response data
        """
        url = f"{self.base_url}/v1/market/optionexpiredate.json"
        
        params = {"symbol": symbol}
        if expiry_type:
            params["expiryType"] = expiry_type
        
        response = self.session.get(url, params=params)
        response.raise_for_status()
        
        return response.json()
  • Helper function that provides the singleton authenticated MarketClient instance used by the tool handler.
    def get_market_client() -> MarketClient:
        """Get market client (requires authentication)"""
        global _market_client
        if _market_client is None:
            # Try to load access token from environment
            access_token = os.getenv("ETRADE_ACCESS_TOKEN")
            access_token_secret = os.getenv("ETRADE_ACCESS_TOKEN_SECRET")
            
            if access_token and access_token_secret:
                # Create session from stored tokens
                auth = get_auth()
                from rauth import OAuth1Session
                session = OAuth1Session(
                    auth.consumer_key,
                    auth.consumer_secret,
                    access_token=access_token,
                    access_token_secret=access_token_secret
                )
                _market_client = MarketClient(session, auth.base_url)
            else:
                raise ValueError(
                    "Not authenticated. Please run authenticate.py to get access tokens, "
                    "or use etrade_get_auth_url and etrade_authenticate tools."
                )
        return _market_client
  • Initialization of the FastMCP server instance where all @mcp.tool() decorators register their tools.
    mcp = FastMCP("E*TRADE Market API")

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/jjmerri/etrade-mcp'

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