Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Real-time and historical stock and forex market data via Twelve Data API: quotes, OHLCV time series, and symbol search.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
tools/quote.py
1"""2Twelve Data Quote Tools — Real-time market quotes for stocks and forex.34Provides tools for fetching current market data including price, volume, and 52-week metrics.5"""67import logging8from typing import List910from core.tool import BaseTool, ToolContext, ToolResult11from .client import get_client, handle_api_error1213logger = logging.getLogger(__name__)141516class TwelveDataQuoteTool(BaseTool):17"""Get real-time quote for a stock or forex pair."""1819@property20def name(self) -> str:21return "twelvedata_quote"2223@property24def description(self) -> str:25return """Get real-time market quote for a stock or forex pair.2627Returns comprehensive current market data including:28- Current price, open, high, low, close29- Volume and trading data30- Price change and percent change31- 52-week high and low32- Previous close and timestamp3334Use this for current market analysis and live monitoring.3536Parameters:37- symbol: Stock symbol (e.g., AAPL, MSFT, TSLA) or forex pair (e.g., EUR/USD, GBP/JPY)38- prepost: (optional) Include pre/post-market data when available (US/Cboe Europe, Pro+ only)3940Returns: Real-time quote with all current market metrics"""4142@property43def parameters(self) -> dict:44return {45"type": "object",46"properties": {47"symbol": {48"type": "string",49"description": "Stock symbol (AAPL, MSFT) or forex pair (EUR/USD, GBP/JPY)",50},51"prepost": {52"type": "boolean",53"description": "Include pre/post-market data when available (US/Cboe Europe, Pro+ only)",54},55},56"required": ["symbol"],57}5859async def execute(self, ctx: ToolContext, symbol: str = "", prepost: bool = False, **kwargs) -> ToolResult:60if not symbol:61return ToolResult(success=False, error="'symbol' is required")62try:63data = await get_client().get_quote(symbol=symbol, prepost=prepost)64if data.get("status") == "error":65return ToolResult(success=False, error=f"API Error: {data.get('message', 'Unknown error')}")66return ToolResult(success=True, output=data)67except Exception as e:68return handle_api_error(e)697071class TwelveDataQuoteBatchTool(BaseTool):72"""Get real-time quotes for multiple stocks or forex pairs at once."""7374@property75def name(self) -> str:76return "twelvedata_quote_batch"7778@property79def description(self) -> str:80return """Get real-time quotes for multiple stocks or forex pairs in a single API call.8182Efficient way to fetch market data for multiple symbols simultaneously. Maximum 120 symbols per request.8384Parameters:85- symbols: Array of stock symbols or forex pairs (max 120)86- prepost: (optional) Include pre/post-market data when available (US/Cboe Europe, Pro+ only)8788Returns: Quotes for all requested symbols"""8990@property91def parameters(self) -> dict:92return {93"type": "object",94"properties": {95"symbols": {96"type": "array",97"items": {"type": "string"},98"description": "Array of stock symbols or forex pairs (max 120)",99"minItems": 1,100"maxItems": 120,101},102"prepost": {103"type": "boolean",104"description": "Include pre/post-market data when available (US/Cboe Europe, Pro+ only)",105},106},107"required": ["symbols"],108}109110async def execute(self, ctx: ToolContext, symbols: List[str] = None, prepost: bool = False, **kwargs) -> ToolResult:111if not symbols:112return ToolResult(success=False, error="'symbols' array is required and must not be empty")113try:114data = await get_client().get_quote_batch(symbols=symbols, prepost=prepost)115if data.get("status") == "error":116return ToolResult(success=False, error=f"API Error: {data.get('message', 'Unknown error')}")117return ToolResult(success=True, output=data)118except Exception as e:119return handle_api_error(e)120121122class TwelveDataPriceBatchTool(BaseTool):123"""Get latest prices for multiple stocks or forex pairs at once."""124125@property126def name(self) -> str:127return "twelvedata_price_batch"128129@property130def description(self) -> str:131return """Get latest trading prices for multiple stocks or forex pairs in a single API call.132133Lightweight endpoint for quick price checks on multiple symbols. Maximum 120 symbols per request.134135Parameters:136- symbols: Array of stock symbols or forex pairs (max 120)137- prepost: (optional) Include pre/post-market data when available (US/Cboe Europe, Pro+ only)138139Returns: Current prices for all requested symbols"""140141@property142def parameters(self) -> dict:143return {144"type": "object",145"properties": {146"symbols": {147"type": "array",148"items": {"type": "string"},149"description": "Array of stock symbols or forex pairs (max 120)",150"minItems": 1,151"maxItems": 120,152},153"prepost": {154"type": "boolean",155"description": "Include pre/post-market data when available (US/Cboe Europe, Pro+ only)",156},157},158"required": ["symbols"],159}160161async def execute(self, ctx: ToolContext, symbols: List[str] = None, prepost: bool = False, **kwargs) -> ToolResult:162if not symbols:163return ToolResult(success=False, error="'symbols' array is required and must not be empty")164try:165data = await get_client().get_price_batch(symbols=symbols, prepost=prepost)166if data.get("status") == "error":167return ToolResult(success=False, error=f"API Error: {data.get('message', 'Unknown error')}")168return ToolResult(success=True, output=data)169except Exception as e:170return handle_api_error(e)171