66from mcp .server .fastmcp import Context
77
88from schwab_mcp .tools .registry import register
9- from schwab_mcp .tools .utils import call , get_price_history_client
9+ from schwab_mcp .tools .utils import call , get_context
1010
1111
1212def _parse_iso_datetime (value : str | None ) -> datetime .datetime | None :
@@ -17,7 +17,9 @@ def _parse_iso_datetime(value: str | None) -> datetime.datetime | None:
1717async def get_advanced_price_history (
1818 ctx : Context ,
1919 symbol : Annotated [str , "Symbol of the security" ],
20- period_type : Annotated [str | None , "Period type: DAY, MONTH, YEAR, YEAR_TO_DATE" ] = None ,
20+ period_type : Annotated [
21+ str | None , "Period type: DAY, MONTH, YEAR, YEAR_TO_DATE"
22+ ] = None ,
2123 period : Annotated [
2224 str | None ,
2325 (
@@ -26,7 +28,8 @@ async def get_advanced_price_history(
2628 ),
2729 ] = None ,
2830 frequency_type : Annotated [
29- str | None , "Frequency type: MINUTE (for DAY), DAILY/WEEKLY (for MONTH/YTD), DAILY/WEEKLY/MONTHLY (for YEAR)"
31+ str | None ,
32+ "Frequency type: MINUTE (for DAY), DAILY/WEEKLY (for MONTH/YTD), DAILY/WEEKLY/MONTHLY (for YEAR)" ,
3033 ] = None ,
3134 frequency : Annotated [
3235 int | str | None ,
@@ -57,16 +60,15 @@ async def get_advanced_price_history(
5760 YEAR_TO_DATE: DAILY, WEEKLY (default)
5861 Dates must be in ISO format.
5962 """
60- client = get_price_history_client (ctx )
63+ context = get_context (ctx )
64+ client = context .price_history
6165
6266 start_dt = _parse_iso_datetime (start_datetime )
6367 end_dt = _parse_iso_datetime (end_datetime )
6468
6569 # Normalize enum-like strings
6670 period_type_enum = (
67- client .PriceHistory .PeriodType [period_type .upper ()]
68- if period_type
69- else None
71+ client .PriceHistory .PeriodType [period_type .upper ()] if period_type else None
7072 )
7173 period_enum = client .PriceHistory .Period [period .upper ()] if period else None
7274 frequency_type_enum = (
@@ -109,7 +111,8 @@ async def get_price_history_every_minute(
109111 """
110112 Get OHLCV price history per minute. For detailed intraday analysis. Max 48 days history. Dates ISO format.
111113 """
112- client = get_price_history_client (ctx )
114+ context = get_context (ctx )
115+ client = context .price_history
113116
114117 start_dt = _parse_iso_datetime (start_datetime )
115118 end_dt = _parse_iso_datetime (end_datetime )
@@ -140,7 +143,8 @@ async def get_price_history_every_five_minutes(
140143 """
141144 Get OHLCV price history per 5 minutes. Balance between detail and noise. Approx. 9 months history. Dates ISO format.
142145 """
143- client = get_price_history_client (ctx )
146+ context = get_context (ctx )
147+ client = context .price_history
144148
145149 start_dt = _parse_iso_datetime (start_datetime )
146150 end_dt = _parse_iso_datetime (end_datetime )
@@ -171,7 +175,8 @@ async def get_price_history_every_ten_minutes(
171175 """
172176 Get OHLCV price history per 10 minutes. Good for intraday trends/levels. Approx. 9 months history. Dates ISO format.
173177 """
174- client = get_price_history_client (ctx )
178+ context = get_context (ctx )
179+ client = context .price_history
175180
176181 start_dt = _parse_iso_datetime (start_datetime )
177182 end_dt = _parse_iso_datetime (end_datetime )
@@ -202,7 +207,8 @@ async def get_price_history_every_fifteen_minutes(
202207 """
203208 Get OHLCV price history per 15 minutes. Shows significant intraday moves, filters noise. Approx. 9 months history. Dates ISO format.
204209 """
205- client = get_price_history_client (ctx )
210+ context = get_context (ctx )
211+ client = context .price_history
206212
207213 start_dt = _parse_iso_datetime (start_datetime )
208214 end_dt = _parse_iso_datetime (end_datetime )
@@ -233,7 +239,8 @@ async def get_price_history_every_thirty_minutes(
233239 """
234240 Get OHLCV price history per 30 minutes. For broader intraday trends, filters noise. Approx. 9 months history. Dates ISO format.
235241 """
236- client = get_price_history_client (ctx )
242+ context = get_context (ctx )
243+ client = context .price_history
237244
238245 start_dt = _parse_iso_datetime (start_datetime )
239246 end_dt = _parse_iso_datetime (end_datetime )
@@ -270,7 +277,8 @@ async def get_price_history_every_day(
270277 """
271278 Get daily OHLCV price history. For medium/long-term analysis. Extensive history (back to 1985 possible). Dates ISO format.
272279 """
273- client = get_price_history_client (ctx )
280+ context = get_context (ctx )
281+ client = context .price_history
274282
275283 start_dt = _parse_iso_datetime (start_datetime )
276284 end_dt = _parse_iso_datetime (end_datetime )
@@ -301,7 +309,8 @@ async def get_price_history_every_week(
301309 """
302310 Get weekly OHLCV price history. For long-term analysis, major cycles. Extensive history (back to 1985 possible). Dates ISO format.
303311 """
304- client = get_price_history_client (ctx )
312+ context = get_context (ctx )
313+ client = context .price_history
305314
306315 start_dt = _parse_iso_datetime (start_datetime )
307316 end_dt = _parse_iso_datetime (end_datetime )
0 commit comments