update tools

This commit is contained in:
tianyufan
2025-10-30 14:40:42 +08:00
parent 3f1812d320
commit 0bb5086df1

View File

@@ -8,7 +8,7 @@ from dotenv import load_dotenv
load_dotenv() load_dotenv()
mcp = FastMCP("LocalPrices") mcp = FastMCP("LocalPrices")
from tools.general_tools import get_config_value
def _workspace_data_path(filename: str) -> Path: def _workspace_data_path(filename: str) -> Path:
base_dir = Path(__file__).resolve().parents[1] base_dir = Path(__file__).resolve().parents[1]
@@ -75,61 +75,8 @@ def get_price_local(symbol: str, date: str) -> Dict[str, Any]:
return {"error": f"No records found for stock {symbol} in local data", "symbol": symbol, "date": date} return {"error": f"No records found for stock {symbol} in local data", "symbol": symbol, "date": date}
def get_price_local_function(symbol: str, date: str, filename: str = "merged.jsonl") -> Dict[str, Any]:
"""Read OHLCV data for specified stock and date from local JSONL data.
Args:
symbol: Stock symbol, e.g. 'IBM' or '600243.SHH'.
date: Date in 'YYYY-MM-DD' format.
filename: Data filename, defaults to 'merged.jsonl' (located in data/ under project root).
Returns:
Dictionary containing symbol, date and ohlcv data.
"""
try:
_validate_date(date)
except ValueError as e:
return {"error": str(e), "symbol": symbol, "date": date}
data_path = _workspace_data_path(filename)
if not data_path.exists():
return {"error": f"Data file not found: {data_path}", "symbol": symbol, "date": date}
with data_path.open("r", encoding="utf-8") as f:
for line in f:
if not line.strip():
continue
doc = json.loads(line)
meta = doc.get("Meta Data", {})
if meta.get("2. Symbol") != symbol:
continue
series = doc.get("Time Series (Daily)", {})
day = series.get(date)
if day is None:
sample_dates = sorted(series.keys(), reverse=True)[:5]
return {
"error": f"Data not found for date {date}. Please verify the date exists in data. Sample available dates: {sample_dates}",
"symbol": symbol,
"date": date
}
return {
"symbol": symbol,
"date": date,
"ohlcv": {
"buy price": day.get("1. buy price"),
"high": day.get("2. high"),
"low": day.get("3. low"),
"sell price": day.get("4. sell price"),
"volume": day.get("5. volume"),
},
}
return {"error": f"No records found for stock {symbol} in local data", "symbol": symbol, "date": date}
if __name__ == "__main__": if __name__ == "__main__":
# print("a test case") # print("a test case")
# print(get_price_local_function("AAPL", "2025-10-16"))
port = int(os.getenv("GETPRICE_HTTP_PORT", "8003")) port = int(os.getenv("GETPRICE_HTTP_PORT", "8003"))
mcp.run(transport="streamable-http", port=port) mcp.run(transport="streamable-http", port=port)