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.
exports.py
1"""2TwelveData skill exports — script-mode skill.34Usage from a bash block:5python3 - <<'EOF'6import sys7sys.path.insert(0, "/data/workspace/skills/twelvedata")8from exports import twelvedata_price, twelvedata_time_series9print(twelvedata_price(symbol="AAPL"))10EOF1112Imports from sidecar.proxy_client (NOT core.http_client) so this skill13stays runnable without the agent platform's core/* modules on PYTHONPATH.14"""15import os1617# Make sidecar/ importable when the script is invoked directly via18# `python3 -c` from the agent's bash tool. /app is already on PYTHONPATH19# inside the container (set by entrypoint.sh), so `from sidecar...` works20# in production. The fallback covers local-dev runs from outside /app.21try:22from sidecar.proxy_client import proxied_get23except ImportError:24# Local dev / running outside the deployed image: fall back to25# core.http_client which is identical. Skill still works either way.26from core.http_client import proxied_get2728API_KEY = os.environ.get("TWELVEDATA_API_KEY", "")29BASE = "https://api.twelvedata.com"303132def _get(endpoint, params=None):33"""Make a GET request to TwelveData API."""34if params is None:35params = {}36params["apikey"] = API_KEY37r = proxied_get(f"{BASE}/{endpoint}", params=params)38r.raise_for_status()39return r.json()404142def twelvedata_time_series(symbol, interval="1day", outputsize=30, start_date=None, end_date=None, prepost=False):43"""Get OHLCV time series data."""44params = {"symbol": symbol, "interval": interval, "outputsize": outputsize}45if start_date:46params["start_date"] = start_date47if end_date:48params["end_date"] = end_date49if prepost:50params["prepost"] = "true"51return _get("time_series", params)525354def twelvedata_price(symbol, prepost=False):55"""Get current price for a symbol."""56params = {"symbol": symbol}57if prepost:58params["prepost"] = "true"59return _get("price", params)606162def twelvedata_eod(symbol, date=None, prepost=False):63"""Get end-of-day price."""64params = {"symbol": symbol}65if date:66params["date"] = date67if prepost:68params["prepost"] = "true"69return _get("eod", params)707172def twelvedata_quote(symbol, prepost=False):73"""Get detailed quote (price, volume, 52w high/low, change %)."""74params = {"symbol": symbol}75if prepost:76params["prepost"] = "true"77return _get("quote", params)787980def twelvedata_quote_batch(symbols, prepost=False):81"""Get quotes for multiple symbols. symbols: comma-separated string."""82params = {"symbol": symbols}83if prepost:84params["prepost"] = "true"85return _get("quote", params)868788def twelvedata_price_batch(symbols, prepost=False):89"""Get prices for multiple symbols. symbols: comma-separated string."""90params = {"symbol": symbols}91if prepost:92params["prepost"] = "true"93return _get("price", params)949596def twelvedata_search(query):97"""Search for symbols by name or ticker."""98return _get("symbol_search", {"symbol": query})99100101def twelvedata_stocks(exchange=None, country=None):102"""Get list of available stocks, optionally filtered."""103params = {}104if exchange:105params["exchange"] = exchange106if country:107params["country"] = country108return _get("stocks", params)109110111def twelvedata_forex_pairs():112"""Get all available forex pairs."""113return _get("forex_pairs")114115116def twelvedata_exchanges():117"""Get list of supported exchanges."""118return _get("exchanges")119