openmarkets 0.1.0.dev43__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_server_yfinance/__init__.py +5 -0
- mcp_server_yfinance/_version.py +21 -0
- mcp_server_yfinance/py.typed +0 -0
- mcp_server_yfinance/server.py +45 -0
- mcp_server_yfinance/tools/__init__.py +33 -0
- mcp_server_yfinance/tools/analyst_data.py +81 -0
- mcp_server_yfinance/tools/calendar.py +78 -0
- mcp_server_yfinance/tools/corporate_actions.py +147 -0
- mcp_server_yfinance/tools/crypto.py +203 -0
- mcp_server_yfinance/tools/extended_market.py +298 -0
- mcp_server_yfinance/tools/financial_statements.py +140 -0
- mcp_server_yfinance/tools/funds.py +167 -0
- mcp_server_yfinance/tools/historical_data.py +121 -0
- mcp_server_yfinance/tools/market_data.py +201 -0
- mcp_server_yfinance/tools/news.py +148 -0
- mcp_server_yfinance/tools/options.py +151 -0
- mcp_server_yfinance/tools/screener.py +386 -0
- mcp_server_yfinance/tools/stock_info.py +143 -0
- mcp_server_yfinance/tools/technical_analysis.py +153 -0
- openmarkets-0.1.0.dev43.dist-info/METADATA +247 -0
- openmarkets-0.1.0.dev43.dist-info/RECORD +24 -0
- openmarkets-0.1.0.dev43.dist-info/WHEEL +4 -0
- openmarkets-0.1.0.dev43.dist-info/entry_points.txt +2 -0
- openmarkets-0.1.0.dev43.dist-info/licenses/LICENSE +661 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
|
5
|
+
|
|
6
|
+
TYPE_CHECKING = False
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from typing import Tuple
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
12
|
+
else:
|
|
13
|
+
VERSION_TUPLE = object
|
|
14
|
+
|
|
15
|
+
version: str
|
|
16
|
+
__version__: str
|
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
|
18
|
+
version_tuple: VERSION_TUPLE
|
|
19
|
+
|
|
20
|
+
__version__ = version = '0.1.0.dev43'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 1, 0, 'dev43')
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""MCP Server Markets - YFinance integration"""
|
|
2
|
+
|
|
3
|
+
from mcp.server import FastMCP
|
|
4
|
+
|
|
5
|
+
from .tools import (
|
|
6
|
+
register_analyst_data_tools,
|
|
7
|
+
register_calendar_tools,
|
|
8
|
+
register_corporate_actions_tools,
|
|
9
|
+
register_crypto_tools,
|
|
10
|
+
register_extended_market_tools,
|
|
11
|
+
register_financial_statements_tools,
|
|
12
|
+
register_fund_tools,
|
|
13
|
+
register_historical_data_tools,
|
|
14
|
+
register_market_data_tools,
|
|
15
|
+
register_news_tools,
|
|
16
|
+
register_options_tools,
|
|
17
|
+
register_stock_info_tools,
|
|
18
|
+
register_technical_analysis_tools,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
mcp = FastMCP("Market Data Server", "1.0.0")
|
|
22
|
+
|
|
23
|
+
# Register all tool modules
|
|
24
|
+
register_stock_info_tools(mcp)
|
|
25
|
+
register_historical_data_tools(mcp)
|
|
26
|
+
register_analyst_data_tools(mcp)
|
|
27
|
+
register_financial_statements_tools(mcp)
|
|
28
|
+
register_options_tools(mcp)
|
|
29
|
+
register_calendar_tools(mcp)
|
|
30
|
+
register_market_data_tools(mcp)
|
|
31
|
+
register_crypto_tools(mcp)
|
|
32
|
+
register_technical_analysis_tools(mcp)
|
|
33
|
+
register_corporate_actions_tools(mcp)
|
|
34
|
+
register_extended_market_tools(mcp)
|
|
35
|
+
register_news_tools(mcp)
|
|
36
|
+
register_fund_tools(mcp)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main():
|
|
40
|
+
"""Main function to start the MCP server."""
|
|
41
|
+
mcp.run()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if __name__ == "__main__":
|
|
45
|
+
main()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"""Financial tools package."""
|
|
2
|
+
|
|
3
|
+
from .analyst_data import register_analyst_data_tools
|
|
4
|
+
from .calendar import register_calendar_tools
|
|
5
|
+
from .corporate_actions import register_corporate_actions_tools
|
|
6
|
+
from .crypto import register_crypto_tools
|
|
7
|
+
from .extended_market import register_extended_market_tools
|
|
8
|
+
from .financial_statements import register_financial_statements_tools
|
|
9
|
+
from .funds import register_fund_tools
|
|
10
|
+
from .historical_data import register_historical_data_tools
|
|
11
|
+
from .market_data import register_market_data_tools
|
|
12
|
+
from .news import register_news_tools
|
|
13
|
+
from .options import register_options_tools
|
|
14
|
+
from .screener import register_screener_tools
|
|
15
|
+
from .stock_info import register_stock_info_tools
|
|
16
|
+
from .technical_analysis import register_technical_analysis_tools
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"register_stock_info_tools",
|
|
20
|
+
"register_historical_data_tools",
|
|
21
|
+
"register_analyst_data_tools",
|
|
22
|
+
"register_financial_statements_tools",
|
|
23
|
+
"register_options_tools",
|
|
24
|
+
"register_calendar_tools",
|
|
25
|
+
"register_market_data_tools",
|
|
26
|
+
"register_technical_analysis_tools",
|
|
27
|
+
"register_crypto_tools",
|
|
28
|
+
"register_corporate_actions_tools",
|
|
29
|
+
"register_extended_market_tools",
|
|
30
|
+
"register_news_tools",
|
|
31
|
+
"register_fund_tools",
|
|
32
|
+
"register_screener_tools",
|
|
33
|
+
]
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Analyst data tools."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import yfinance as yf
|
|
6
|
+
from mcp.server import FastMCP
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def register_analyst_data_tools(mcp: FastMCP):
|
|
10
|
+
"""Register analyst data tools with the MCP server."""
|
|
11
|
+
|
|
12
|
+
@mcp.tool()
|
|
13
|
+
async def get_recommendations(ticker: str) -> str:
|
|
14
|
+
"""Get analyst recommendations for a stock.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
ticker: Stock ticker symbol
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
JSON string containing analyst recommendations
|
|
21
|
+
"""
|
|
22
|
+
stock = yf.Ticker(ticker)
|
|
23
|
+
recs = stock.recommendations
|
|
24
|
+
if recs is not None and not recs.empty:
|
|
25
|
+
return recs.to_json(date_format="iso")
|
|
26
|
+
return json.dumps({"error": "No recommendations available"})
|
|
27
|
+
|
|
28
|
+
@mcp.tool()
|
|
29
|
+
async def get_analyst_price_targets(ticker: str) -> str:
|
|
30
|
+
"""Get analyst price targets and estimates.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
ticker: Stock ticker symbol
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
JSON string containing price targets
|
|
37
|
+
"""
|
|
38
|
+
stock = yf.Ticker(ticker)
|
|
39
|
+
info = stock.info
|
|
40
|
+
price_targets = {
|
|
41
|
+
"targetHighPrice": info.get("targetHighPrice"),
|
|
42
|
+
"targetLowPrice": info.get("targetLowPrice"),
|
|
43
|
+
"targetMeanPrice": info.get("targetMeanPrice"),
|
|
44
|
+
"targetMedianPrice": info.get("targetMedianPrice"),
|
|
45
|
+
"recommendationMean": info.get("recommendationMean"),
|
|
46
|
+
"recommendationKey": info.get("recommendationKey"),
|
|
47
|
+
"numberOfAnalystOpinions": info.get("numberOfAnalystOpinions"),
|
|
48
|
+
}
|
|
49
|
+
return json.dumps(price_targets, indent=2)
|
|
50
|
+
|
|
51
|
+
@mcp.tool()
|
|
52
|
+
async def get_upgrades_downgrades(ticker: str) -> str:
|
|
53
|
+
"""Get recent upgrades and downgrades.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
ticker: Stock ticker symbol
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
JSON string containing upgrades/downgrades
|
|
60
|
+
"""
|
|
61
|
+
stock = yf.Ticker(ticker)
|
|
62
|
+
upgrades = stock.upgrades_downgrades
|
|
63
|
+
if upgrades is not None and not upgrades.empty:
|
|
64
|
+
return upgrades.to_json(date_format="iso")
|
|
65
|
+
return json.dumps({"error": "No upgrades/downgrades data available"})
|
|
66
|
+
|
|
67
|
+
@mcp.tool()
|
|
68
|
+
async def get_recommendations_summary(ticker: str) -> str:
|
|
69
|
+
"""Get recommendations summary.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
ticker: Stock ticker symbol
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
JSON string containing recommendations summary
|
|
76
|
+
"""
|
|
77
|
+
stock = yf.Ticker(ticker)
|
|
78
|
+
rec_summary = stock.recommendations_summary
|
|
79
|
+
if rec_summary is not None and not rec_summary.empty:
|
|
80
|
+
return rec_summary.to_json(date_format="iso")
|
|
81
|
+
return json.dumps({"error": "No recommendations summary available"})
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Calendar and events tools."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
import yfinance as yf
|
|
6
|
+
from mcp.server import FastMCP
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def register_calendar_tools(mcp: FastMCP):
|
|
10
|
+
"""Register calendar tools with the MCP server."""
|
|
11
|
+
|
|
12
|
+
@mcp.tool()
|
|
13
|
+
async def get_earnings_calendar(ticker: str) -> str:
|
|
14
|
+
"""Get earnings calendar information.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
ticker: Stock ticker symbol
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
JSON string containing earnings calendar data
|
|
21
|
+
"""
|
|
22
|
+
stock = yf.Ticker(ticker)
|
|
23
|
+
calendar = stock.calendar
|
|
24
|
+
if calendar is not None and not calendar.empty:
|
|
25
|
+
return calendar.to_json(date_format="iso")
|
|
26
|
+
return json.dumps({"error": "No earnings calendar data available"})
|
|
27
|
+
|
|
28
|
+
@mcp.tool()
|
|
29
|
+
async def get_earnings_dates(ticker: str) -> str:
|
|
30
|
+
"""Get upcoming and past earnings dates.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
ticker: Stock ticker symbol
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
JSON string containing earnings dates
|
|
37
|
+
"""
|
|
38
|
+
stock = yf.Ticker(ticker)
|
|
39
|
+
info = stock.info
|
|
40
|
+
|
|
41
|
+
earnings_info = {
|
|
42
|
+
"earningsDate": info.get("earningsDate"),
|
|
43
|
+
"exDividendDate": info.get("exDividendDate"),
|
|
44
|
+
"dividendDate": info.get("dividendDate"),
|
|
45
|
+
"lastEarningsDate": info.get("lastEarningsDate"),
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return json.dumps(earnings_info, indent=2, default=str)
|
|
49
|
+
|
|
50
|
+
@mcp.tool()
|
|
51
|
+
async def get_market_calendar_info(ticker: str) -> str:
|
|
52
|
+
"""Get market calendar information for a stock.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
ticker: Stock ticker symbol
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
JSON string containing market calendar info
|
|
59
|
+
"""
|
|
60
|
+
stock = yf.Ticker(ticker)
|
|
61
|
+
info = stock.info
|
|
62
|
+
|
|
63
|
+
market_info = {
|
|
64
|
+
"exchange": info.get("exchange"),
|
|
65
|
+
"exchangeTimezoneName": info.get("exchangeTimezoneName"),
|
|
66
|
+
"exchangeTimezoneShortName": info.get("exchangeTimezoneShortName"),
|
|
67
|
+
"gmtOffSetMilliseconds": info.get("gmtOffSetMilliseconds"),
|
|
68
|
+
"market": info.get("market"),
|
|
69
|
+
"marketState": info.get("marketState"),
|
|
70
|
+
"regularMarketTime": info.get("regularMarketTime"),
|
|
71
|
+
"regularMarketPreviousClose": info.get("regularMarketPreviousClose"),
|
|
72
|
+
"preMarketPrice": info.get("preMarketPrice"),
|
|
73
|
+
"preMarketTime": info.get("preMarketTime"),
|
|
74
|
+
"postMarketPrice": info.get("postMarketPrice"),
|
|
75
|
+
"postMarketTime": info.get("postMarketTime"),
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return json.dumps(market_info, indent=2, default=str)
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""Corporate actions and dividend tools for yfinance MCP server."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import pandas as pd
|
|
6
|
+
import yfinance as yf
|
|
7
|
+
from mcp.server import FastMCP
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def register_corporate_actions_tools(mcp: FastMCP):
|
|
11
|
+
"""Register corporate actions and dividend tools."""
|
|
12
|
+
|
|
13
|
+
@mcp.tool("get_dividends_history")
|
|
14
|
+
def get_dividends(
|
|
15
|
+
symbol: str,
|
|
16
|
+
period: str = "1y",
|
|
17
|
+
start_date: Optional[str] = None,
|
|
18
|
+
end_date: Optional[str] = None,
|
|
19
|
+
) -> dict:
|
|
20
|
+
"""
|
|
21
|
+
Get dividend history for a stock.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
symbol: Stock symbol (e.g., 'AAPL', 'GOOGL')
|
|
25
|
+
period: Time period ('1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max')
|
|
26
|
+
start_date: Start date in YYYY-MM-DD format (optional)
|
|
27
|
+
end_date: End date in YYYY-MM-DD format (optional)
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
Dictionary containing dividend data
|
|
31
|
+
"""
|
|
32
|
+
try:
|
|
33
|
+
ticker = yf.Ticker(symbol)
|
|
34
|
+
|
|
35
|
+
if start_date and end_date:
|
|
36
|
+
dividends = ticker.dividends.loc[start_date:end_date]
|
|
37
|
+
else:
|
|
38
|
+
dividends = ticker.history(period=period).dividends
|
|
39
|
+
|
|
40
|
+
# Filter out zero dividends
|
|
41
|
+
dividends = dividends[dividends > 0]
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
"symbol": symbol,
|
|
45
|
+
"dividends": dividends.to_dict(),
|
|
46
|
+
"total_dividends": float(dividends.sum()),
|
|
47
|
+
"dividend_count": len(dividends),
|
|
48
|
+
"period": period if not (start_date and end_date) else f"{start_date} to {end_date}",
|
|
49
|
+
}
|
|
50
|
+
except Exception as e:
|
|
51
|
+
return {"error": str(e)}
|
|
52
|
+
|
|
53
|
+
@mcp.tool("get_splits_history")
|
|
54
|
+
def get_splits(symbol: str, period: str = "5y") -> dict:
|
|
55
|
+
"""
|
|
56
|
+
Get stock split history.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
symbol: Stock symbol (e.g., 'AAPL', 'GOOGL')
|
|
60
|
+
period: Time period ('1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max')
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
Dictionary containing stock split data
|
|
64
|
+
"""
|
|
65
|
+
try:
|
|
66
|
+
ticker = yf.Ticker(symbol)
|
|
67
|
+
splits = ticker.splits
|
|
68
|
+
|
|
69
|
+
# Filter splits within the period
|
|
70
|
+
if period != "max":
|
|
71
|
+
history = ticker.history(period=period)
|
|
72
|
+
if not history.empty:
|
|
73
|
+
start_date = history.index[0]
|
|
74
|
+
splits = splits[splits.index >= start_date]
|
|
75
|
+
|
|
76
|
+
return {"symbol": symbol, "splits": splits.to_dict(), "split_count": len(splits), "period": period}
|
|
77
|
+
except Exception as e:
|
|
78
|
+
return {"error": str(e)}
|
|
79
|
+
|
|
80
|
+
@mcp.tool("get_actions")
|
|
81
|
+
def get_actions(symbol: str, period: str = "1y") -> dict:
|
|
82
|
+
"""
|
|
83
|
+
Get all corporate actions (dividends and splits) for a stock.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
symbol: Stock symbol (e.g., 'AAPL', 'GOOGL')
|
|
87
|
+
period: Time period ('1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max')
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
Dictionary containing all corporate actions
|
|
91
|
+
"""
|
|
92
|
+
try:
|
|
93
|
+
ticker = yf.Ticker(symbol)
|
|
94
|
+
actions = ticker.actions
|
|
95
|
+
|
|
96
|
+
# Filter actions within the period
|
|
97
|
+
if period != "max":
|
|
98
|
+
history = ticker.history(period=period)
|
|
99
|
+
if not history.empty:
|
|
100
|
+
start_date = history.index[0]
|
|
101
|
+
actions = actions[actions.index >= start_date]
|
|
102
|
+
|
|
103
|
+
return {"symbol": symbol, "actions": actions.to_dict(), "period": period, "total_actions": len(actions)}
|
|
104
|
+
except Exception as e:
|
|
105
|
+
return {"error": str(e)}
|
|
106
|
+
|
|
107
|
+
@mcp.tool("get_dividend_yield")
|
|
108
|
+
def get_dividend_yield(symbol: str) -> dict:
|
|
109
|
+
"""
|
|
110
|
+
Calculate dividend yield and related metrics.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
symbol: Stock symbol (e.g., 'AAPL', 'GOOGL')
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
Dictionary containing dividend yield metrics
|
|
117
|
+
"""
|
|
118
|
+
try:
|
|
119
|
+
ticker = yf.Ticker(symbol)
|
|
120
|
+
info = ticker.info
|
|
121
|
+
|
|
122
|
+
# Get trailing twelve months dividends
|
|
123
|
+
dividends = ticker.dividends
|
|
124
|
+
if len(dividends) > 0:
|
|
125
|
+
# Get dividends from last 12 months
|
|
126
|
+
latest_date = dividends.index[-1]
|
|
127
|
+
one_year_ago = latest_date - pd.DateOffset(years=1)
|
|
128
|
+
ttm_dividends = dividends[dividends.index > one_year_ago].sum()
|
|
129
|
+
else:
|
|
130
|
+
ttm_dividends = 0
|
|
131
|
+
|
|
132
|
+
current_price = info.get("currentPrice", info.get("regularMarketPrice", 0))
|
|
133
|
+
dividend_yield = (ttm_dividends / current_price * 100) if current_price > 0 else 0
|
|
134
|
+
|
|
135
|
+
return {
|
|
136
|
+
"symbol": symbol,
|
|
137
|
+
"current_price": current_price,
|
|
138
|
+
"ttm_dividends": float(ttm_dividends),
|
|
139
|
+
"dividend_yield_percent": round(dividend_yield, 2),
|
|
140
|
+
"forward_dividend_rate": info.get("dividendRate"),
|
|
141
|
+
"forward_dividend_yield": info.get("dividendYield"),
|
|
142
|
+
"payout_ratio": info.get("payoutRatio"),
|
|
143
|
+
"ex_dividend_date": info.get("exDividendDate"),
|
|
144
|
+
"dividend_date": info.get("dividendDate"),
|
|
145
|
+
}
|
|
146
|
+
except Exception as e:
|
|
147
|
+
return {"error": str(e)}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"""Cryptocurrency and alternative assets tools."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
import yfinance as yf
|
|
7
|
+
from mcp.server import FastMCP
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def register_crypto_tools(mcp: FastMCP):
|
|
11
|
+
"""Register cryptocurrency tools with the MCP server."""
|
|
12
|
+
|
|
13
|
+
@mcp.tool()
|
|
14
|
+
async def get_crypto_info(crypto_symbol: str) -> str:
|
|
15
|
+
"""Get cryptocurrency information.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
crypto_symbol: Crypto symbol with -USD suffix (e.g., 'BTC-USD', 'ETH-USD')
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
JSON string containing crypto information
|
|
22
|
+
"""
|
|
23
|
+
if not crypto_symbol.endswith("-USD"):
|
|
24
|
+
crypto_symbol += "-USD"
|
|
25
|
+
|
|
26
|
+
crypto = yf.Ticker(crypto_symbol)
|
|
27
|
+
info = crypto.info
|
|
28
|
+
|
|
29
|
+
crypto_info = {
|
|
30
|
+
"symbol": info.get("symbol"),
|
|
31
|
+
"name": info.get("shortName"),
|
|
32
|
+
"currentPrice": info.get("currentPrice"),
|
|
33
|
+
"marketCap": info.get("marketCap"),
|
|
34
|
+
"volume24Hr": info.get("volume24Hr"),
|
|
35
|
+
"circulatingSupply": info.get("circulatingSupply"),
|
|
36
|
+
"maxSupply": info.get("maxSupply"),
|
|
37
|
+
"previousClose": info.get("previousClose"),
|
|
38
|
+
"dayLow": info.get("dayLow"),
|
|
39
|
+
"dayHigh": info.get("dayHigh"),
|
|
40
|
+
"fiftyTwoWeekLow": info.get("fiftyTwoWeekLow"),
|
|
41
|
+
"fiftyTwoWeekHigh": info.get("fiftyTwoWeekHigh"),
|
|
42
|
+
"currency": info.get("currency"),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return json.dumps(crypto_info, indent=2)
|
|
46
|
+
|
|
47
|
+
@mcp.tool()
|
|
48
|
+
async def get_crypto_historical_data(crypto_symbol: str, period: str = "1mo", interval: str = "1d") -> str:
|
|
49
|
+
"""Get historical cryptocurrency data.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
crypto_symbol: Crypto symbol with -USD suffix (e.g., 'BTC-USD')
|
|
53
|
+
period: Data period (1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max)
|
|
54
|
+
interval: Data interval (1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo)
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
JSON string containing historical crypto data
|
|
58
|
+
"""
|
|
59
|
+
if not crypto_symbol.endswith("-USD"):
|
|
60
|
+
crypto_symbol += "-USD"
|
|
61
|
+
|
|
62
|
+
crypto = yf.Ticker(crypto_symbol)
|
|
63
|
+
hist = crypto.history(period=period, interval=interval)
|
|
64
|
+
|
|
65
|
+
if hist.empty:
|
|
66
|
+
return json.dumps({"error": "No historical data available"})
|
|
67
|
+
|
|
68
|
+
return hist.to_json(date_format="iso")
|
|
69
|
+
|
|
70
|
+
@mcp.tool()
|
|
71
|
+
async def get_top_cryptocurrencies(count: int = 10) -> str:
|
|
72
|
+
"""Get data for top cryptocurrencies by market cap.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
count: Number of top cryptocurrencies to return (max 20)
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
JSON string containing top crypto data
|
|
79
|
+
"""
|
|
80
|
+
# Top cryptocurrencies by market cap (approximate list)
|
|
81
|
+
top_cryptos = [
|
|
82
|
+
"BTC-USD",
|
|
83
|
+
"ETH-USD",
|
|
84
|
+
"BNB-USD",
|
|
85
|
+
"XRP-USD",
|
|
86
|
+
"SOL-USD",
|
|
87
|
+
"ADA-USD",
|
|
88
|
+
"AVAX-USD",
|
|
89
|
+
"DOGE-USD",
|
|
90
|
+
"TRX-USD",
|
|
91
|
+
"DOT-USD",
|
|
92
|
+
"MATIC-USD",
|
|
93
|
+
"LTC-USD",
|
|
94
|
+
"SHIB-USD",
|
|
95
|
+
"BCH-USD",
|
|
96
|
+
"UNI-USD",
|
|
97
|
+
"ATOM-USD",
|
|
98
|
+
"LINK-USD",
|
|
99
|
+
"ETC-USD",
|
|
100
|
+
"XLM-USD",
|
|
101
|
+
"ALGO-USD",
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
selected_cryptos = top_cryptos[: min(count, 20)]
|
|
105
|
+
crypto_data = []
|
|
106
|
+
|
|
107
|
+
try:
|
|
108
|
+
for crypto in selected_cryptos:
|
|
109
|
+
ticker = yf.Ticker(crypto)
|
|
110
|
+
info = ticker.info
|
|
111
|
+
hist = ticker.history(period="2d")
|
|
112
|
+
|
|
113
|
+
daily_change = None
|
|
114
|
+
daily_change_percent = None
|
|
115
|
+
|
|
116
|
+
if len(hist) >= 2:
|
|
117
|
+
current_price = hist.iloc[-1]["Close"]
|
|
118
|
+
previous_close = hist.iloc[-2]["Close"]
|
|
119
|
+
daily_change = current_price - previous_close
|
|
120
|
+
daily_change_percent = (daily_change / previous_close) * 100
|
|
121
|
+
|
|
122
|
+
crypto_data.append(
|
|
123
|
+
{
|
|
124
|
+
"symbol": crypto,
|
|
125
|
+
"name": info.get("shortName", ""),
|
|
126
|
+
"currentPrice": info.get("currentPrice"),
|
|
127
|
+
"marketCap": info.get("marketCap"),
|
|
128
|
+
"volume": info.get("volume"),
|
|
129
|
+
"dailyChange": daily_change,
|
|
130
|
+
"dailyChangePercent": daily_change_percent,
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
return json.dumps({"count": len(crypto_data), "cryptocurrencies": crypto_data}, indent=2)
|
|
135
|
+
|
|
136
|
+
except Exception as e:
|
|
137
|
+
return json.dumps({"error": f"Failed to get crypto data: {str(e)}"})
|
|
138
|
+
|
|
139
|
+
@mcp.tool()
|
|
140
|
+
async def get_crypto_fear_greed_proxy(crypto_symbols: List[str] = None) -> str:
|
|
141
|
+
"""Get a proxy for crypto market sentiment using price movements.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
crypto_symbols: List of crypto symbols to analyze (default: major cryptos)
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
JSON string containing market sentiment proxy data
|
|
148
|
+
"""
|
|
149
|
+
if crypto_symbols is None:
|
|
150
|
+
crypto_symbols = ["BTC-USD", "ETH-USD", "BNB-USD", "XRP-USD", "SOL-USD"]
|
|
151
|
+
|
|
152
|
+
try:
|
|
153
|
+
sentiment_data = []
|
|
154
|
+
total_change = 0
|
|
155
|
+
valid_cryptos = 0
|
|
156
|
+
|
|
157
|
+
for crypto in crypto_symbols:
|
|
158
|
+
ticker = yf.Ticker(crypto)
|
|
159
|
+
hist = ticker.history(period="7d") # Get 7 days for weekly change
|
|
160
|
+
|
|
161
|
+
if len(hist) >= 2:
|
|
162
|
+
weekly_change = ((hist.iloc[-1]["Close"] - hist.iloc[0]["Close"]) / hist.iloc[0]["Close"]) * 100
|
|
163
|
+
daily_change = ((hist.iloc[-1]["Close"] - hist.iloc[-2]["Close"]) / hist.iloc[-2]["Close"]) * 100
|
|
164
|
+
|
|
165
|
+
sentiment_data.append(
|
|
166
|
+
{
|
|
167
|
+
"symbol": crypto,
|
|
168
|
+
"daily_change_percent": daily_change,
|
|
169
|
+
"weekly_change_percent": weekly_change,
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
total_change += weekly_change
|
|
174
|
+
valid_cryptos += 1
|
|
175
|
+
|
|
176
|
+
# Simple sentiment scoring (this is a basic proxy)
|
|
177
|
+
avg_change = total_change / valid_cryptos if valid_cryptos > 0 else 0
|
|
178
|
+
|
|
179
|
+
if avg_change > 10:
|
|
180
|
+
sentiment = "Extreme Greed"
|
|
181
|
+
elif avg_change > 5:
|
|
182
|
+
sentiment = "Greed"
|
|
183
|
+
elif avg_change > 0:
|
|
184
|
+
sentiment = "Neutral-Positive"
|
|
185
|
+
elif avg_change > -5:
|
|
186
|
+
sentiment = "Neutral-Negative"
|
|
187
|
+
elif avg_change > -10:
|
|
188
|
+
sentiment = "Fear"
|
|
189
|
+
else:
|
|
190
|
+
sentiment = "Extreme Fear"
|
|
191
|
+
|
|
192
|
+
return json.dumps(
|
|
193
|
+
{
|
|
194
|
+
"sentiment_proxy": sentiment,
|
|
195
|
+
"average_weekly_change": avg_change,
|
|
196
|
+
"crypto_data": sentiment_data,
|
|
197
|
+
"note": "This is a simplified sentiment proxy based on price movements, not the official Fear & Greed Index",
|
|
198
|
+
},
|
|
199
|
+
indent=2,
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
except Exception as e:
|
|
203
|
+
return json.dumps({"error": f"Failed to calculate sentiment proxy: {str(e)}"})
|