Class: SchwabMCP::Tools::QuoteTool
- Inherits:
-
MCP::Tool
- Object
- MCP::Tool
- SchwabMCP::Tools::QuoteTool
show all
- Extended by:
- Loggable
- Defined in:
- lib/schwab_mcp/tools/quote_tool.rb
Class Method Summary
collapse
Methods included from Loggable
log_debug, log_error, log_fatal, log_info, log_warn, logger
Class Method Details
.call(symbol:, server_context:) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/schwab_mcp/tools/quote_tool.rb', line 33
def self.call(symbol:, server_context:)
log_info("Getting quote for symbol: #{symbol}")
begin
client = SchwabClientFactory.create_client
return SchwabClientFactory.client_error_response unless client
log_debug("Making API request for symbol: #{symbol}")
quote_obj = client.get_quote(symbol.upcase)
unless quote_obj
log_warn("No quote data object returned for symbol: #{symbol}")
return MCP::Tool::Response.new([{
type: "text",
text: "**No Data**: No quote data returned for symbol: #{symbol}"
}])
end
formatted = format_quote_object(quote_obj)
log_info("Successfully retrieved quote for #{symbol}")
MCP::Tool::Response.new([{
type: "text",
text: "**Quote for #{symbol.upcase}:**\n\n#{formatted}"
}])
rescue => e
log_error("Error retrieving quote for #{symbol}: #{e.message}")
log_debug("Backtrace: #{e.backtrace.first(3).join('\n')}")
MCP::Tool::Response.new([{
type: "text",
text: "**Error** retrieving quote for #{symbol}: #{e.message}\n\n#{e.backtrace.first(3).join('\n')}"
}])
end
end
|
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/schwab_mcp/tools/quote_tool.rb', line 68
def self.format_quote_object(obj)
case obj
when SchwabRb::DataObjects::OptionQuote
"Option: #{obj.symbol}\nLast: #{obj.last_price} Bid: #{obj.bid_price} Ask: #{obj.ask_price} Mark: #{obj.mark} Delta: #{obj.delta} Gamma: #{obj.gamma} Vol: #{obj.volatility} OI: #{obj.open_interest} Exp: #{obj.expiration_month}/#{obj.expiration_day}/#{obj.expiration_year} Strike: #{obj.strike_price}"
when SchwabRb::DataObjects::EquityQuote
"Equity: #{obj.symbol}\nLast: #{obj.last_price} Bid: #{obj.bid_price} Ask: #{obj.ask_price} Mark: #{obj.mark} Net Chg: #{obj.net_change} %Chg: #{obj.net_percent_change} Vol: #{obj.total_volume}"
when SchwabRb::DataObjects::IndexQuote
"Index: #{obj.symbol}\nLast: #{obj.last_price} Bid: N/A Ask: N/A Mark: #{obj.mark} Net Chg: #{obj.net_change} %Chg: #{obj.net_percent_change} Vol: #{obj.total_volume}"
else
obj.respond_to?(:to_h) ? obj.to_h.inspect : obj.inspect
end
end
|